diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-29 20:19:34 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-29 20:19:34 +0300 |
| commit | 4a70c0ea083306cb79d0fa325d331ffa4333154a (patch) | |
| tree | 84df7e2f781974ef45ac8c34f1a59e80fdd5c41d /web/js/themes.js | |
| parent | cf30414c2a0696cc75c615f4da66ea85d0522c42 (diff) | |
feat: create web PWA frontend
Diffstat (limited to 'web/js/themes.js')
| -rw-r--r-- | web/js/themes.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/web/js/themes.js b/web/js/themes.js new file mode 100644 index 0000000..e952140 --- /dev/null +++ b/web/js/themes.js @@ -0,0 +1,20 @@ +const STORAGE_KEY = 'kiss-theme'; + +export function initThemes() { + const saved = localStorage.getItem(STORAGE_KEY) || 'dark'; + apply(saved); + const btn = document.getElementById('theme-toggle'); + if (btn) btn.addEventListener('click', toggle); +} + +export function apply(theme) { + document.documentElement.setAttribute('data-theme', theme); + localStorage.setItem(STORAGE_KEY, theme); + const btn = document.getElementById('theme-toggle'); + if (btn) btn.textContent = theme === 'dark' ? '☀' : '🌙'; +} + +export function toggle() { + const current = document.documentElement.getAttribute('data-theme') || 'dark'; + apply(current === 'dark' ? 'light' : 'dark'); +} |
