diff options
author | Choom | 2023-01-20 00:36:43 -0300 |
---|---|---|
committer | Choom | 2023-01-22 07:57:56 -0300 |
commit | 8e519f17d144165b6de31bf3ebabdab5eb13bf0d (patch) | |
tree | 10b3bd7affd037d198fc6ec54af6862cb0ce85b0 /static/js/weabot.js | |
parent | 649a2e5f4fa0b13a58068772ec72605dba6624d2 (diff) | |
download | weabot-8e519f17d144165b6de31bf3ebabdab5eb13bf0d.tar.gz weabot-8e519f17d144165b6de31bf3ebabdab5eb13bf0d.tar.xz weabot-8e519f17d144165b6de31bf3ebabdab5eb13bf0d.zip |
Config para el usuario
Diffstat (limited to 'static/js/weabot.js')
-rw-r--r-- | static/js/weabot.js | 139 |
1 files changed, 58 insertions, 81 deletions
diff --git a/static/js/weabot.js b/static/js/weabot.js index 693d138..afe65c8 100644 --- a/static/js/weabot.js +++ b/static/js/weabot.js @@ -1,30 +1,11 @@ var style_cookie = "weabot_style_ib"; if (localStorage.hasOwnProperty(style_cookie)) { - setTheme(localStorage.getItem(style_cookie)); -} - -function setTheme(styletitle) { var css = document.getElementById("css"); if (css) { - css.href = "/static/css/" + styletitle.toLowerCase() + ".css"; - localStorage.setItem(style_cookie, styletitle); + css.href = "/static/css/" + localStorage.getItem(style_cookie).toLowerCase() + ".css"; } } -/* IE/Opera fix, because they need to go learn a book on how to use indexOf with arrays */ -if (!Array.prototype.indexOf) { - Array.prototype.indexOf = function(elt /*, from*/) { - var len = this.length; - var from = Number(arguments[1]) || 0; - from = from < 0 ? Math.ceil(from) : Math.floor(from); - if (from < 0) from += len; - for (; from < len; from++) { - if (from in this && this[from] === elt) return from; - } - return -1; - }; -} - function postClick(num) { var sel = window.getSelection().toString(); if (sel) sel = sel.replace(/^/gm, ">") + "\n"; @@ -204,16 +185,6 @@ function getPassword() { return pass; } -function catSearch() { - var filter = this.value.toLowerCase(); - var nodes = document.getElementsByTagName("p"); - for (var i = 0; i < nodes.length; i++) { - if (nodes[i].innerText.toLowerCase().includes(filter)) - nodes[i].parentNode.removeAttribute("style"); - else nodes[i].parentNode.style.display = "none"; - } -} - function togglePost(e) { if (e.tagName == "DIV") { var post = e.parentElement; @@ -223,24 +194,32 @@ function togglePost(e) { var pid = post.id.slice(1); var typ = post.id.charAt(0); - var itm = "hid-" + typ + "-" + document.body.dataset.brd; + var itm = "hid-" + typ + "-" + board; var hidp = localStorage.getItem(itm); var hid = Array(); - if (hidp) hid = hidp.split("!"); + if (hidp) { hid = hidp.split("!"); } if (post.classList.contains("hidden")) { - if (hid.includes(pid)) hid.splice(hid.indexOf(pid), 1); + if (hid.includes(pid)) { + hid.splice(hid.indexOf(pid), 1); + } } else { - if (!hid.includes(pid)) hid.push(pid); + if (!hid.includes(pid)) { + hid.push(pid); + } } post.classList.toggle("hidden"); localStorage.setItem(itm, hid.join("!")); } +function checkHidden() { + +} + document.addEventListener("DOMContentLoaded", function(e) { - var board = document.body.dataset.brd; + board = document.body.dataset.brd; checkhighlight(); if (localStorage.hasOwnProperty("weabot")) { @@ -249,15 +228,10 @@ document.addEventListener("DOMContentLoaded", function(e) { weabot = { name: null, email: null, password: null }; } - var head = document.getElementById("main_nav"); - var a = head.getElementsByTagName("a"); - for (var i = 0; i < a.length; i++) { - if (a[i].getAttribute("href") == "/" + board + "/") { - a[i].className = "cur_brd"; - break; - } - } + var blink = document.getElementById("b-" + board); + if (blink) { blink.className = "cur_brd"; } + var head = document.getElementById("main_nav"); if (document.body.clientWidth < 600) { var navlink = head.getElementsByTagName("a"); @@ -296,17 +270,11 @@ document.addEventListener("DOMContentLoaded", function(e) { var hid = hidp.split("!"); for (var j = 0; j < hid.length; j++) { var post = document.getElementById(type+hid[j]); - if (post) post.classList.add("hidden"); + if (post) { post.classList.add("hidden"); } } } } - var styleSelect = document.getElementById("styles"); - if (styleSelect) { - styleSelect.addEventListener("change", function(e) { setTheme(this.value); }); - styleSelect.value = localStorage.getItem(style_cookie); - } - if (document.getElementById("postform")) { setInputs("postform"); postform.file.addEventListener("change", filePreview); @@ -317,7 +285,7 @@ document.addEventListener("DOMContentLoaded", function(e) { var cat = document.getElementById("catalog"); if (cat) { - if (j>0) { + if (j > 0) { // hidden threads number document.getElementById("hid-label").removeAttribute("style"); document.getElementById("hid-num").innerText = j; } @@ -338,40 +306,49 @@ document.addEventListener("DOMContentLoaded", function(e) { this.innerText = (this.innerText == "Pequeño") ? "Grande" : "Pequeño"; }); - document.getElementById("cat-srch").addEventListener("keyup", catSearch); - document.getElementById("hid-num").addEventListener("click", function(e) { e.preventDefault(); cat.classList.toggle("showhid"); }); - } else { - window.addEventListener("hashchange", checkhighlight); - } + } + + window.addEventListener("hashchange", checkhighlight); }); -document.addEventListener("click", function(e) { - var cn = e.target.className; - if (cn == "num") { - e.preventDefault(); - postClick(e.target.textContent); - return; - } - if (cn == "expimg") { - e.preventDefault(); - expandimg(e.target); - return; - } - if (cn == "tt") { - e.preventDefault(); - togglePost(e.target); - return; - } -}, false); -document.addEventListener("dblclick", function(e) { - if (e.target.closest(".info")) { - e.preventDefault(); - togglePost(e.target.closest(".info")); - return; - } -}, false); + +window.addEventListener("load", function() { + document.addEventListener("click", function(e) { + var cn = e.target.className; + if (cn == "num") { + e.preventDefault(); + postClick(e.target.textContent); + return; + } + if (cn == "expimg") { + e.preventDefault(); + expandimg(e.target); + return; + } + if (cn == "tt") { + e.preventDefault(); + togglePost(e.target); + return; + } + }, false); + + document.addEventListener("dblclick", function(e) { + if (e.target.closest(".info")) { + e.preventDefault(); + togglePost(e.target.closest(".info")); + return; + } + if (document.getElementById("catalog")) { + if (e.target.className == 'subj') { + e.preventDefault(); + togglePost(e.target.className == 'subj'); + return; + } + } + }, false); +}); |