mirror of
https://git.kittycat.homes/zoe/hugo-battheme.git
synced 2024-08-15 03:25:18 +00:00
36 lines
877 B
JavaScript
36 lines
877 B
JavaScript
const checkbox = document.getElementById("darkmode-toggle");
|
|
const colorswitchers = document.getElementsByClassName("colorswitch");
|
|
|
|
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");
|
|
}
|
|
}
|
|
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
if (localStorage.getItem("light")) {
|
|
switchToLight();
|
|
} else {
|
|
switchToDark();
|
|
}
|
|
checkbox.checked = localStorage.getItem("dark");
|
|
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;
|
|
}
|
|
});
|