Files
hyzendust.github.io/layouts/_partials/body/body-end.html
2026-03-03 15:27:18 +05:30

25 lines
673 B
HTML

<script>
(function () {
var btn = document.getElementById('theme-toggle');
if (!btn) return;
function getTheme() {
var stored = localStorage.getItem('theme');
if (stored) return stored;
return window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';
}
function applyTheme(theme) {
document.documentElement.setAttribute('data-theme', theme);
localStorage.setItem('theme', theme);
}
applyTheme(getTheme());
btn.addEventListener('click', function () {
var current = document.documentElement.getAttribute('data-theme') || getTheme();
applyTheme(current === 'dark' ? 'light' : 'dark');
});
})();
</script>