2022-04-09 21:45:40 +00:00
|
|
|
const checkbox = document.getElementById("darkmode-toggle");
|
|
|
|
const colorswitchers = document.getElementsByClassName("colorswitch");
|
2022-04-09 19:42:12 +00:00
|
|
|
|
2022-04-13 10:43:01 +00:00
|
|
|
if (localStorage.getItem("light")) {
|
2022-04-09 21:45:40 +00:00
|
|
|
switchToLight();
|
2022-04-13 10:43:01 +00:00
|
|
|
} else {
|
|
|
|
switchToDark();
|
2022-04-09 19:42:12 +00:00
|
|
|
}
|
2022-04-09 21:45:40 +00:00
|
|
|
checkbox.checked = localStorage.getItem("dark");
|
2022-04-09 20:23:18 +00:00
|
|
|
|
2022-04-10 19:57:17 +00:00
|
|
|
checkbox.addEventListener("change", function () {
|
2022-04-13 10:43:01 +00:00
|
|
|
localStorage.setItem("light", this.checked);
|
2022-04-09 21:45:40 +00:00
|
|
|
if (this.checked) {
|
|
|
|
switchToLight();
|
2022-04-13 10:43:01 +00:00
|
|
|
} else {
|
|
|
|
localStorage.removeItem("light");
|
|
|
|
switchToDark();
|
2022-04-09 21:45:40 +00:00
|
|
|
}
|
|
|
|
});
|
2022-04-09 19:42:12 +00:00
|
|
|
|
|
|
|
function switchToLight() {
|
2022-04-09 21:45:40 +00:00
|
|
|
for (let item of colorswitchers) {
|
|
|
|
item.classList.add("light");
|
|
|
|
}
|
2022-04-09 19:42:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function switchToDark() {
|
2022-04-09 21:45:40 +00:00
|
|
|
for (let item of colorswitchers) {
|
|
|
|
console.log(item);
|
|
|
|
item.classList.remove("light");
|
|
|
|
}
|
2022-04-09 19:42:12 +00:00
|
|
|
}
|