Add: Theme switcher

This commit is contained in:
hyzen
2026-03-03 15:27:18 +05:30
parent c0ddb10f4b
commit 83fdcac429
27 changed files with 637 additions and 346 deletions

View File

@@ -1 +1,24 @@
{{- /* You can dynamically load scripts in this file */ -}}
<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>

View File

@@ -12,4 +12,12 @@
<!-- Direct custom CSS -->
<link rel="stylesheet" href="{{ "css/custom.css" | relURL }}">
<!-- Theme switcher: run before paint to avoid flash -->
<script>
(function(){
var t = localStorage.getItem('theme');
if (t) { document.documentElement.setAttribute('data-theme', t); }
})();
</script>
{{ partial "head/head-end.html" . }}