mirror of
https://git.kittycat.homes/zoe/hugo-battheme.git
synced 2024-08-15 03:25:18 +00:00
color switching is working i am so happy
This commit is contained in:
parent
873317081b
commit
ff99214248
4 changed files with 67 additions and 36 deletions
|
@ -1,29 +1,32 @@
|
|||
const checkbox = document.getElementById('darkmode-toggle');
|
||||
const body = document.querySelector("body");
|
||||
const checkbox = document.getElementById("darkmode-toggle");
|
||||
const colorswitchers = document.getElementsByClassName("colorswitch");
|
||||
|
||||
if (localStorage.getItem('dark')) {
|
||||
switchToDark()
|
||||
if (localStorage.getItem("dark")) {
|
||||
switchToDark();
|
||||
} else {
|
||||
switchToLight()
|
||||
switchToLight();
|
||||
}
|
||||
checkbox.checked = localStorage.getItem('dark')
|
||||
checkbox.checked = localStorage.getItem("dark");
|
||||
|
||||
checkbox.addEventListener("click", function () {
|
||||
localStorage.setItem("dark", this.checked)
|
||||
if (this.checked) {
|
||||
switchToDark()
|
||||
} else {
|
||||
switchToLight()
|
||||
}
|
||||
})
|
||||
localStorage.setItem("dark", this.checked);
|
||||
if (this.checked) {
|
||||
switchToDark();
|
||||
} else {
|
||||
localStorage.removeItem("dark");
|
||||
switchToLight();
|
||||
}
|
||||
});
|
||||
|
||||
function switchToLight() {
|
||||
// for some reason this needs to be set to null
|
||||
// i am losing my mind
|
||||
localStorage.removeItem("dark")
|
||||
body.classList.add('light')
|
||||
for (let item of colorswitchers) {
|
||||
item.classList.add("light");
|
||||
}
|
||||
}
|
||||
|
||||
function switchToDark() {
|
||||
body.classList.remove('light')
|
||||
for (let item of colorswitchers) {
|
||||
console.log(item);
|
||||
item.classList.remove("light");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue