LAN_Portal/theme.js
2026-10-16 16:22:59 -04:00

21 lines
893 B
JavaScript
Executable file

// Applies the theme: the visitor's saved choice if there is one, otherwise the site defaults.
(function () {
var root = document.documentElement;
var dark = window.matchMedia('(prefers-color-scheme: dark)');
var modes = ['light', 'dark', 'auto'];
var current = {};
function apply(prefs) {
current = prefs || {};
var mode = modes.indexOf(current.mode) >= 0 ? current.mode : root.dataset.defaultMode;
root.dataset.bsTheme = mode === 'auto' ? (dark.matches ? 'dark' : 'light') : mode;
root.dataset.accent = current.accent || root.dataset.defaultAccent;
}
var saved = {};
try { saved = JSON.parse(localStorage.getItem('portal-appearance')) || {}; } catch (e) {}
apply(saved);
dark.addEventListener('change', function () { apply(current); });
window.portalTheme = { key: 'portal-appearance', apply: apply, current: function () { return current; } };
})();