2022-02-05 08:19:47 +00:00
|
|
|
const sitePreference = document.documentElement.getAttribute("data-default-appearance");
|
2022-01-27 04:26:18 +00:00
|
|
|
const userPreference = localStorage.getItem("appearance");
|
|
|
|
|
2022-03-13 23:40:34 +00:00
|
|
|
if ((sitePreference === "dark" && userPreference === null) || userPreference === "dark") {
|
2022-01-27 04:26:18 +00:00
|
|
|
document.documentElement.classList.add("dark");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (document.documentElement.getAttribute("data-auto-appearance") === "true") {
|
2022-03-13 23:40:34 +00:00
|
|
|
if (
|
|
|
|
window.matchMedia &&
|
|
|
|
window.matchMedia("(prefers-color-scheme: dark)").matches &&
|
|
|
|
userPreference !== "light"
|
|
|
|
) {
|
|
|
|
document.documentElement.classList.add("dark");
|
|
|
|
}
|
2022-01-27 04:26:18 +00:00
|
|
|
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", (event) => {
|
|
|
|
if (event.matches) {
|
|
|
|
document.documentElement.classList.add("dark");
|
|
|
|
} else {
|
|
|
|
document.documentElement.classList.remove("dark");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener("DOMContentLoaded", (event) => {
|
2022-02-06 04:10:59 +00:00
|
|
|
const switcher = document.getElementById("appearance-switcher");
|
2022-02-05 08:19:47 +00:00
|
|
|
if (switcher) {
|
|
|
|
switcher.addEventListener("click", () => {
|
|
|
|
document.documentElement.classList.toggle("dark");
|
|
|
|
localStorage.setItem(
|
|
|
|
"appearance",
|
|
|
|
document.documentElement.classList.contains("dark") ? "dark" : "light"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
switcher.addEventListener("contextmenu", (event) => {
|
|
|
|
event.preventDefault();
|
|
|
|
localStorage.removeItem("appearance");
|
|
|
|
});
|
|
|
|
}
|
2022-01-27 04:26:18 +00:00
|
|
|
});
|