diff options
author | FChannel <> | 2022-06-19 12:47:32 -0700 |
---|---|---|
committer | FChannel <> | 2022-06-19 16:03:29 -0700 |
commit | b02f813e519dc890f2eb4827ff52cff3ff90c828 (patch) | |
tree | d020fbdefda52542aab3f4250bf93533e9f38504 /static/js | |
parent | cd99df8d6781c3f0a191d119ea0ddf8c4a16089f (diff) |
v0.1.0
Diffstat (limited to 'static/js')
-rw-r--r-- | static/js/footerscript.js | 44 | ||||
-rw-r--r-- | static/js/posts.js | 344 | ||||
-rw-r--r-- | static/js/themes.js | 40 | ||||
-rw-r--r-- | static/js/timer.js | 38 |
4 files changed, 0 insertions, 466 deletions
diff --git a/static/js/footerscript.js b/static/js/footerscript.js deleted file mode 100644 index 69e56e7..0000000 --- a/static/js/footerscript.js +++ /dev/null @@ -1,44 +0,0 @@ -var imgs = document.querySelectorAll('#img'); -var imgArray = [].slice.call(imgs); - -imgArray.forEach(function(img, i){ - img.addEventListener("click", function(e){ - var id = img.getAttribute("id"); - var media = document.getElementById("media-" + id); - var sensitive = document.getElementById("sensitive-" + id); - - if(img.getAttribute("enlarge") == "0") - { - var attachment = img.getAttribute("attachment"); - img.setAttribute("enlarge", "1"); - img.setAttribute("style", "float: left; margin-right: 10px; cursor: pointer;"); - img.src = attachment; - } - else - { - var preview = img.getAttribute("preview"); - img.setAttribute("enlarge", "0"); - if(img.getAttribute("main") == 1) - { - img.setAttribute("style", "float: left; margin-right: 10px; max-width: 250px; max-height: 250px; cursor: pointer;"); - img.src = preview; - } - else - { - img.setAttribute("style", "float: left; margin-right: 10px; max-width: 125px; max-height: 125px; cursor: pointer;"); - img.src = preview; - } - } - }); -}); - - -function viewLink(board, actor) { - var posts = document.querySelectorAll('#view'); - var postsArray = [].slice.call(posts); - - postsArray.forEach(function(p, i){ - var id = p.getAttribute("post"); - p.href = "/" + board + "/" + shortURL(actor, id); - }); -} diff --git a/static/js/posts.js b/static/js/posts.js deleted file mode 100644 index 87f6228..0000000 --- a/static/js/posts.js +++ /dev/null @@ -1,344 +0,0 @@ -function startNewPost(){ - var el = document.getElementById("newpostbtn"); - el.style="display:none;"; - el.setAttribute("state", "1"); - document.getElementById("newpost").style = ""; - document.getElementById("stopTablePost").style = "display:unset;"; - sessionStorage.setItem("newpostState", true); -} - -function stopNewPost(){ - var el = document.getElementById("newpostbtn"); - el.style="display:block;margin-bottom:100px;"; - el.setAttribute("state", "0"); - document.getElementById("newpost").style = "display: none;"; - sessionStorage.setItem("newpostState", false); -} - -function shortURL(actorName, url) -{ - re = /.+\//g; - temp = re.exec(url); - - var output; - - if(stripTransferProtocol(temp[0]) == stripTransferProtocol(actorName) + "/") - { - var short = url.replace("https://", ""); - short = short.replace("http://", ""); - short = short.replace("www.", ""); - - var re = /^.{3}/g; - - var u = re.exec(short); - - re = /\w+$/g; - - output = re.exec(short); - }else{ - var short = url.replace("https://", ""); - short = short.replace("http://", ""); - short = short.replace("www.", ""); - - var re = /^.{3}/g; - - var u = re.exec(short); - - re = /\w+$/g; - - u = re.exec(short); - - str = short.replace(/\/+/g, " "); - - str = str.replace(u, " ").trim(); - - re = /(\w|[!@#$%^&*<>])+$/; - - v = re.exec(str); - - output = "f" + v[0] + "-" + u - } - - return output; -} - -function getBoardId(url) -{ - var re = /\/([^/\n]+)(.+)?/gm; - var matches = re.exec(url); - return matches[1]; -} - -function convertContent(actorName, content, opid) -{ - var re = /(>>)(https?:\/\/)?(www\.)?.+\/\w+/gm; - var match = content.match(re); - var newContent = content; - if(match) - { - match.forEach(function(quote, i){ - var link = quote.replace('>>', ''); - var isOP = ""; - if(link == opid) - { - isOP = " (OP)"; - } - - var q = link; - - if(document.getElementById(link + "-content") != null) { - q = document.getElementById(link + "-content").innerText; - q = q.replaceAll('>', '/\>'); - q = q.replaceAll('"', ''); - q = q.replaceAll("'", ""); - } - newContent = newContent.replace(quote, '<a class="reply" title="' + q + '" href="'+ (actorName) + "/" + shortURL(actorName, opid) + '#' + shortURL(actorName, link) + '";">>>' + shortURL(actorName, link) + isOP + '</a>'); - - }); - } - - re = /^(\s+)?>.+/gm; - - match = newContent.match(re); - if(match) - { - match.forEach(function(quote, i) { - - newContent = newContent.replace(quote, '<span class="quote">' + quote + '</span>'); - }); - } - - return newContent.replaceAll('/\>', '>'); -} - -function convertContentNoLink(actorName, content, opid) -{ - var re = /(>>)(https?:\/\/)?(www\.)?.+\/\w+/gm; - var match = content.match(re); - var newContent = content; - if(match) - { - match.forEach(function(quote, i){ - var link = quote.replace('>>', ''); - var isOP = ""; - if(link == opid) - { - isOP = " (OP)"; - } - - var q = link; - - if(document.getElementById(link + "-content") != null) { - q = document.getElementById(link + "-content").innerText; - } - - newContent = newContent.replace(quote, '>>' + shortURL(actorName, link) + isOP); - }); - } - newContent = newContent.replaceAll("'", ""); - return newContent.replaceAll('"', ''); -} - -function closeReply() -{ - document.getElementById("reply-box").style.display = "none"; - document.getElementById("reply-comment").value = ""; - - sessionStorage.setItem("element-closed-reply", true); -} - -function closeReport() -{ - document.getElementById("report-box").style.display = "none"; - document.getElementById("report-comment").value = ""; - - sessionStorage.setItem("element-closed-report", true); -} - -function quote(actorName, opid, id) -{ - sessionStorage.setItem("element-closed-reply", false); - var box = document.getElementById("reply-box"); - var header = document.getElementById("reply-header"); - var header_text = document.getElementById("reply-header-text"); - var comment = document.getElementById("reply-comment"); - var inReplyTo = document.getElementById("inReplyTo-box"); - - var w = window.innerWidth / 2 - 200; - var h = 300; //document.getElementById(id + "-content").offsetTop - 348; - - const boxStyle = "top: " + h + "px; left: " + w + "px;"; - box.setAttribute("style", boxStyle); - sessionStorage.setItem("element-reply-style", boxStyle); - sessionStorage.setItem("reply-top", h); - sessionStorage.setItem("reply-left", w); - - - if (inReplyTo.value != opid) - comment.value = ""; - - header_text.innerText = "Replying to Thread No. " + shortURL(actorName, opid); - inReplyTo.value = opid; - sessionStorage.setItem("element-reply-actor", actorName); - sessionStorage.setItem("element-reply-id", inReplyTo.value); - - if(id != "reply") - comment.value += ">>" + id + "\n"; - sessionStorage.setItem("element-reply-comment", comment.value); - - dragElement(header); -} - -function report(actorName, id) -{ - sessionStorage.setItem("element-closed-report", false); - var box = document.getElementById("report-box"); - var header = document.getElementById("report-header"); - var comment = document.getElementById("report-comment"); - var inReplyTo = document.getElementById("report-inReplyTo-box"); - - var w = window.innerWidth / 2 - 200; - var h = 300; //document.getElementById(id + "-content").offsetTop - 348; - - const boxStyle = "top: " + h + "px; left: " + w + "px;"; - box.setAttribute("style", boxStyle); - sessionStorage.setItem("element-report-style", boxStyle); - sessionStorage.setItem("report-top", h); - sessionStorage.setItem("report-left", w); - - header.innerText = "Report Post No. " + shortURL(actorName, id); - inReplyTo.value = id; - sessionStorage.setItem("element-report-actor", actorName); - sessionStorage.setItem("element-report-id", id); - - dragElement(header); -} - -var pos1, pos2, pos3, pos4; -var elmnt; - -function closeDragElement(e) { - // stop moving when mouse button is released: - document.onmouseup = null; - document.onmousemove = null; - sessionStorage.setItem("eventhandler", false); -} - -function elementDrag(e) { - e = e || window.event; - e.preventDefault(); - // calculate the new cursor position: - pos1 = pos3 - e.clientX; - pos2 = pos4 - e.clientY; - pos3 = e.clientX; - pos4 = e.clientY; - sessionStorage.setItem("pos1", pos1); - sessionStorage.setItem("pos2", pos2); - sessionStorage.setItem("pos3", pos3); - sessionStorage.setItem("pos4", pos4); - - // set the element's new position: - elmnt.parentElement.style.top = (elmnt.parentElement.offsetTop - pos2) + "px"; - elmnt.parentElement.style.left = (elmnt.parentElement.offsetLeft - pos1) + "px"; - if(elmnt.id.startsWith("report")){ - sessionStorage.setItem("report-top", elmnt.parentElement.style.top); - sessionStorage.setItem("report-left", elmnt.parentElement.style.left); - }else if(elmnt.id.startsWith("reply")){ - sessionStorage.setItem("reply-top", elmnt.parentElement.style.top); - sessionStorage.setItem("reply-left", elmnt.parentElement.style.left); - } -} - -function dragMouseDown(e) { - e = e || window.event; - e.preventDefault(); - - // get the mouse cursor position at startup: - pos3 = e.clientX; - pos4 = e.clientY; - sessionStorage.setItem("pos3", pos3); - sessionStorage.setItem("pos4", pos4); - - elmnt = e.currentTarget; - - // call a function whenever the cursor moves: - document.onmouseup = closeDragElement; - document.onmousemove = elementDrag; - sessionStorage.setItem("eventhandler", true); - -} - -function dragElement(elmnt) { - elmnt.onmousedown = dragMouseDown; -} - -const stateLoadHandler = function(event){ - pos1 = parseInt(sessionStorage.getItem("pos1")); - pos2 = parseInt(sessionStorage.getItem("pos2")); - pos3 = parseInt(sessionStorage.getItem("pos3")); - pos4 = parseInt(sessionStorage.getItem("pos4")); - - if(sessionStorage.getItem("element-closed-report") === "false"){ - var box = document.getElementById("report-box"); - var header = document.getElementById("report-header"); - var comment = document.getElementById("report-comment"); - var inReplyTo = document.getElementById("report-inReplyTo-box"); - - header.onmousedown = dragMouseDown; - inReplyTo.value = parseInt(sessionStorage.getItem("element-report-id")); - header.innerText = "Report Post No. " + shortURL(sessionStorage.getItem("element-report-actor"), sessionStorage.getItem("element-report-id")); - comment.value = sessionStorage.getItem("element-report-comment"); - - box.setAttribute("style", sessionStorage.getItem("element-report-style")); - - box.style.top = sessionStorage.getItem("report-top"); - box.style.left = sessionStorage.getItem("report-left"); - - if(sessionStorage.getItem("eventhandler") === "true"){ - elmnt = header; - document.onmouseup = closeDragElement; - document.onmousemove = elementDrag; - }else{ - document.onmouseup = null; - document.onmousemove = null; - } - } - if(sessionStorage.getItem("element-closed-reply") === "false"){ - var box = document.getElementById("reply-box"); - var header = document.getElementById("reply-header"); - var header_text = document.getElementById("reply-header-text"); - var comment = document.getElementById("reply-comment"); - var inReplyTo = document.getElementById("inReplyTo-box"); - - header.onmousedown = dragMouseDown; - inReplyTo.value = parseInt(sessionStorage.getItem("element-reply-id")); - header_text.innerText = "Replying to Thread No. " + shortURL(sessionStorage.getItem("element-reply-actor"), sessionStorage.getItem("element-reply-id")); - comment.value = sessionStorage.getItem("element-reply-comment"); - - pos1 = parseInt(sessionStorage.getItem("pos1")); - pos2 = parseInt(sessionStorage.getItem("pos2")); - pos3 = parseInt(sessionStorage.getItem("pos3")); - pos4 = parseInt(sessionStorage.getItem("pos4")); - - box.setAttribute("style", sessionStorage.getItem("element-reply-style")); - - box.style.top = sessionStorage.getItem("reply-top"); - box.style.left = sessionStorage.getItem("reply-left"); - - if(sessionStorage.getItem("eventhandler") === "true"){ - elmnt = header; - document.onmouseup = closeDragElement; - document.onmousemove = elementDrag; - }else{ - document.onmouseup = null; - document.onmousemove = null; - } - } -}; - -document.addEventListener("DOMContentLoaded", stateLoadHandler, false); - -function stripTransferProtocol(value){ - var re = /(https:\/\/|http:\/\/)?(www.)?/; - return value.replace(re, ""); -} diff --git a/static/js/themes.js b/static/js/themes.js deleted file mode 100644 index ccdd277..0000000 --- a/static/js/themes.js +++ /dev/null @@ -1,40 +0,0 @@ -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; - } - } -} diff --git a/static/js/timer.js b/static/js/timer.js deleted file mode 100644 index d8be9de..0000000 --- a/static/js/timer.js +++ /dev/null @@ -1,38 +0,0 @@ -var timerCount; -var timerToggle = false; -var timer; -const contentLoadHandler = function(event){ - timerToggle = !!document.getElementById("autoreload-checkbox").checked; - if(timerToggle){ - timerCount = 45; - document.getElementById("autoreload-countdown").innerHTML = "45"; - document.getElementById("autoreload-countdown").style.visibility = "visible"; - timer = setInterval(timerFunction, 1000); - document.removeEventListener("DOMContentLoaded", contentLoadHandler, false); - } -}; - -document.addEventListener("DOMContentLoaded", contentLoadHandler, false); - -function timerFunction(){ - timerCount--; - document.getElementById("autoreload-countdown").innerHTML = timerCount; - if(timerCount <= 0){ - document.getElementById("autoreload-countdown").innerHTML = "Refreshing..."; - clearInterval(timer); - location.reload(); - } -} - -function autoTimer(){ - timerToggle = !timerToggle; - if(timerToggle === true){ - timerCount = 45; - document.getElementById("autoreload-countdown").innerHTML = "45"; - document.getElementById("autoreload-countdown").style.visibility = "visible"; - timer = setInterval(timerFunction, 1000); - }else{ - clearInterval(timer); - document.getElementById("autoreload-countdown").style.visibility = "hidden"; - } -} |