diff options
author | WeedSmokingJew <59340248+KushBlazingJudah@users.noreply.github.com> | 2021-08-17 20:15:44 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-17 20:15:44 -0300 |
commit | 17e54854794dacac8409cd10ffb77005d74b8dbe (patch) | |
tree | 1ef3612a0063e3c8bc4293e5ba31dc50097f7c7e /static/js/themes.js | |
parent | 21917eb2ea72fe40d70c2c991e821aace5430c23 (diff) | |
parent | 9552ec24b1631032acbf1efbe21479ff44b29a63 (diff) |
Merge pull request #1 from KushBlazingJudah/darkmode
merge in darkmode
Diffstat (limited to 'static/js/themes.js')
-rw-r--r-- | static/js/themes.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/static/js/themes.js b/static/js/themes.js new file mode 100644 index 0000000..0d9772f --- /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"); +} |