⚡ feat: clean js code
This commit is contained in:
parent
26ad170d9f
commit
2f80b0b5ad
@ -1,15 +1,14 @@
|
|||||||
var themeSwitcher = document.querySelector('.theme-switcher input');
|
const themeSwitcher = document.querySelector('.theme-switcher input');
|
||||||
var currentTheme = localStorage.getItem('theme');
|
const currentTheme = localStorage.getItem('theme');
|
||||||
|
|
||||||
// detect the user's preferred color scheme and activate it
|
// detect the user's preferred color scheme and activate it
|
||||||
if (currentTheme) {
|
if (currentTheme) {
|
||||||
document.documentElement.setAttribute('data-theme', currentTheme);
|
document.documentElement.setAttribute( 'data-theme', currentTheme);
|
||||||
if (currentTheme === 'dark') {
|
themeSwitcher.checked = currentTheme === 'dark';
|
||||||
themeSwitcher.checked = true;
|
} else {
|
||||||
}
|
const isSystemDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||||
} else if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
document.documentElement.setAttribute( 'data-theme', isSystemDark? 'dark' : 'light');
|
||||||
document.documentElement.setAttribute('data-theme', 'dark');
|
themeSwitcher.checked = isSystemDark;
|
||||||
themeSwitcher.checked = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// switch between themes
|
// switch between themes
|
||||||
|
Loading…
x
Reference in New Issue
Block a user