aboutsummaryrefslogtreecommitdiff
path: root/views/js/themes.js
diff options
context:
space:
mode:
authorFChannel <>2021-10-24 10:40:45 -0700
committerFChannel <>2022-06-19 12:53:29 -0700
commit48fefb76c0a908cc3fa00abc9c090ce3ac8cb560 (patch)
treea7a24aec9f43222949e1f004fd5cd8a247e5024e /views/js/themes.js
parent65e79e6a743f447f320595dafec530212a568b9d (diff)
gofiber conversion, index, board posts, board post hooked up
Diffstat (limited to 'views/js/themes.js')
-rw-r--r--views/js/themes.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/views/js/themes.js b/views/js/themes.js
new file mode 100644
index 0000000..ccdd277
--- /dev/null
+++ b/views/js/themes.js
@@ -0,0 +1,40 @@
+function setCookie(key, value, age) {
+ document.cookie = key + "=" + encodeURIComponent(value) + ";sameSite=strict;max-age=" + (60 * 60 * 24 * age) + ";path=/";
+}
+
+function getCookie(key) {
+ if (document.cookie.length != 0) {
+ return document.cookie.split('; ').find(row => row.startsWith(key)).split('=')[1];
+ }
+ return "";
+}
+
+function setTheme(name) {
+ for (let i = 0, tags = document.getElementsByTagName("link"); i < tags.length; i++) {
+ if (tags[i].type === "text/css" && tags[i].title) {
+ tags[i].disabled = !(tags[i].title === name);
+ }
+ }
+
+ setCookie("theme", name, 3650);
+}
+
+function applyTheme() {
+ // HACK: disable all of the themes first. this for some reason makes things work.
+ for (let i = 0, tags = document.getElementsByTagName("link"); i < tags.length; i++) {
+ if (tags[i].type === "text/css" && tags[i].title) {
+ tags[i].disabled = true;
+ }
+ }
+ let theme = getCookie("theme") || "default";
+ setTheme(theme);
+
+ // reflect this in the switcher
+ let switcher = document.getElementById("themeSwitcher");
+ for(var i = 0; i < switcher.options.length; i++) {
+ if (switcher.options[i].value === theme) {
+ switcher.selectedIndex = i;
+ break;
+ }
+ }
+}