summaryrefslogtreecommitdiff
path: root/player-server/web/js/themes.js
blob: e952140a067b813e459fe4604e5ac0e9f3290791 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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');
}