summaryrefslogtreecommitdiffstats
path: root/assets/js/theme-switch.js
diff options
context:
space:
mode:
authorSimone Bortolin <simonebortolin@users.noreply.github.com>2022-08-04 20:32:06 +0200
committerSimone Bortolin <simonebortolin@users.noreply.github.com>2022-12-19 22:55:44 +0100
commitabdbcb1a85b9f76efc7a000e06afdaaf4caa0966 (patch)
treeb210446698c234f08e6e87a7032183ff9bee8084 /assets/js/theme-switch.js
parentMerge branch 'main' of github.com:hack-gpon/hack-gpon.github.io (diff)
downloadhack-gpon.github.io-abdbcb1a85b9f76efc7a000e06afdaaf4caa0966.tar
hack-gpon.github.io-abdbcb1a85b9f76efc7a000e06afdaaf4caa0966.tar.gz
hack-gpon.github.io-abdbcb1a85b9f76efc7a000e06afdaaf4caa0966.tar.bz2
hack-gpon.github.io-abdbcb1a85b9f76efc7a000e06afdaaf4caa0966.tar.lz
hack-gpon.github.io-abdbcb1a85b9f76efc7a000e06afdaaf4caa0966.tar.xz
hack-gpon.github.io-abdbcb1a85b9f76efc7a000e06afdaaf4caa0966.tar.zst
hack-gpon.github.io-abdbcb1a85b9f76efc7a000e06afdaaf4caa0966.zip
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);