From 51cb1c38add7ca81f6e098c06bee5c1c6391f9e5 Mon Sep 17 00:00:00 2001
From: Evorp <3vorpgaming@gmail.com>
Date: Sun, 7 Jul 2024 16:07:48 -0700
Subject: [PATCH] less terrible theme code
---
_layouts/default.html | 2 +-
js/theme.js | 34 ++++++++++++++++++++--------------
2 files changed, 21 insertions(+), 15 deletions(-)
diff --git a/_layouts/default.html b/_layouts/default.html
index 80fa8edd..971bbc64 100644
--- a/_layouts/default.html
+++ b/_layouts/default.html
@@ -254,7 +254,7 @@
-
+
Auto Theme
diff --git a/js/theme.js b/js/theme.js
index ae85b71d..67ae4997 100644
--- a/js/theme.js
+++ b/js/theme.js
@@ -42,25 +42,31 @@ window.theme = {
get nextTheme() {
return THEME_VALUES[(this.currentThemeIndex + 1) % THEME_VALUES.length].value
},
- set nextTheme(_v) {}
+ set nextTheme(_v) {},
+
+ get isDark() {
+ return (
+ theme.currentTheme === 'dark' ||
+ (theme.currentTheme === 'auto' && matchMedia('(prefers-color-scheme: dark)').matches)
+ )
+ },
+
+ get isLight() {
+ return !this.isDark;
+ }
}
// update btn
btn.innerHTML = theme.currentThemeHTML
-window.changeMod = (change) => {
- // true if the btn calls the method, false otherwise
- if (change) {
- window.theme.currentTheme = theme.nextTheme
- btn.innerHTML = theme.currentThemeHTML
- }
+window.cycleTheme = () => {
+ window.theme.currentTheme = theme.nextTheme
+ btn.innerHTML = theme.currentThemeHTML
+ updateTheme()
+}
- // update theme
- const isDark = (
- theme.currentTheme === 'dark' ||
- (theme.currentTheme === 'auto' && matchMedia('(prefers-color-scheme: dark)').matches)
- )
- css.href = isDark ? '/css/dark.css' : '/css/light.css'
+window.updateTheme = () => {
+ css.href = theme.isDark ? '/css/dark.css' : '/css/light.css'
}
-changeMod(false)
+updateTheme()