mirror of
https://github.com/KivotosRailway/website.git
synced 2026-11-03 11:06:32 +09:00
13 lines
690 B
JavaScript
13 lines
690 B
JavaScript
(() => {
|
|
const isTheme = (value) => value === "light" || value === "system" || value === "dark";
|
|
let preference = "system";
|
|
try {
|
|
const cookieTheme = document.cookie.split(";").map((entry) => entry.trim()).find((entry) => entry.startsWith("kr-theme="))?.slice("kr-theme=".length);
|
|
const savedTheme = isTheme(cookieTheme) ? cookieTheme : localStorage.getItem("kr-theme");
|
|
if (isTheme(savedTheme)) preference = savedTheme;
|
|
} catch {}
|
|
const theme = preference === "system" ? (matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light") : preference;
|
|
document.documentElement.dataset.theme = theme;
|
|
document.documentElement.style.colorScheme = theme;
|
|
})();
|