-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
theme-load.js
32 lines (28 loc) · 1.04 KB
/
theme-load.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(() => {
const storageType =
document.querySelector("theme-toggle")?.getAttribute("storage") === "local"
? localStorage
: sessionStorage;
const currentTheme = storageType.getItem("theme") || "auto";
const metaColorScheme = document.querySelector('meta[name="color-scheme"]');
const lightIcon = document.querySelector(".light");
const darkIcon = document.querySelector(".dark");
const autoIcon = document.querySelector(".auto");
if (currentTheme === "auto") {
metaColorScheme.setAttribute("content", "light dark");
document.documentElement.style.colorScheme = "";
} else {
metaColorScheme.setAttribute("content", currentTheme);
document.documentElement.style.colorScheme = currentTheme;
}
lightIcon.style.display = "none";
darkIcon.style.display = "none";
autoIcon.style.display = "none";
if (currentTheme === "light") {
lightIcon.style.display = "inline";
} else if (currentTheme === "dark") {
darkIcon.style.display = "inline";
} else {
autoIcon.style.display = "inline";
}
})();