Files
bookorbit/client/public/theme-init.js
T
neon 876e32654a feat(client): support system theme mode
Add system preference option for appearance theme with auto-switching based on OS color scheme settings. Update default theme preference to system and listen for OS dark mode changes dynamically.

Closes #695
2026-07-15 15:22:15 +00:00

21 lines
813 B
JavaScript

;(function () {
function readStoredValue(key, fallback) {
var stored = localStorage.getItem(key)
if (stored === null) return fallback
try {
return JSON.parse(stored)
} catch {
return stored
}
}
var theme = readStoredValue('theme', 'system')
var accent = readStoredValue('accent', 'neutral')
var radius = readStoredValue('radius', 'default')
var systemDark = typeof window.matchMedia === 'function' && window.matchMedia('(prefers-color-scheme: dark)').matches
var isDark = theme === 'dark' || (theme !== 'light' && systemDark)
if (isDark) document.documentElement.classList.add('dark')
if (accent !== 'neutral') document.documentElement.classList.add('accent-' + accent)
if (radius !== 'default') document.documentElement.classList.add('radius-' + radius)
})()