From c455494cd617d66bc28a30afb1fbd4377e0ecb01 Mon Sep 17 00:00:00 2001 From: KushBlazingJudah <59340248+KushBlazingJudah@users.noreply.github.com> Date: Mon, 16 Aug 2021 16:35:19 -0300 Subject: extremely basic themes support --- static/js/themes.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 static/js/themes.js (limited to 'static/js') diff --git a/static/js/themes.js b/static/js/themes.js new file mode 100644 index 0000000..70a1b7f --- /dev/null +++ b/static/js/themes.js @@ -0,0 +1,24 @@ +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() { + setTheme(getCookie("theme") || "default"); +} -- cgit v1.2.3