14 lines
374 B
JavaScript
14 lines
374 B
JavaScript
const root = document.documentElement;
|
|
const saved = window?.localStorage?.getItem('theme');
|
|
const sysDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
|
|
if (saved) {
|
|
root.setAttribute('data-theme', saved);
|
|
} else {
|
|
if (sysDark) {
|
|
root.setAttribute('data-theme', 'dark');
|
|
} else {
|
|
root.setAttribute('data-theme', 'light');
|
|
}
|
|
}
|