blob: 66a3194d2bb13bbccb16c76c8029716e75dcba6d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
const theme = localStorage.getItem("theme");
var isDark = false;
if (theme) {
setTheme(theme === "dark");
} else if (window.matchMedia
&& window.matchMedia("(prefers-color-scheme: dark)").matches) {
setTheme(true);
}
function setTheme(dark) {
if (dark) {
document.body.classList.add("dark-mode");
localStorage.setItem("theme", "dark");
} else {
document.body.classList.remove("dark-mode");
localStorage.setItem("theme", "light");
}
isDark = dark;
}
function switchTheme() {
setTheme(!isDark);
}
|