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 From 9552ec24b1631032acbf1efbe21479ff44b29a63 Mon Sep 17 00:00:00 2001 From: KushBlazingJudah <59340248+KushBlazingJudah@users.noreply.github.com> Date: Mon, 16 Aug 2021 18:56:59 -0300 Subject: = -> == --- static/js/themes.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'static/js') diff --git a/static/js/themes.js b/static/js/themes.js index 70a1b7f..0d9772f 100644 --- a/static/js/themes.js +++ b/static/js/themes.js @@ -11,8 +11,8 @@ function getCookie(key) { 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); + if (tags[i].type === "text/css" && tags[i].title) { + tags[i].disabled = !(tags[i].title === name); } } -- cgit v1.2.3 From 9e782ba01620997becc3118433e3d1961a88b2c3 Mon Sep 17 00:00:00 2001 From: KushBlazingJudah <59340248+KushBlazingJudah@users.noreply.github.com> Date: Wed, 18 Aug 2021 00:26:02 -0300 Subject: rudimentary theme switching --- static/js/themes.js | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'static/js') diff --git a/static/js/themes.js b/static/js/themes.js index 0d9772f..19bdbb4 100644 --- a/static/js/themes.js +++ b/static/js/themes.js @@ -20,5 +20,11 @@ function setTheme(name) { } 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; + } + } setTheme(getCookie("theme") || "default"); } -- cgit v1.2.3 From d460fa6316d3db4e68e6b4d4c7ee2d02d6505304 Mon Sep 17 00:00:00 2001 From: KushBlazingJudah <59340248+KushBlazingJudah@users.noreply.github.com> Date: Wed, 18 Aug 2021 00:50:13 -0300 Subject: it works --- static/js/themes.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'static/js') diff --git a/static/js/themes.js b/static/js/themes.js index 19bdbb4..3f1b906 100644 --- a/static/js/themes.js +++ b/static/js/themes.js @@ -26,5 +26,15 @@ function applyTheme() { tags[i].disabled = true; } } - setTheme(getCookie("theme") || "default"); + 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; + } + } } -- cgit v1.2.3 From 7027fdd87011962b2b177342a462d54737e03501 Mon Sep 17 00:00:00 2001 From: KushBlazingJudah <59340248+KushBlazingJudah@users.noreply.github.com> Date: Wed, 18 Aug 2021 12:57:26 -0300 Subject: theme newpost at top of page --- static/js/posts.js | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) (limited to 'static/js') diff --git a/static/js/posts.js b/static/js/posts.js index 455e7ea..75244fa 100644 --- a/static/js/posts.js +++ b/static/js/posts.js @@ -2,29 +2,16 @@ function startNewPost(){ var el = document.getElementById("newpostbtn"); el.style="display:none;"; el.setAttribute("state", "1"); - document.getElementById("newpost").style = "display: block;"; + document.getElementById("newpost").style = ""; + sessionStorage.setItem("newpostState", true); } function stopNewPost(){ var el = document.getElementById("newpostbtn"); el.style="display:block;"; el.setAttribute("state", "0"); - document.getElementById("newpost").style = "display: hidden;"; -} - -function newpost() -{ - var state = document.getElementById("newpostbtn").getAttribute("state"); - if(state === "0") - { - startNewPost(); - sessionStorage.setItem("newpostState", true); - } - else - { - stopNewPost(); - sessionStorage.setItem("newpostState", false); - } + document.getElementById("newpost").style = "display: none;"; + sessionStorage.setItem("newpostState", false); } function shortURL(actorName, url) -- cgit v1.2.3 From d2cb70e8725371a72c0f9db36ad734041f4fb977 Mon Sep 17 00:00:00 2001 From: KushBlazingJudah <59340248+KushBlazingJudah@users.noreply.github.com> Date: Wed, 18 Aug 2021 13:25:28 -0300 Subject: themeable popup --- static/js/posts.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'static/js') diff --git a/static/js/posts.js b/static/js/posts.js index 75244fa..30f4893 100644 --- a/static/js/posts.js +++ b/static/js/posts.js @@ -169,7 +169,7 @@ function quote(actorName, opid, id) var h = document.getElementById(id + "-content").offsetTop - 348; } - const boxStyle = "display: block; position: absolute; width: 400px; height: 600px; z-index: 9; top: " + h + "px; left: " + w + "px; padding: 5px;"; + const boxStyle = "top: " + h + "px; left: " + w + "px;"; box.setAttribute("style", boxStyle); sessionStorage.setItem("element-reply-style", boxStyle); sessionStorage.setItem("reply-top", h); @@ -189,7 +189,6 @@ function quote(actorName, opid, id) sessionStorage.setItem("element-reply-comment", comment.value); dragElement(header); - } function report(actorName, id) @@ -203,7 +202,7 @@ function report(actorName, id) var w = window.innerWidth / 2 - 200; var h = document.getElementById(id + "-content").offsetTop - 348; - const boxStyle = "display: block; position: absolute; width: 400px; height: 480px; z-index: 9; top: " + h + "px; left: " + w + "px; padding: 5px;"; + const boxStyle = "top: " + h + "px; left: " + w + "px;"; box.setAttribute("style", boxStyle); sessionStorage.setItem("element-report-style", boxStyle); sessionStorage.setItem("report-top", h); -- cgit v1.2.3