mirror of
https://git.kittycat.homes/zoe/hugo-battheme.git
synced 2024-08-15 03:25:18 +00:00
fix lightmode button being weird
This commit is contained in:
parent
76b758dcad
commit
2e52a4843f
4 changed files with 42 additions and 36 deletions
|
@ -1,23 +1,6 @@
|
|||
const checkbox = document.getElementById("darkmode-toggle");
|
||||
const colorswitchers = document.getElementsByClassName("colorswitch");
|
||||
|
||||
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();
|
||||
}
|
||||
});
|
||||
|
||||
function switchToLight() {
|
||||
for (let item of colorswitchers) {
|
||||
item.classList.add("light");
|
||||
|
@ -30,3 +13,24 @@ function switchToDark() {
|
|||
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;
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue