Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/AmazingRise/hugo-theme-diary.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authoramazingrise <8315221+AmazingRise@users.noreply.github.com>2021-09-18 12:15:14 +0300
committeramazingrise <8315221+AmazingRise@users.noreply.github.com>2021-09-18 12:15:14 +0300
commitae81c0fcf360b449d73d7c220ab5bf65f57d690f (patch)
tree8cba7988b84201cb41a650447e05cac1d1ab866c /static
parent4a1b3df7d03398d58e44e37dd799f6ca7c356c3d (diff)
Dark mode optimization.
Diffstat (limited to 'static')
-rw-r--r--static/js/journal.js38
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 () {