mirror of
https://git.kittycat.homes/zoe/hugo-battheme.git
synced 2024-08-15 03:25:18 +00:00
32 lines
714 B
JavaScript
32 lines
714 B
JavaScript
const checkbox = document.getElementById("darkmode-toggle");
|
|
const colorswitchers = document.getElementsByClassName("colorswitch");
|
|
|
|
if (localStorage.getItem("dark")) {
|
|
switchToDark();
|
|
} else {
|
|
switchToLight();
|
|
}
|
|
checkbox.checked = localStorage.getItem("dark");
|
|
|
|
checkbox.addEventListener("click", function () {
|
|
localStorage.setItem("dark", this.checked);
|
|
if (this.checked) {
|
|
switchToDark();
|
|
} else {
|
|
localStorage.removeItem("dark");
|
|
switchToLight();
|
|
}
|
|
});
|
|
|
|
function switchToLight() {
|
|
for (let item of colorswitchers) {
|
|
item.classList.add("light");
|
|
}
|
|
}
|
|
|
|
function switchToDark() {
|
|
for (let item of colorswitchers) {
|
|
console.log(item);
|
|
item.classList.remove("light");
|
|
}
|
|
}
|