diff options
-rw-r--r-- | static/js/weabotxt.js | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/static/js/weabotxt.js b/static/js/weabotxt.js index 9cd407c..f4bbe2f 100644 --- a/static/js/weabotxt.js +++ b/static/js/weabotxt.js @@ -18,8 +18,8 @@ function changeDate() { if (board == "world") week = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"]; for(var d=0;d<dts.length;d++) { dts[d].addEventListener('mouseover', function(e) { this.title = "Hace " + timeAgo(this.dataset.unix); }); - if (dts[d].innerText.includes("ID:")) var id = dts[d].innerText.split(" ")[1]; - dts[d].innerText = localTime(dts[d].dataset.unix, id); + if (dts[d].textContent.includes("ID:")) var id = dts[d].textContent.split(" ")[1]; + dts[d].textContent = localTime(dts[d].dataset.unix, id); } } } @@ -121,21 +121,19 @@ function insert(text) { } function deletePost(e) { - var ids = this.parentElement.firstChild.href.split("/"); + var ids = e.parentElement.firstChild.href.split("/"); var post = ids.pop(); var realid = ids.pop(); if(confirm("¿Seguro que deseas borrar el mensaje "+post+"?")) { var script="/cgi/delete"; document.location=script+"?board="+board+"&password="+weabot.password+"&delete="+realid; } - e.preventDefault(); } -function postClick(e) { - e.preventDefault(); +function postClick(num) { var sel = window.getSelection().toString(); if (sel) { sel=sel.replace(/^/gm, ">")+"\n"; sel="\n"+sel; } - insert(">>" + this.textContent + sel); + insert(">>"+num+sel); } function previewPost(e) { @@ -168,7 +166,7 @@ function listSort() { var cont = document.getElementById("content"); var elem = document.getElementsByClassName("row"); var arr = Array.prototype.slice.call(elem); arr.shift(); - if (s=="Normal") { arr.sort(function (a,b) { return (parseInt(a.childNodes[1].innerText) - parseInt(b.childNodes[1].innerText)) }); } + if (s=="Normal") { arr.sort(function (a,b) { return (parseInt(a.childNodes[1].textContent) - parseInt(b.childNodes[1].textContent)) }); } else if(s=="Edad"){ arr.sort(function (a,b) { return (b.children[1].firstChild.href.split("/")[5] - a.children[1].firstChild.href.split("/")[5]) }); } else if(s=="Largo"){ arr.sort(function (a,b) { return (b.children[2].textContent - a.children[2].textContent) }); } else if(s=="Rapidez"){ var now=Math.round(Date.now()/1000); arr.sort(function (a,b) { return ((b.children[2].textContent/(now-b.children[1].firstChild.href.split("/")[5])) - (a.children[2].textContent/(now-a.children[1].firstChild.href.split("/")[5]))) }); } @@ -185,7 +183,7 @@ function listDisplay() { var style = document.createElement("style"); style.id = "labels"; style.type = "text/css"; - style.innerText = '#content .row div.date{display:none}#content.grid div.com:before{content:"("}#content.grid .com:after{content:")"}'; + style.textContent = '#content .row div.date{display:none}#content.grid div.com:before{content:"("}#content.grid .com:after{content:")"}'; document.head.appendChild(style); } else if (d=="Lista") { var style = document.getElementById("labels"); @@ -200,7 +198,7 @@ function searchSubjects(e) { var filter = this.value.toLowerCase(); var nodes = document.getElementsByClassName("thread"); for (i=0; i<nodes.length; i++) { - if (nodes[i].innerText.toLowerCase().includes(filter)) nodes[i].parentNode.removeAttribute("style"); + if (nodes[i].textContent.toLowerCase().includes(filter)) nodes[i].parentNode.removeAttribute("style"); else nodes[i].parentNode.style.display = "none"; } } @@ -220,17 +218,16 @@ function is_ie() { return(document.all&&!document.opera); } function showpost(post) { post.children[0].classList.remove("hidden"); - post.children[1].style.display = 'block'; + post.children[1].removeAttribute("style"); } function hidepost(post) { post.children[0].classList.add("hidden"); - post.children[1].style.display = 'none'; + 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); @@ -238,7 +235,6 @@ function togglepost(e) { hidepost(post); if(!hiddenposts.includes(postid)) hiddenposts.push(postid); } - localStorage.setItem("hiddenposts", hiddenposts.join("!")); } @@ -253,9 +249,6 @@ document.addEventListener("DOMContentLoaded", function() { board = document.body.dataset.brd; - var ids = document.getElementsByClassName("num"); - for(var i=0;i<ids.length;i++) ids[i].addEventListener("click", postClick); - var forms = document.getElementsByTagName("form"); for(var i=0;i<forms.length;i++) { if(forms[i].id.startsWith("postform")) setInputs(forms[i].id); } @@ -273,9 +266,6 @@ document.addEventListener("DOMContentLoaded", function() { if(localStorage.getItem("shobon_time") != "false") changeDate(); - var dds = document.getElementsByClassName("del"); - for(var i=0;i<dds.length;i++) { dds[i].children[1].addEventListener("click", deletePost); } - if (document.body.className == "threads") { var srt = document.getElementsByClassName("l_s"); for(var i=0;i<srt.length;i++){ srt[i].addEventListener("click",function(e){ e.preventDefault(); opcs.sort=this.textContent; listSort(); }); } @@ -285,10 +275,10 @@ document.addEventListener("DOMContentLoaded", function() { if (localStorage.hasOwnProperty("threadlist")) { opcs = JSON.parse(localStorage.getItem("threadlist")); listSort(); listDisplay(); } else { opcs = {"sort":"Normal","disp":"Lista"}; localStorage.setItem("threadlist", JSON.stringify(opcs)); } } - + if(localStorage.hasOwnProperty("hiddenposts")) hiddenposts = localStorage.getItem("hiddenposts").split("!"); - + var pps = document.getElementsByClassName("date"); for(var i=0;i<pps.length;i++) { if(hiddenposts.includes(board+pps[i].dataset.unix)) { @@ -297,4 +287,17 @@ document.addEventListener("DOMContentLoaded", function() { } pps[i].parentElement.addEventListener("dblclick", togglepost); } -});
\ No newline at end of file +}); +document.addEventListener("click", function(e) { + var txt = e.target.textContent; + if (e.target.className == "num") { + e.preventDefault(); + postClick(txt); + return; + } + if (txt == "del") { + e.preventDefault(); + deletePost(e.target); + return; + } +},false);
\ No newline at end of file |