fix prefered theme

master
parent 879ba65373
commit d6e40ea071
  1. 4
      theme/static/css/main.css
  2. 12
      theme/templates/base.html

@ -27,6 +27,10 @@ body[theme=dark] {
--lightColor: #a8a8a8;
--backgroundColor: #2a2a2a;
}
body::after {
content: 'dark';
display: none;
}
}
html, body {

@ -45,10 +45,18 @@
document.body.setAttribute('theme', themeName);
return themeName;
}
function getPreferedTheme() {
let preferedTheme = window.getComputedStyle(document.body, '::after').content;
if (preferedTheme !== undefined) {
return preferedTheme.replace(/"/g, '');
}
return 'light';
}
let darkModeToggleElement = document.getElementById('darkModeToggle');
let theme = localStorage.getItem('theme') || 'light';
let theme = localStorage.getItem('theme') || getPreferedTheme();
setTheme(theme);
darkModeToggle.addEventListener('click', (e) => {

Loading…
Cancel
Save