diff options
Diffstat (limited to 'static/js/journal.js')
-rw-r--r-- | static/js/journal.js | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/static/js/journal.js b/static/js/journal.js index 6b4a91f..8893bf8 100644 --- a/static/js/journal.js +++ b/static/js/journal.js @@ -212,27 +212,8 @@ document.querySelectorAll("table").forEach(function (elem) { // Night mode -var night = document.cookie.replace( - /(?:(?:^|.*;\s*)night\s*\=\s*([^;]*).*$)|^.*$/, - "$1" -); - var isDarkMode = false; -if (night == "") { - if ( - window.matchMedia && - window.matchMedia("(prefers-color-scheme: dark)").matches - ) { - isDarkMode = true; - } -} else { - // If night is not empty - if (night == "1") { - isDarkMode = true; - } -} - var toggleDarkMode = function () { isDarkMode = !isDarkMode; let icon = document.getElementById("darkModeToggleIcon"); @@ -250,6 +231,25 @@ var toggleDarkMode = function () { } }; +let night = document.cookie.replace( + /(?:(?:^|.*;\s*)night\s*\=\s*([^;]*).*$)|^.*$/, + "$1" +); + +if (night == "") { + if ( + window.matchMedia && + window.matchMedia("(prefers-color-scheme: dark)").matches + ) { + toggleDarkMode(); + } +} else { + // If night is not empty + if (night === "1") { + toggleDarkMode(); + } +} + document .getElementById("darkModeToggleButton") .addEventListener("click", function () { |