mirror of
https://github.com/bookorbit/bookorbit.git
synced 2026-11-03 08:21:39 -06:00
876e32654a
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
21 lines
813 B
JavaScript
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)
|
|
})()
|