23 lines
728 B
JavaScript
Executable File
23 lines
728 B
JavaScript
Executable File
function updateLights(dark) {
|
|
document.body.classList.toggle("dark", dark)
|
|
|
|
const date = new Date()
|
|
date.setDate(date.getDate() + 30)
|
|
|
|
document.cookie = `dark=${!dark ? "" : "1"}; expires=${date.toDateString()}`
|
|
}
|
|
|
|
window.addEventListener("load", () => {
|
|
const lightButton = document.getElementsByClassName("light-button")[0]
|
|
lightButton.classList.remove("hidden")
|
|
|
|
const lightToggle = lightButton.querySelector(".light-toggle")
|
|
|
|
lightToggle.addEventListener("input", () => updateLights(!lightToggle.checked))
|
|
|
|
// Check for existing dark mode cookie
|
|
const darkModeCookie = document.cookie.split(" ").some(c => { if (c.startsWith("dark=")) return c.startsWith("dark=1") })
|
|
|
|
// lightToggle.checked = !darkModeCookie
|
|
})
|