aboutsummaryrefslogtreecommitdiff
path: root/static/js
diff options
context:
space:
mode:
Diffstat (limited to 'static/js')
-rw-r--r--static/js/aquiencitas.js23
-rw-r--r--static/js/weabot.js315
-rw-r--r--static/js/weabotxt.js114
3 files changed, 154 insertions, 298 deletions
diff --git a/static/js/aquiencitas.js b/static/js/aquiencitas.js
index 4284f0a..93f5323 100644
--- a/static/js/aquiencitas.js
+++ b/static/js/aquiencitas.js
@@ -54,13 +54,13 @@ function getPostDivs(e) {
return divs;
} else {
ele = document.getElementById(
- "reply" + e.getAttribute("href").split("#")[1]
+ "p" + e.getAttribute("href").split("#")[1]
);
return [ele];
}
}
function get_pid(e) {
- return is_bbs ? e.dataset.n : e.id.substr(5);
+ return is_bbs ? e.dataset.n : e.id.substr(1);
}
function fill_links(e) {
var divs = getPostDivs(e);
@@ -144,12 +144,9 @@ function quotePreview() {
if (localStorage.getItem("shobon_on") == "false") {
return;
}
- if (
- localStorage.getItem("shobon_preview") == "false" &&
- localStorage.getItem("shobon_backlink") == "false"
- ) {
- return;
- }
+ var showprev = localStorage.getItem("shobon_preview");
+ var showlink = localStorage.getItem("shobon_backlink");
+ if (showprev == "false" && showlink == "false") return;
var i, q, replies, quotes;
@@ -160,10 +157,10 @@ function quotePreview() {
if (is_bbs) replies = document.getElementsByClassName("msg");
else replies = document.getElementsByTagName("blockquote");
- urls = window.location.pathname.split("/");
- cur_url = urls[0] + "/" + urls[1] + "/" + urls[2] + "/" + urls[3];
+ var urls = window.location.pathname.split("/");
+ cur_url = "/" + ((urls[2]) ? urls[1] + "/" + urls[2] + "/" + urls[3] : urls[1]);
- for (x = 0; x < replies.length; x++) {
+ for (var x = 0; x < replies.length; x++) {
quotes = replies[x].getElementsByTagName("a");
linklist = {};
@@ -171,12 +168,12 @@ function quotePreview() {
q = quotes[i];
if (q.textContent.length < 3 || !q.textContent.startsWith(">>")) continue;
- if (localStorage.getItem("shobon_preview") != "false") {
+ if (showprev != "false") {
q.addEventListener("mouseover", who_are_you_quoting, false);
q.addEventListener("mouseout", remove_quote_preview, false);
}
- if (localStorage.getItem("shobon_backlink") != "false") {
+ if (showlink != "false") {
fill_links(q);
}
}
diff --git a/static/js/weabot.js b/static/js/weabot.js
index 9ab84f3..3371437 100644
--- a/static/js/weabot.js
+++ b/static/js/weabot.js
@@ -1,6 +1,9 @@
var style_cookie = "weabot_style_ib";
+if (localStorage.hasOwnProperty(style_cookie)) {
+ setTheme(localStorage.getItem(style_cookie));
+}
-function set_stylesheet(styletitle) {
+function setTheme(styletitle) {
var css = document.getElementById("css");
if (css) {
css.href = "/static/css/" + styletitle.toLowerCase() + ".css";
@@ -8,11 +11,6 @@ function set_stylesheet(styletitle) {
}
}
-if (style_cookie && localStorage.hasOwnProperty(style_cookie)) {
- set_stylesheet(localStorage.getItem(style_cookie));
-}
-
-var hiddenthreads = Array();
/* 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*/) {
@@ -69,7 +67,7 @@ function checkhighlight() {
function highlight(post) {
var hl = document.getElementsByClassName("reply highlight");
if (hl.length) { hl[0].className = "reply"; }
- var reply = document.getElementById("reply" + post);
+ var reply = document.getElementById("p" + post);
if (reply) {
reply.className = "reply highlight";
var match = /^([^#]*)/.exec(document.location.toString());
@@ -188,27 +186,6 @@ function filePreview(e) {
};
}
-function togglethread(e) {
- if (e.parentElement.id.startsWith("unhide")) {
- var threadid = e.parentElement.id.substr(6);
- } else if (e.parentElement.parentElement.id.startsWith("thread")) {
- var threadid = e.parentElement.parentElement.id.substr(6);
- } else {
- return;
- }
- if (hiddenthreads.toString().indexOf(threadid) !== -1) {
- document.getElementById("unhide" + threadid).style.display = "none";
- document.getElementById("thread" + threadid).removeAttribute("style");
- hiddenthreads.splice(hiddenthreads.indexOf(threadid), 1);
- } else {
- document.getElementById("unhide" + threadid).removeAttribute("style");
- document.getElementById("thread" + threadid).style.display = "none";
- hiddenthreads.push(threadid);
- }
- if (hiddenthreads == "") localStorage.removeItem("hiddenthreads");
- else localStorage.setItem("hiddenthreads", hiddenthreads.join("!"));
-}
-
function saveInputs(e) {
var e = e || window.event;
var form = e.target || e.srcElement;
@@ -224,7 +201,8 @@ function setInputs(id) {
fielda.value = weabot.name;
if (typeof fielda !== "undefined" && !fieldb.value && weabot.email)
fieldb.value = weabot.email;
- if (!password.value) password.value = getPassword();
+ if (!password.value)
+ password.value = getPassword();
addEventListener("submit", saveInputs);
}
}
@@ -232,10 +210,10 @@ function setInputs(id) {
function getPassword() {
if (weabot.password) return weabot.password;
+
var pass = "";
- var char =
- "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789?!-_.";
- while (pass.length < 10) {
+ var char = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789?!-_.";
+ for (var i=0; i<10; i++) {
pass += char[Math.floor(Math.random() * char.length)];
}
weabot.password = pass;
@@ -243,154 +221,51 @@ function getPassword() {
return pass;
}
-function catSort(type) {
- for (var i = 0; i < srt.length; i++) srt[i].innerHTML = srt[i].innerText;
- srt[type].innerHTML = "<b>" + srt[type].innerText + "</b>";
- var cont = document.getElementById("catalog");
- var elem = document.getElementsByClassName("thread");
- var arr = Array.prototype.slice.call(elem);
- if (type == 0)
- arr.sort(function(a, b) { return a.dataset.num - b.dataset.num; });
- else if (type == 1)
- arr.sort(function(a, b) { return b.dataset.id - a.dataset.id; });
- else if (type == 2)
- arr.sort(function(a, b) { return a.dataset.id - b.dataset.id; });
- else if (type == 3)
- arr.sort(function(a, b) { return b.dataset.res - a.dataset.res; });
- else if (type == 4)
- arr.sort(function(a, b) { return a.dataset.res - b.dataset.res; });
- for (var j = 0; j < arr.length; j++) cont.appendChild(arr[j]);
- localStorage.setItem("catalog", JSON.stringify(opcs));
-}
-
function catSearch() {
- var filter = document.getElementById("cat_search").value.toLowerCase();
+ var filter = this.value.toLowerCase();
var nodes = document.getElementsByTagName("p");
- for (i = 0; i < nodes.length; i++) {
+ 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 catThumbs(big) {
- var btn = document.getElementById("cat_size");
- var cat = document.getElementById("catalog");
- var threads = document.getElementsByClassName("thread");
- if (opcs.big) {
- cat.className = "enlarged";
- for (j = 0; j < threads.length; j++) {
- img = threads[j].getElementsByTagName("a")[0];
- img.innerHTML = img.innerHTML.replace("/cat/", "/thumb/");
- }
- btn.innerText = "Grande";
+function togglePost(e) {
+ if (e.tagName == "DIV") {
+ var post = e.parentElement;
} else {
- cat.removeAttribute("class");
- for (j = 0; j < threads.length; j++) {
- img = threads[j].getElementsByTagName("a")[0];
- img.innerHTML = img.innerHTML.replace("/thumb/", "/cat/");
- }
- btn.innerText = "Pequeño";
+ var post = e.parentElement.parentElement;
}
- localStorage.setItem("catalog", JSON.stringify(opcs));
-}
-
-function catTeasers(teaser) {
- var btn = document.getElementById("cat_hide");
- if (!teaser) {
- var style = document.createElement("style");
- style.id = "teaser_style";
- style.type = "text/css";
- style.innerText = "#catalog p {display:none}";
- document.head.appendChild(style);
- btn.innerText = "Mostrar";
+
+ var pid = post.id.slice(1);
+ var typ = post.id.charAt(0);
+ var itm = "hid-" + typ + "-" + document.body.dataset.brd;
+
+ var hidp = localStorage.getItem(itm);
+ var hid = Array();
+ if (hidp) hid = hidp.split("!");
+
+ if (post.classList.contains("hidden")) {
+ if (hid.includes(pid)) hid.splice(hid.indexOf(pid), 1);
} else {
- var style = document.getElementById("teaser_style");
- if (style) style.parentNode.removeChild(style);
- btn.innerText = "Ocultar";
+ if (!hid.includes(pid)) hid.push(pid);
}
- localStorage.setItem("catalog", JSON.stringify(opcs));
-}
-
-function catMenu(e) {
- var brd = document.getElementsByName("board")[0].value;
- var id = this.dataset.id;
- this.insertAdjacentHTML("afterbegin",
- '<div id="thread_ctrl" style="margin-bottom:3px;">[<a href="/cgi/report/' +
- brd + "/" + id + '">Denunciar</a>] [<a href="#" class="hh">Ocultar</a>]');
- this.getElementsByClassName("hh")[0].addEventListener("click", function(e) {
- document.getElementById("cat" + id + brd).style.display = "none";
- hiddenthreads.push(id + brd);
- localStorage.setItem("hiddenthreads", hiddenthreads.join("!"));
- if (document.getElementById("hidden_label")) {
- hidden_num++;
- document.getElementById("hidden_num").innerText = hidden_num;
- } else {
- hidden_num = 1;
- catHidden();
- }
- });
-}
-
-function catMenuClose(e) {
- document.getElementById("thread_ctrl").remove();
-}
-
-function catHidden() {
- var menu = document.getElementById("ctrl");
- menu.insertAdjacentHTML(
- "beforeend",
- ' <span id="hidden_label">[Hilos ocultos: <span id="hidden_num">' +
- hidden_num +
- "</span> - "
- );
- var lbl = document.getElementById("hidden_label");
- var shw = document.createElement("a");
- shw.href = "#";
- shw.innerText = "Deshacer";
- shw.addEventListener("click", function(e) {
- e.preventDefault();
- for (var i = 0; i < hiddenthreads.length; i++) {
- try {
- document.getElementById("cat" + hiddenthreads[i]).removeAttribute("style");
- } catch (err) {
- continue;
- }
- }
- lbl.parentElement.removeChild(lbl);
- hidden_num = 0;
- var aux = hiddenthreads.join("!");
- var exp = new RegExp(
- "\\b[0-9]+" + document.getElementsByName("board")[0].value + "\\b",
- "g"
- );
- aux = aux.replace(exp, "!");
- aux = aux.replace(/!+/g, "!");
- aux = aux.replace(/(^!|!$)/g, "");
- if (aux == "") {
- localStorage.removeItem("hiddenthreads");
- hiddenthreads = [];
- } else {
- localStorage.setItem("hiddenthreads", aux);
- hiddenthreads = aux.split("!");
- }
- });
- lbl.appendChild(shw);
- lbl.appendChild(document.createTextNode("]"));
-}
+ post.classList.toggle("hidden");
-function applyTheme() {
- var newTheme = document.getElementById("styles").value;
- set_stylesheet(newTheme);
+ localStorage.setItem(itm, hid.join("!"));
}
document.addEventListener("DOMContentLoaded", function(e) {
+ var board = document.body.dataset.brd;
checkhighlight();
- if (localStorage.hasOwnProperty("weabot"))
+
+ if (localStorage.hasOwnProperty("weabot")) {
weabot = JSON.parse(localStorage.getItem("weabot"));
- else weabot = { name: null, email: null, password: null };
-
- board = document.body.dataset.brd;
+ } else {
+ weabot = { name: null, email: null, password: null };
+ }
+
var a = document.getElementById("main_nav").getElementsByTagName("a");
for (var i = 0; i < a.length; i++) {
if (a[i].getAttribute("href") == "/" + board + "/") {
@@ -399,36 +274,21 @@ document.addEventListener("DOMContentLoaded", function(e) {
}
}
- if (localStorage.hasOwnProperty("hiddenthreads")) {
- hiddenthreads = localStorage.getItem("hiddenthreads").split("!");
- if (document.getElementById("catalog")) {
- hidden_num = 0;
- for (var i = 0; i < hiddenthreads.length; i++) {
- try {
- document.getElementById("cat" + hiddenthreads[i]).style.display = "none";
- hidden_num++;
- } catch (err) {
- continue;
- }
- }
- if (hidden_num) {
- catHidden();
- }
- } else {
- for (var i = 0; i < hiddenthreads.length; i++) {
- try {
- document.getElementById("unhide" + hiddenthreads[i]).removeAttribute("style");
- document.getElementById("thread" + hiddenthreads[i]).style.display = "none";
- } catch (err) {
- continue;
- }
+ for (var i=0; i<2; i++) {
+ var type = "pt".charAt(i);
+ var hidp = localStorage.getItem("hid-" + type + "-" + board);
+ if (hidp) {
+ 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");
}
}
}
var styleSelect = document.getElementById("styles");
if (styleSelect) {
- styleSelect.addEventListener("change", applyTheme, false);
+ styleSelect.addEventListener("change", function(e) { setTheme(this.value); });
styleSelect.value = localStorage.getItem(style_cookie);
}
@@ -440,47 +300,46 @@ document.addEventListener("DOMContentLoaded", function(e) {
var del = document.getElementById("delform");
if (del) del.password.value = weabot.password;
- window.addEventListener("hashchange", checkhighlight);
-
- if (document.getElementById("catalog")) {
- srt = document.getElementsByClassName("cat_sort");
- for (var i = 0; i < srt.length; i++) {
- srt[i].innerHTML = srt[i].innerText;
- srt[i].addEventListener("click", function(e) {
- e.preventDefault();
- opcs.sort = this.dataset.sort;
- catSort(opcs.sort);
- });
+ var cat = document.getElementById("catalog");
+ if (cat) {
+ if (j>0) {
+ document.getElementById("hid-label").removeAttribute("style");
+ document.getElementById("hid-num").innerText = j;
}
- document.getElementById("cat_size").addEventListener("click", function(e) {
+
+ document.getElementById("cat-size").addEventListener("click", function(e) {
e.preventDefault();
- opcs.big = !opcs.big;
- catThumbs(opcs.big);
+ var thumb = cat.getElementsByTagName("img");
+ if (cat.classList.contains("enlarged")) {
+ for (var i = 0; i < thumb.length; i++) {
+ thumb[i].src = thumb[i].src.replace("/thumb/", "/cat/");
+ }
+ } else {
+ for (var i = 0; i < thumb.length; i++) {
+ thumb[i].src = thumb[i].src.replace("/cat/", "/thumb/");
+ }
+ }
+ cat.classList.toggle("enlarged");
+ this.innerText = (this.innerText == "Pequeño") ? "Grande" : "Pequeño";
});
- document.getElementById("cat_hide").addEventListener("click", function(e) {
+
+ document.getElementById("cat-hide").addEventListener("click", function(e) {
e.preventDefault();
- opcs.teaser = !opcs.teaser;
- catTeasers(opcs.teaser);
+ cat.classList.toggle("notxt");
+ this.innerText = (this.innerText == "Ocultar") ? "Mostrar" : "Ocultar";
});
- document.getElementById("cat_search").addEventListener("keyup", catSearch);
- if (localStorage.hasOwnProperty("catalog")) {
- opcs = JSON.parse(localStorage.getItem("catalog"));
- if ((match = /\?sort=([0-9])/.exec(document.location.toString())))
- opcs.sort = match[1];
- catSort(opcs.sort);
- catThumbs(opcs.big);
- catTeasers(opcs.teaser);
- } else {
- opcs = { sort: 1, big: false, teaser: true };
- localStorage.setItem("catalog", JSON.stringify(opcs));
- }
- var thr = document.getElementsByClassName("thread");
- for (var i = 0; i < thr.length; i++) {
- thr[i].addEventListener("mouseenter", catMenu);
- thr[i].addEventListener("mouseleave", catMenuClose);
- }
+
+ 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);
}
});
+
document.addEventListener("click", function(e) {
var cn = e.target.className;
if (cn == "num") {
@@ -488,14 +347,22 @@ document.addEventListener("click", function(e) {
postClick(e.target.textContent);
return;
}
- if (cn == "tt") {
+ if (cn == "expimg") {
e.preventDefault();
- togglethread(e.target);
+ expandimg(e.target);
return;
}
- if (cn == "expimg") {
+ if (cn == "tt") {
e.preventDefault();
- expandimg(e.target);
+ togglePost(e.target);
return;
}
}, false);
+
+document.addEventListener("dblclick", function(e) {
+ if (e.target.closest(".info")) {
+ e.preventDefault();
+ togglePost(e.target.closest(".info"));
+ return;
+ }
+}, false); \ No newline at end of file
diff --git a/static/js/weabotxt.js b/static/js/weabotxt.js
index df4bc56..fec445d 100644
--- a/static/js/weabotxt.js
+++ b/static/js/weabotxt.js
@@ -1,11 +1,9 @@
var style_cookie = "weabot_style_txt";
-if (style_cookie && localStorage.hasOwnProperty(style_cookie)) {
- set_stylesheet(localStorage.getItem(style_cookie));
+if (localStorage.hasOwnProperty(style_cookie)) {
+ setTheme(localStorage.getItem(style_cookie));
}
-var hiddenposts = Array();
-
-function set_stylesheet(styletitle) {
+function setTheme(styletitle) {
var css = document.getElementById("css");
if (css) css.href = "/static/css/txt/" + styletitle.toLowerCase() + ".css";
localStorage.setItem(style_cookie, styletitle);
@@ -28,9 +26,8 @@ if (!Array.prototype.indexOf) {
function getPassword() {
if (weabot.password) return weabot.password;
var pass = "";
- var char =
- "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789?!-_.";
- while (pass.length < 10) {
+ var char = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789?!-_.";
+ for (var i=0; i<11; i++) {
pass += char[Math.floor(Math.random() * char.length)];
}
weabot.password = pass;
@@ -135,6 +132,24 @@ function previewPost(e) {
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send(text);
}
+function get_xmlhttp() {
+ var xmlhttp;
+ try {
+ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
+ } catch (e1) {
+ try {
+ xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
+ } catch (e1) {
+ xmlhttp = null;
+ }
+ }
+ if (!xmlhttp && typeof XMLHttpRequest != "undefined")
+ xmlhttp = new XMLHttpRequest();
+ return xmlhttp;
+}
+function is_ie() {
+ return document.all && !document.opera;
+}
function listSort(e) {
e.preventDefault();
@@ -178,52 +193,23 @@ function searchSubjects(e) {
}
}
-function get_xmlhttp() {
- var xmlhttp;
- try {
- xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
- } catch (e1) {
- try {
- xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- } catch (e1) {
- xmlhttp = null;
- }
- }
- if (!xmlhttp && typeof XMLHttpRequest != "undefined")
- xmlhttp = new XMLHttpRequest();
- return xmlhttp;
-}
-
-function is_ie() {
- return document.all && !document.opera;
-}
-
-function showpost(post) {
- post.children[0].classList.remove("hidden");
- post.children[1].removeAttribute("style");
-}
-function hidepost(post) {
- post.children[0].classList.add("hidden");
- post.children[1].style.display = "none";
-}
-function togglepost(e) {
- e.preventDefault();
- var post = this.parentElement;
- var postid = board + this.getElementsByClassName("date")[0].dataset.unix;
- if (post.children[1].style.display == "none") {
- showpost(post);
- if (hiddenposts.includes(postid))
- hiddenposts.splice(hiddenposts.indexOf(postid), 1);
+function togglePost(e) {
+ var post = e.parentElement;
+ var pid = post.id.slice(1);
+
+ var hidp = localStorage.getItem("hid-p-"+board);
+ var hid = Array();
+ if (hidp) hid = hidp.split("!");
+
+ if (post.classList.contains("hidden")) {
+ post.classList.remove("hidden");
+ if (hid.includes(pid)) hid.splice(hid.indexOf(pid), 1);
} else {
- hidepost(post);
- if (!hiddenposts.includes(postid)) hiddenposts.push(postid);
+ post.classList.add("hidden");
+ if (!hid.includes(pid)) hid.push(pid);
}
- localStorage.setItem("hiddenposts", hiddenposts.join("!"));
-}
-function applyTheme() {
- var newTheme = document.getElementById("styles").value;
- set_stylesheet(newTheme);
+ localStorage.setItem("hid-p-"+board, hid.join("!"));
}
document.addEventListener("DOMContentLoaded", function() {
@@ -232,6 +218,7 @@ document.addEventListener("DOMContentLoaded", function() {
else weabot = { name: null, email: null, password: null };
board = document.body.dataset.brd;
+
var head = document.getElementById("main_nav");
if (head) {
var b = head.getElementsByTagName("a");
@@ -250,7 +237,7 @@ document.addEventListener("DOMContentLoaded", function() {
var styleSelect = document.getElementById("styles");
if (styleSelect) {
- styleSelect.addEventListener("change", applyTheme, false);
+ styleSelect.addEventListener("change", function(e) { setTheme(this.value); });
styleSelect.value = localStorage.getItem(style_cookie);
}
@@ -262,16 +249,13 @@ document.addEventListener("DOMContentLoaded", function() {
document.getElementById("l_sr").addEventListener("keyup", searchSubjects);
}
- if (localStorage.hasOwnProperty("hiddenposts"))
- hiddenposts = localStorage.getItem("hiddenposts").split("!");
-
- var dt = document.getElementsByClassName("date");
- for (var i = 0; i < dt.length; i++) {
- if (hiddenposts.includes(board + dt[i].dataset.unix)) {
- console.log(dt[i].dataset.unix);
- hidepost(dt[i].parentElement.parentElement);
+ var hidp = localStorage.getItem("hid-p-"+board);
+ if (hidp) {
+ var hid = hidp.split("!");
+ for (var i = 0; i < hid.length; i++) {
+ var post = document.getElementById("p"+hid[i]);
+ if (post) post.classList.add("hidden");
}
- dt[i].parentElement.addEventListener("dblclick", togglepost);
}
});
@@ -287,4 +271,12 @@ document.addEventListener("click", function(e) {
deletePost(e.target);
return;
}
+}, false);
+
+document.addEventListener("dblclick", function(e) {
+ if (e.target.closest("h4")) {
+ e.preventDefault();
+ togglePost(e.target.closest("h4"));
+ return;
+ }
}, false); \ No newline at end of file