1
0
wiki/prescript.js

2 lines
903 B
JavaScript
Raw Normal View History

2024-09-06 10:58:26 +08:00
(function(){var o=window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark",r=localStorage.getItem("theme")??o;document.documentElement.setAttribute("saved-theme",r);var d=t=>{let n=new CustomEvent("themechange",{detail:{theme:t}});document.dispatchEvent(n)};document.addEventListener("nav",()=>{let t=c=>{let e=document.documentElement.getAttribute("saved-theme")==="dark"?"light":"dark";document.documentElement.setAttribute("saved-theme",e),localStorage.setItem("theme",e),d(e)},n=c=>{let e=c.matches?"dark":"light";document.documentElement.setAttribute("saved-theme",e),localStorage.setItem("theme",e),d(e)},a=document.querySelector("#darkmode");a.addEventListener("click",t),window.addCleanup(()=>a.removeEventListener("click",t));let m=window.matchMedia("(prefers-color-scheme: dark)");m.addEventListener("change",n),window.addCleanup(()=>m.removeEventListener("change",n))})})();