diff options
Diffstat (limited to 'static')
-rw-r--r-- | static/js/themes.js | 24 | ||||
-rw-r--r-- | static/main.html | 9 |
2 files changed, 30 insertions, 3 deletions
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"); +} diff --git a/static/main.html b/static/main.html index 3f819dd..3fa1b66 100644 --- a/static/main.html +++ b/static/main.html @@ -8,10 +8,11 @@ <meta property="og:locale" content="en_US" /> <meta property="og:type" content="website" /> <link rel="icon" type="image/png" href="/static/favicon.png"> - <link rel="stylesheet" type="text/css" href="/static/css/style.css"> + <link rel="stylesheet" type="text/css" href="/static/css/style.css" title="default"> + <link rel="alternate stylesheet" type="text/css" href="/static/css/gruvbox.css" title="gruvbox"> {{ template "header" . }} </head> - <body {{ if not .Board.Restricted }}class="nsfw"{{ end }}> + <body {{ if not .Board.Restricted }}class="nsfw"{{ end }} onload="applyTheme()"> <ul style="display: inline; padding:0;"> {{ $l := len .Boards }} <li style="display: inline;">[<a href="/">Home</a>]</li> @@ -41,8 +42,10 @@ <a href="/">[Home]</a><a href="/static/rules.html">[Rules]</a><a href="/static/faq.html">[FAQ]</a> <p>All trademarks and copyrights on this page are owned by their respective parties.</p> </div> + + <script src="/static/js/themes.js"></script> +{{ template "script" . }} </body> </html> -{{ template "script" . }} {{ end }} |