kristofersxyz/static/main/js/lightmode.js
2023-01-20 05:25:29 +02:00

27 lines
675 B
JavaScript

let lightmode = localStorage.getItem("lightmode")
const HTML = document.documentElement
console.log(HTML)
const ENABLE_LIGHT_MODE = () => {
HTML.setAttribute("data-color-mode", "light")
localStorage.setItem("lightmode", "enabled")
}
const DISABLE_LIGHT_MODE = () => {
HTML.setAttribute("data-color-mode", "dark")
localStorage.setItem("lightmode", null)
}
if (lightmode === "enabled") {
ENABLE_LIGHT_MODE()
}
document.querySelector("#color-mode-toggle").addEventListener("click", () => {
lightmode = localStorage.getItem("lightmode")
if (lightmode !== "enabled") {
ENABLE_LIGHT_MODE()
} else {
DISABLE_LIGHT_MODE()
}
})