// Theme override: System (no attribute, the OS decides), Light or Dark. // // A classic script loaded from , not a module, so the saved choice is on // before the first paint and a Dark user on a light OS never sees a // flash. The CSP allows no inline script, hence a file of its own. Account // (account.js) reads and writes the choice through window.terdutTheme. (function () { var KEY = 'terdut.theme'; var COLORS = { light: '#f5f6f8', dark: '#0f1115' }; function get() { try { var v = localStorage.getItem(KEY); return v === 'light' || v === 'dark' ? v : 'system'; } catch (e) { return 'system'; // storage unavailable } } // The browser chrome colour follows the choice too; the two s are // media-keyed to the OS, so a forced theme sets both to the same colour. function apply(theme) { var root = document.documentElement; if (theme === 'system') root.removeAttribute('data-theme'); else root.setAttribute('data-theme', theme); var metas = document.querySelectorAll('meta[name="theme-color"]'); for (var i = 0; i < metas.length; i++) { var scheme = /dark/.test(metas[i].media) ? 'dark' : 'light'; metas[i].content = COLORS[theme === 'system' ? scheme : theme]; } } function set(theme) { try { if (theme === 'system') localStorage.removeItem(KEY); else localStorage.setItem(KEY, theme); } catch (e) { /* storage unavailable: applies for this page view only */ } apply(theme); } window.terdutTheme = { get: get, set: set }; apply(get()); })();