aboutsummaryrefslogtreecommitdiff
path: root/res/js/themeswap.js
diff options
context:
space:
mode:
authorFrankie B <floppydisk05@aol.com>2022-07-05 15:38:32 +0100
committerFrankie B <floppydisk05@aol.com>2022-07-05 15:38:32 +0100
commit8cfb858b77d276448a8075b482cf533397bf926b (patch)
tree595c26d7354eeca09a6df14ff64d1f9b90d4229f /res/js/themeswap.js
parentdc625dcbe5203598a1cdb25a360b94f92df97697 (diff)
Add existing files
Diffstat (limited to 'res/js/themeswap.js')
-rwxr-xr-xres/js/themeswap.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/res/js/themeswap.js b/res/js/themeswap.js
new file mode 100755
index 0000000..12969a0
--- /dev/null
+++ b/res/js/themeswap.js
@@ -0,0 +1,26 @@
+function addStyleSheet(name, id) {
+ var path = '/res/css/' + name + '.min.css';
+ var old = document.getElementById(id);
+ if (old && (old.href != path)) {
+ old.href = path;
+ }
+}
+
+var otherTheme = {
+ 'dark': 'light',
+ 'light': 'dark',
+};
+
+var currentTheme = localStorage.getItem('theme');
+
+if (!otherTheme.hasOwnProperty(currentTheme)) {
+ currentTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
+}
+
+addStyleSheet(currentTheme, 'theme');
+
+function toggleTheme() {
+ currentTheme = otherTheme[currentTheme] || 'light';
+ localStorage.setItem('theme', currentTheme);
+ addStyleSheet(currentTheme, 'theme');
+} \ No newline at end of file