mirror of https://github.com/jpanther/congo.git
1 line
1.5 KiB
JavaScript
1 line
1.5 KiB
JavaScript
|
const sitePreference=document.documentElement.getAttribute("data-default-appearance"),userPreference=localStorage.getItem("appearance");function getCSSValue(e){var t=window.getComputedStyle(document.documentElement).getPropertyValue(e);return"rgb("+t.replace(/\s+/g,"")+")"}function setThemeColor(){var e=document.querySelector("meta[name=theme-color]");return document.documentElement.classList.contains("dark")?e.setAttribute("content",getCSSValue("--color-neutral-800")):e.setAttribute("content",getCSSValue("--color-neutral")),!0}(sitePreference==="dark"&&userPreference===null||userPreference==="dark")&&(document.documentElement.classList.add("dark"),setThemeColor()),document.documentElement.getAttribute("data-auto-appearance")==="true"&&(window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches&&userPreference!=="light"&&(document.documentElement.classList.add("dark"),setThemeColor()),window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",e=>{e.matches?document.documentElement.classList.add("dark"):document.documentElement.classList.remove("dark"),setThemeColor()})),window.addEventListener("DOMContentLoaded",e=>{var t=document.querySelectorAll("[id^='appearance-switcher']");t.forEach(e=>{e.addEventListener("click",()=>{document.documentElement.classList.toggle("dark"),setThemeColor(),localStorage.setItem("appearance",document.documentElement.classList.contains("dark")?"dark":"light")}),e.addEventListener("contextmenu",e=>{e.preventDefault(),localStorage.removeItem("appearance")})})})
|