Spaces:
Running
Running
File size: 1,349 Bytes
03c9ca7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | /* Light/dark mode on both sites. Persisted (strictly necessary localStorage), honors
prefers-color-scheme on first visit. Toggle button: #theme-btn in the nav. */
(function () {
var KEY = 'uas_theme';
function apply(t) {
document.documentElement.setAttribute('data-theme', t);
var b = document.getElementById('theme-btn');
if (b) b.textContent = t === 'dark' ? '☀️' : '🌙';
var m = document.querySelector('meta[name="theme-color"]');
if (m) m.setAttribute('content', t === 'dark' ? '#08111B' : '#ffffff');
}
window.Theme = {
current: function () {
var s = null;
try { s = localStorage.getItem(KEY); } catch (e) {}
if (!s) s = document.documentElement.getAttribute('data-theme'); // brand default in HTML
if (!s) s = (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) ? 'dark' : 'light';
return s;
},
init: function () { apply(this.current()); },
toggle: function () {
var t = this.current() === 'dark' ? 'light' : 'dark';
try { localStorage.setItem(KEY, t); } catch (e) {}
apply(t);
}
};
window.addEventListener('DOMContentLoaded', function () {
Theme.init();
var b = document.getElementById('theme-btn');
if (b) b.addEventListener('click', function () { Theme.toggle(); });
});
})();
|