raycer/frontend/public/js/theme.js
Spencer Flagg ed3a0d3ea3 Initial commit: raycer accountability PWA
Vanilla HTML/JS/CSS PWA with Dexie offline-first sync, Hono+SQLite backend,
served via nginx reverse-proxy. Two seed goals (no-sugar, no-social-media)
for users ray and cer.

Local dev runs at https://raycer.test via the shared Traefik proxy.
Production deploys to https://raycer.altweb.me on cool2026/personal via
docker-compose.coolify.yaml — see deploy/COOLIFY.md.
2026-04-23 16:45:06 +02:00

26 lines
655 B
JavaScript

import { getTheme, setTheme } from './db.js';
const THEMES = ['auto', 'dark', 'light'];
function applyTheme(value) {
const root = document.documentElement;
if (value === 'auto') root.removeAttribute('data-theme');
else root.setAttribute('data-theme', value);
}
export async function initTheme() {
const t = await getTheme();
applyTheme(t || 'auto');
}
export async function cycleTheme() {
const cur = (await getTheme()) || 'auto';
const next = THEMES[(THEMES.indexOf(cur) + 1) % THEMES.length];
await setTheme(next);
applyTheme(next);
return next;
}
export async function currentTheme() {
return (await getTheme()) || 'auto';
}