Skip to content

Commit

Permalink
default to browsers preferred color scheme, but persist and prefer th…
Browse files Browse the repository at this point in the history
…e users choice, fixes #17
  • Loading branch information
elrido committed Jan 21, 2021
1 parent 1611c7c commit 059a1fd
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions css/dark-mode-switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
);
}
function initTheme() {
var darkThemeSelected =
localStorage.getItem("darkSwitch") !== null &&
localStorage.getItem("darkSwitch") === "dark";
var darkThemeSelected = localStorage.getItem("darkSwitch") !== null
? localStorage.getItem("darkSwitch") === "dark"
: window.matchMedia("(prefers-color-scheme: dark)").matches;
darkSwitch.checked = darkThemeSelected;
darkThemeSelected
? enableDark()
Expand All @@ -39,7 +39,7 @@
localStorage.setItem("darkSwitch", "dark");
} else {
disableDark();
localStorage.removeItem("darkSwitch");
localStorage.setItem("darkSwitch", "light");
}
}
}
Expand Down

0 comments on commit 059a1fd

Please sign in to comment.