This commit is contained in:
Andras Schmelczer 2026-05-11 21:30:57 +01:00
parent f3fc893675
commit bb5b4c4cf3
43 changed files with 585 additions and 524 deletions

22
src/scripts/theme-init.js Normal file
View file

@ -0,0 +1,22 @@
(function () {
var key = 'theme';
var legacyKey = 'dark-mode';
var saved = null;
try {
var value = localStorage.getItem(key);
if (value === 'light' || value === 'dark') {
saved = value;
} else {
var legacyValue = localStorage.getItem(legacyKey);
if (legacyValue !== null) {
saved = JSON.parse(legacyValue) ? 'dark' : 'light';
}
}
} catch (e) {
saved = null;
}
var systemDark = matchMedia('(prefers-color-scheme: dark)').matches;
var theme = saved || (systemDark ? 'dark' : 'light');
document.documentElement.dataset.theme = theme;
document.documentElement.style.colorScheme = theme;
})();