From b5013b5817e21602b8a6bc5a8b6f0c22436ea5bd Mon Sep 17 00:00:00 2001 From: Greenscreener Date: Sat, 26 Oct 2019 18:23:52 +0200 Subject: [PATCH] Implemented darkmode, without UI. Resolved #3. --- themes/patek/assets/js/dark-mode.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/themes/patek/assets/js/dark-mode.js b/themes/patek/assets/js/dark-mode.js index ddaff24..8d24f97 100644 --- a/themes/patek/assets/js/dark-mode.js +++ b/themes/patek/assets/js/dark-mode.js @@ -1,5 +1,21 @@ document.addEventListener("DOMContentLoaded", () => { - if (window.location.search.indexOf("darkmode=true") > -1) { - document.getElementById("content").classList.add("dark-mode"); + if (window.location.search.indexOf("darkmode=false") > -1) { + document.cookie = "darkmode=false; path=/"; + try { + document.getElementById("content").classList.remove("dark-mode"); + } catch (error) { + if (error.message !== "document.getElementById(...) is null") { + throw error; + } + } + } else if (window.location.search.indexOf("darkmode=true") > -1 || document.cookie.indexOf("darkmode=true") > -1) { + document.cookie = "darkmode=true; path=/"; + try { + document.getElementById("content").classList.add("dark-mode"); + } catch (error) { + if (error.message !== "document.getElementById(...) is null") { + throw error; + } + } } });