/** * Applies the user's stored theme to a static page. * * The React surfaces do this through `useTheme`, but the help and privacy pages * have no React and no settings hook — so without this, someone who has chosen * Dark in Settings clicks Help and gets a white page. The stylesheet already * honours `prefers-color-scheme`, so this only has to handle the case where the * explicit preference differs from the system one. * * Deliberately tiny and failure-tolerant: if storage is unreadable for any * reason, the page still renders in the system theme rather than not at all. */ const STORAGE_KEY = 'enggauge.settings.v1' async function apply(): Promise { try { const raw = await chrome.storage.local.get(STORAGE_KEY) const theme = (raw[STORAGE_KEY] as { theme?: string } | undefined)?.theme if (theme === 'light' || theme === 'dark') { document.documentElement.setAttribute('data-theme', theme) } } catch { // System theme it is. } } void apply()