Skip to content

Commit

Permalink
feat: follow system preferences when dark mode isn't fiddled with
Browse files Browse the repository at this point in the history
fix #170
  • Loading branch information
BreadGenie committed Jul 11, 2023
1 parent a04ee41 commit 901c503
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion wiki/public/js/wiki.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ window.Wiki = class Wiki {
}
const darkMode = localStorage.getItem("darkMode");

if (darkMode === null || darkMode === "false") {
if (
(!("darkMode" in localStorage) &&
!window.matchMedia?.("(prefers-color-scheme: dark)")?.matches) ||
darkMode === "false"
) {
$(".sun-moon-container .feather-sun").removeClass("hide");
} else {
$(".sun-moon-container .feather-moon").removeClass("hide");
Expand Down
3 changes: 2 additions & 1 deletion wiki/wiki/doctype/wiki_page/templates/wiki_navbar.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

<script>
if (localStorage.getItem("darkMode") === "true") document.body.classList.add("dark");
if (localStorage.getItem("darkMode") === "true" || (!("darkMode" in localStorage) && window.matchMedia?.("(prefers-color-scheme: dark)")?.matches))
document.body.classList.add("dark");
</script>

<nav class="wiki-navbar navbar navbar-light navbar-expand-lg sticky-top pr-4">
Expand Down

0 comments on commit 901c503

Please sign in to comment.