Source code + assets for pluie.me
at main 32 lines 921 B view raw
1const themes = ["neon", "strawberry-milkshake"]; 2const isDark = globalThis.matchMedia("(prefers-color-scheme: dark)"); 3 4const theme = new Proxy( 5 { 6 value: localStorage.getItem("theme") 7 ?? (isDark.matches ? "neon" : "strawberry-milkshake"), 8 }, 9 { 10 set(target, p, newValue) { 11 if (p !== "value") return false; 12 if (!themes.includes(newValue)) return false; 13 if (target.value === newValue) return true; 14 15 target.value = newValue; 16 document.body.dataset.theme = newValue; 17 localStorage.setItem("theme", newValue); 18 19 return true; 20 }, 21 }, 22); 23 24globalThis.addEventListener("DOMContentLoaded", () => { 25 const themeSwitcher = document.querySelector("#theme-switcher"); 26 document.body.dataset.theme = theme.value; 27 28 themeSwitcher!.addEventListener("click", () => { 29 const idx = (themes.indexOf(theme.value) + 1) % themes.length; 30 theme.value = themes[idx]; 31 }); 32});