mirror of
https://git.kittycat.homes/zoe/hugo-batsite.git
synced 2024-08-15 03:18:24 +00:00
42 lines
1 KiB
JavaScript
42 lines
1 KiB
JavaScript
const checkbox = document.getElementById("darkmode-toggle");
|
|
const colorswitchers = document.getElementsByClassName("colorswitch");
|
|
const button = document.getElementById("darkmode-button-small");
|
|
|
|
function switchToLight() {
|
|
button.innerHTML = "滛";
|
|
for (let item of colorswitchers) {
|
|
item.classList.add("light");
|
|
}
|
|
}
|
|
|
|
function switchToDark() {
|
|
button.innerHTML = "";
|
|
for (let item of colorswitchers) {
|
|
item.classList.remove("light");
|
|
}
|
|
}
|
|
|
|
export function updateMode() {
|
|
if (localStorage.getItem("light")) {
|
|
switchToLight();
|
|
} else {
|
|
switchToDark();
|
|
}
|
|
checkbox.checked = localStorage.getItem("dark");
|
|
|
|
button.addEventListener("click", function () {
|
|
checkbox.click();
|
|
});
|
|
checkbox.addEventListener("change", function () {
|
|
localStorage.setItem("light", this.checked);
|
|
if (this.checked) {
|
|
switchToLight();
|
|
} else {
|
|
localStorage.removeItem("light");
|
|
switchToDark();
|
|
}
|
|
});
|
|
if (localStorage.getItem("light")) {
|
|
checkbox.checked = true;
|
|
}
|
|
}
|