-
Notifications
You must be signed in to change notification settings - Fork 0
/
prescript.js
1 lines (1 loc) · 915 Bytes
/
prescript.js
1
(function(){var r=window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark",c=localStorage.getItem("theme")??r;document.documentElement.setAttribute("saved-theme",c);var m=t=>{let d=new CustomEvent("themechange",{detail:{theme:t}});document.dispatchEvent(d)};document.addEventListener("nav",()=>{let t=a=>{let e=a.target?.checked?"dark":"light";document.documentElement.setAttribute("saved-theme",e),localStorage.setItem("theme",e),m(e)},d=a=>{let e=a.matches?"dark":"light";document.documentElement.setAttribute("saved-theme",e),localStorage.setItem("theme",e),n.checked=a.matches,m(e)},n=document.querySelector("#darkmode-toggle");n.addEventListener("change",t),window.addCleanup(()=>n.removeEventListener("change",t)),c==="dark"&&(n.checked=!0);let o=window.matchMedia("(prefers-color-scheme: dark)");o.addEventListener("change",d),window.addCleanup(()=>o.removeEventListener("change",d))})})();