summaryrefslogtreecommitdiffstats
path: root/assets/js
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--assets/js/theme-switch.js12
1 files changed, 8 insertions, 4 deletions
diff --git a/assets/js/theme-switch.js b/assets/js/theme-switch.js
index c3f3949..caffe6e 100644
--- a/assets/js/theme-switch.js
+++ b/assets/js/theme-switch.js
@@ -2,12 +2,16 @@ if(localStorage.getItem("color-scheme") === null) {
const newColorScheme = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? "dark" : "light";
const newTextScheme = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? "Light mode" : "Dark mode";
jtd.setTheme(newColorScheme);
- toggleDarkMode.textContent = newTextScheme;
localStorage.setItem("color-scheme",newColorScheme);
localStorage.setItem("text-scheme",newTextScheme);
+ window.addEventListener('load', function () {
+ toggleDarkMode.textContent = newTextScheme;
+ });
} else {
jtd.setTheme(localStorage.getItem("color-scheme"));
- toggleDarkMode.textContent = localStorage.getItem("text-scheme");
+ window.addEventListener('load', function () {
+ toggleDarkMode.textContent = localStorage.getItem("text-scheme");
+ });
}
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
@@ -24,8 +28,8 @@ window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', eve
const toggleDarkMode = document.querySelector('.js-toggle-dark-mode');
jtd.addEvent(toggleDarkMode, 'click', function(){
- const newColorScheme = jtd.getTheme() === 'dark' ? "dark" : "light";
- const newTextScheme = jtd.getTheme() === 'dark' ? "Light mode" : "Dark mode";
+ const newColorScheme = jtd.getTheme() !== 'dark' ? "dark" : "light";
+ const newTextScheme = jtd.getTheme() !== 'dark' ? "Light mode" : "Dark mode";
jtd.setTheme(newColorScheme);
toggleDarkMode.textContent = newTextScheme;
localStorage.setItem("color-scheme",newColorScheme);