More AI
This commit is contained in:
parent
f3fc893675
commit
bb5b4c4cf3
43 changed files with 585 additions and 524 deletions
22
src/scripts/theme-init.js
Normal file
22
src/scripts/theme-init.js
Normal 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;
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue