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-09 21:45:40 +00:00
|
|
|
if (localStorage.getItem("dark")) {
|
|
|
|
switchToDark();
|
2022-04-09 20:23:18 +00:00
|
|
|
} else {
|
2022-04-09 21:45:40 +00:00
|
|
|
switchToLight();
|
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
|
|
|
|
|
|
|
checkbox.addEventListener("click", function () {
|
2022-04-09 21:45:40 +00:00
|
|
|
localStorage.setItem("dark", this.checked);
|
|
|
|
if (this.checked) {
|
|
|
|
switchToDark();
|
|
|
|
} else {
|
|
|
|
localStorage.removeItem("dark");
|
|
|
|
switchToLight();
|
|
|
|
}
|
|
|
|
});
|
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
|
|
|
}
|