aboutsummaryrefslogtreecommitdiff
path: root/static/js/aquiencitas.js
diff options
context:
space:
mode:
authorLibravatar Renard 2020-03-29 18:47:51 -0300
committerLibravatar Renard 2020-03-29 18:47:51 -0300
commit18f60364b920e0ff33bc4b8e3135590effeaf173 (patch)
treec4067d1b5316882c5b8671c22701b963359db227 /static/js/aquiencitas.js
parent3600b2d2fc91b8a15237cff0f27a2ac423ea6c58 (diff)
downloadweabot-18f60364b920e0ff33bc4b8e3135590effeaf173.tar.gz
weabot-18f60364b920e0ff33bc4b8e3135590effeaf173.tar.xz
weabot-18f60364b920e0ff33bc4b8e3135590effeaf173.zip
Prettier para JS
Diffstat (limited to 'static/js/aquiencitas.js')
-rw-r--r--static/js/aquiencitas.js165
1 files changed, 95 insertions, 70 deletions
diff --git a/static/js/aquiencitas.js b/static/js/aquiencitas.js
index 0cf860f..4284f0a 100644
--- a/static/js/aquiencitas.js
+++ b/static/js/aquiencitas.js
@@ -4,41 +4,59 @@ var linki;
var is_bbs;
var plimit = 5;
function getPostRange(t, n) {
- var posts, replies, s, ss, ee, rev = false;
+ var posts,
+ replies,
+ s,
+ ss,
+ ee,
+ rev = false;
posts = [];
replies = t.getElementsByClassName("reply");
- s = n.split('-');
+ s = n.split("-");
ss = parseInt(s[0]);
ee = ss;
- if(s.length == 2) ee = parseInt(s[1]);
- if(ee<ss) { tmp=ss;ss=ee;ee=tmp; rev=true; }
- for(j = 0; j < replies.length; j++) {
+ if (s.length == 2) ee = parseInt(s[1]);
+ if (ee < ss) {
+ tmp = ss;
+ ss = ee;
+ ee = tmp;
+ rev = true;
+ }
+ for (j = 0; j < replies.length; j++) {
num = parseInt(replies[j].dataset.n);
- if(num > ee) break;
- if(num >= ss && num <= ee) {
- if(rev) posts.unshift(replies[j]);
+ if (num > ee) break;
+ if (num >= ss && num <= ee) {
+ if (rev) posts.unshift(replies[j]);
else posts.push(replies[j]);
}
}
return posts;
}
-function findAncestor (el) {
- while ((el = el.parentElement) && !el.className.startsWith("thread") && !el.className.startsWith("cont"));
+function findAncestor(el) {
+ while (
+ (el = el.parentElement) &&
+ !el.className.startsWith("thread") &&
+ !el.className.startsWith("cont")
+ );
return el;
}
function getPostDivs(e) {
- if(is_bbs) {
+ if (is_bbs) {
divs = [];
t = findAncestor(e);
- s = e.getAttribute('href').split('/');
- r = s[s.length-1];
- rs = r.split(',');
+ s = e.getAttribute("href").split("/");
+ r = s[s.length - 1];
+ rs = r.split(",");
linki = 0;
- for(i=0;i<rs.length;i++) { divs.push.apply(divs, getPostRange(t, rs[i])); }
+ for (i = 0; i < rs.length; i++) {
+ divs.push.apply(divs, getPostRange(t, rs[i]));
+ }
return divs;
} else {
- ele = document.getElementById('reply' + e.getAttribute('href').split('#')[1]);
- return [ele,];
+ ele = document.getElementById(
+ "reply" + e.getAttribute("href").split("#")[1]
+ );
+ return [ele];
}
}
function get_pid(e) {
@@ -46,36 +64,37 @@ function get_pid(e) {
}
function fill_links(e) {
var divs = getPostDivs(e);
- if(!divs[0]) return;
-
+ if (!divs[0]) return;
+
this_id = get_pid(e.parentNode.parentNode);
-
- for(i=0;i<divs.length;i++) {
+
+ for (i = 0; i < divs.length; i++) {
tid = get_pid(divs[i]);
- if (linklist[tid])
- continue;
- if (this_id == tid)
- continue;
- t = (is_bbs ? divs[i].getElementsByTagName("h4")[0] : divs[i]);
- bl = document.createElement('a');
+ if (linklist[tid]) continue;
+ if (this_id == tid) continue;
+ t = is_bbs ? divs[i].getElementsByTagName("h4")[0] : divs[i];
+ bl = document.createElement("a");
bl.href = cur_url + (is_bbs ? "/" : "#") + this_id;
- bl.textContent = '>>' + this_id;
- bl.addEventListener('mouseover', who_are_you_quoting, false);
- bl.addEventListener('mouseout', remove_quote_preview, false);
- if (!(qb = t.getElementsByClassName('quoted')[0])) {
- qb = document.createElement((is_bbs ? 'span' : 'div'));
- qb.className = 'quoted';
- qb.textContent = ' Citado por: ';
- if(is_bbs) {
+ bl.textContent = ">>" + this_id;
+ bl.addEventListener("mouseover", who_are_you_quoting, false);
+ bl.addEventListener("mouseout", remove_quote_preview, false);
+ if (!(qb = t.getElementsByClassName("quoted")[0])) {
+ qb = document.createElement(is_bbs ? "span" : "div");
+ qb.className = "quoted";
+ qb.textContent = " Citado por: ";
+ if (is_bbs) {
t.insertBefore(qb, t.getElementsByClassName("del")[0]);
- t.insertBefore(document.createTextNode(' '), t.getElementsByClassName("del")[0]);
+ t.insertBefore(
+ document.createTextNode(" "),
+ t.getElementsByClassName("del")[0]
+ );
} else {
p = t.getElementsByTagName("blockquote");
- p[p.length-1].insertAdjacentHTML('afterend', qb.outerHTML);
+ p[p.length - 1].insertAdjacentHTML("afterend", qb.outerHTML);
}
- t.getElementsByClassName('quoted')[0].appendChild(bl);
+ t.getElementsByClassName("quoted")[0].appendChild(bl);
} else {
- qb.appendChild(document.createTextNode(' '));
+ qb.appendChild(document.createTextNode(" "));
qb.appendChild(bl);
}
linklist[tid] = true;
@@ -85,17 +104,17 @@ function who_are_you_quoting(e) {
var parent, d, clr, src, cnt, left, top, width, maxWidth;
e = e.target || window.event.srcElement;
var divs = getPostDivs(e);
- if(!divs[0]) return;
-
+ if (!divs[0]) return;
+
maxWidth = 500;
- cnt = document.createElement('div');
- cnt.id = 'q-p';
+ cnt = document.createElement("div");
+ cnt.id = "q-p";
width = divs[0].offsetWidth;
if (width > maxWidth) {
width = maxWidth;
}
-
- for(i=0;i<divs.length&&i<plimit;i++) {
+
+ for (i = 0; i < divs.length && i < plimit; i++) {
src = divs[i].cloneNode(true);
cnt.appendChild(src);
}
@@ -105,15 +124,14 @@ function who_are_you_quoting(e) {
do {
left += parent.offsetLeft;
top += parent.offsetTop;
- } while (parent = parent.offsetParent);
+ } while ((parent = parent.offsetParent));
if ((d = document.body.offsetWidth - left - width) < 0) left += d;
- cnt.setAttribute('style', 'left:' + left + 'px;top:' + top + 'px;');
+ cnt.setAttribute("style", "left:" + left + "px;top:" + top + "px;");
document.body.appendChild(cnt);
}
function remove_quote_preview(e) {
var cnt;
- if (cnt = document.getElementById('q-p'))
- document.body.removeChild(cnt);
+ if ((cnt = document.getElementById("q-p"))) document.body.removeChild(cnt);
}
/*function goTo(e) {
e.preventDefault();
@@ -123,40 +141,47 @@ function remove_quote_preview(e) {
if (pst) pst.scrollIntoView();
}*/
function quotePreview() {
- if(localStorage.getItem("shobon_on") == "false") { return; }
- if(localStorage.getItem("shobon_preview") == "false" && localStorage.getItem("shobon_backlink") == "false") { return; }
-
+ if (localStorage.getItem("shobon_on") == "false") {
+ return;
+ }
+ if (
+ localStorage.getItem("shobon_preview") == "false" &&
+ localStorage.getItem("shobon_backlink") == "false"
+ ) {
+ return;
+ }
+
var i, q, replies, quotes;
-
- if(document.body.className && document.body.className != "res")
+
+ if (document.body.className && document.body.className != "res")
is_bbs = true;
else is_bbs = false;
-
- if(is_bbs) replies = document.getElementsByClassName('msg');
- else replies = document.getElementsByTagName('blockquote');
-
+
+ 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];
-
+
for (x = 0; x < replies.length; x++) {
- quotes = replies[x].getElementsByTagName('a');
+ quotes = replies[x].getElementsByTagName("a");
linklist = {};
-
+
for (i = 0; i < quotes.length; i++) {
q = quotes[i];
- if(q.textContent.length < 3 || !q.textContent.startsWith(">>")) continue;
-
- if(localStorage.getItem("shobon_preview") != "false") {
- q.addEventListener('mouseover', who_are_you_quoting, false);
- q.addEventListener('mouseout', remove_quote_preview, false);
+ if (q.textContent.length < 3 || !q.textContent.startsWith(">>")) continue;
+
+ if (localStorage.getItem("shobon_preview") != "false") {
+ q.addEventListener("mouseover", who_are_you_quoting, false);
+ q.addEventListener("mouseout", remove_quote_preview, false);
}
-
- if(localStorage.getItem("shobon_backlink") != "false") {
+
+ if (localStorage.getItem("shobon_backlink") != "false") {
fill_links(q);
}
}
}
-/* if (document.body.className === "threadpage") {
+ /* if (document.body.className === "threadpage") {
for (x = 0; x < replies.length; x++) {
var q = replies[x].getElementsByTagName("a");
for(var j=0;j<q.length;j++) {
@@ -165,4 +190,4 @@ function quotePreview() {
}
}*/
}
-document.addEventListener('DOMContentLoaded', quotePreview, false); \ No newline at end of file
+document.addEventListener("DOMContentLoaded", quotePreview, false);