Skip to content

Commit

Permalink
⚡ feat: clean js code
Browse files Browse the repository at this point in the history
  • Loading branch information
serginogal committed Feb 16, 2023
1 parent 26ad170 commit 2f80b0b
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions static/js/main.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
var themeSwitcher = document.querySelector('.theme-switcher input');
var currentTheme = localStorage.getItem('theme');
const themeSwitcher = document.querySelector('.theme-switcher input');
const currentTheme = localStorage.getItem('theme');

// detect the user's preferred color scheme and activate it
if (currentTheme) {
document.documentElement.setAttribute('data-theme', currentTheme);
if (currentTheme === 'dark') {
themeSwitcher.checked = true;
}
} else if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.documentElement.setAttribute('data-theme', 'dark');
themeSwitcher.checked = true;
document.documentElement.setAttribute( 'data-theme', currentTheme);
themeSwitcher.checked = currentTheme === 'dark';
} else {
const isSystemDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
document.documentElement.setAttribute( 'data-theme', isSystemDark? 'dark' : 'light');
themeSwitcher.checked = isSystemDark;
}

// switch between themes
Expand Down

0 comments on commit 2f80b0b

Please sign in to comment.