congo/js/appearance.min.74ad8406faea...

1 line
1.5 KiB
JavaScript
Raw Normal View History

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=>{setThemeColor();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")})})})