amethyst/quartz/js/darkmode.28fb245b04b633307edf3c5e2aea4b01.min.js

1 line
1.1 KiB
JavaScript
Raw Normal View History

const userPref=window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark",currentTheme=localStorage.getItem("theme")??userPref,syntaxTheme=document.querySelector("#theme-link");currentTheme&&(document.documentElement.setAttribute("saved-theme",currentTheme),syntaxTheme.href=currentTheme==="dark"?"https://tablet.sh/quartz/styles/_dark_syntax.bec558461529f0dd343a0b008c343934.min.css":"https://tablet.sh/quartz/styles/_light_syntax.86a48a52faebeaaf42158b72922b1c90.min.css");const switchTheme=e=>{e.target.checked?(document.documentElement.setAttribute("saved-theme","dark"),localStorage.setItem("theme","dark"),syntaxTheme.href="https://tablet.sh/quartz/styles/_dark_syntax.bec558461529f0dd343a0b008c343934.min.css"):(document.documentElement.setAttribute("saved-theme","light"),localStorage.setItem("theme","light"),syntaxTheme.href="https://tablet.sh/quartz/styles/_light_syntax.86a48a52faebeaaf42158b72922b1c90.min.css")};window.addEventListener("DOMContentLoaded",()=>{const e=document.querySelector("#darkmode-toggle");e.addEventListener("change",switchTheme,!1),currentTheme==="dark"&&(e.checked=!0)})