1 line
1.0 KiB
JavaScript
1 line
1.0 KiB
JavaScript
const body=document.body,darkModeToggle=document.getElementById("dark-mode-toggle"),darkModeMediaQuery=window.matchMedia("(prefers-color-scheme: dark)");localStorage.getItem("colorscheme")?setTheme(localStorage.getItem("colorscheme")):body.classList.contains("colorscheme-light")||body.classList.contains("colorscheme-dark")?setTheme(body.classList.contains("colorscheme-dark")?"dark":"light"):setTheme(darkModeMediaQuery.matches?"dark":"light"),darkModeToggle&&darkModeToggle.addEventListener("click",()=>{let e=body.classList.contains("colorscheme-dark")?"light":"dark";setTheme(e),rememberTheme(e)}),darkModeMediaQuery.addListener(e=>{setTheme(e.matches?"dark":"light")}),document.addEventListener("DOMContentLoaded",function(){let e=document.querySelector(".preload-transitions");e.classList.remove("preload-transitions")});function setTheme(e){body.classList.remove("colorscheme-auto");let t=e==="dark"?"light":"dark";body.classList.remove("colorscheme-"+t),body.classList.add("colorscheme-"+e)}function rememberTheme(e){localStorage.setItem("colorscheme",e)} |