mirror of
https://github.com/tchartron/blow
synced 2024-11-27 23:00:25 +00:00
1 line
No EOL
1.6 KiB
JavaScript
1 line
No EOL
1.6 KiB
JavaScript
function switchTheme(){"dark"==([...document.documentElement.classList].includes("dark")?"dark":"light")?(localStorage.theme="light",document.documentElement.classList.remove("dark"),document.getElementById("light").classList.add("hidden"),document.getElementById("dark").classList.remove("hidden")):(localStorage.theme="dark",document.documentElement.classList.add("dark"),document.getElementById("dark").classList.add("hidden"),document.getElementById("light").classList.remove("hidden"))}function toggleSidebar(){let e=document.getElementById("sidebar");[...e.classList].includes("translate-x-0")?(document.body.style.removeProperty("overflow"),e.classList.remove("translate-x-0"),e.classList.add("-translate-x-full")):(document.body.style.setProperty("overflow","hidden"),e.classList.remove("-translate-x-full"),e.classList.add("translate-x-0"))}document.addEventListener("DOMContentLoaded",function(){var e=document.querySelector("#nav-links").children;let t=window.location.href,d=[...e].find(e=>e.href===t);void 0!==d&&(d.className="bg-gray-900 text-white px-3 py-2 rounded-md text-sm font-medium"),"dark"===localStorage.theme||!("theme"in localStorage)&&window.matchMedia("(prefers-color-scheme: dark)").matches?(document.documentElement.classList.add("dark"),document.getElementById("dark").classList.add("hidden")):(document.documentElement.classList.remove("dark"),document.getElementById("light").classList.add("hidden")),document.getElementById("switch-theme").addEventListener("click",switchTheme),document.getElementById("toggle-sidebar").addEventListener("click",toggleSidebar)}); |