diff options
author | Señor X | 2019-04-05 03:50:25 -0300 |
---|---|---|
committer | Señor X | 2019-04-05 03:52:47 -0300 |
commit | 6e2a0f64d910b6ccb4d09846ea313e3f308fd747 (patch) | |
tree | e9752724539336bdf9c14d3af89c2af52ea36ded /static/js/weabot.js | |
parent | 7d62e3d0ec4f96d6708e0946dffd81bded9f0aca (diff) | |
download | weabot-6e2a0f64d910b6ccb4d09846ea313e3f308fd747.tar.gz weabot-6e2a0f64d910b6ccb4d09846ea313e3f308fd747.tar.xz weabot-6e2a0f64d910b6ccb4d09846ea313e3f308fd747.zip |
Moviendo funciones de hora local de weabot.js y weabotxt.js a shobon.js + Delegación
Diffstat (limited to 'static/js/weabot.js')
-rw-r--r-- | static/js/weabot.js | 108 |
1 files changed, 37 insertions, 71 deletions
diff --git a/static/js/weabot.js b/static/js/weabot.js index 0f27075..3fed774 100644 --- a/static/js/weabot.js +++ b/static/js/weabot.js @@ -27,36 +27,10 @@ if (!Array.prototype.indexOf) { }; } -function timeAgo(timestamp) { - var time = Math.round(Date.now()/1000); - var el = time - timestamp; - if (el==0) return "un instante"; - else if (el==1) return "un segundo"; - else if (el<60) return el + " segundos"; - else if (el<120) return "un minuto"; - else if (el<3600) return Math.round(el/60) + " minutos"; - else if (el<7200) return "una hora"; - else if (el<86400) return Math.round(el/3600) + " horas"; - else if (el<172800) return "un día"; - else if (el<2628000) return Math.round(el/86400) + " días"; - else if (el<5256000) return "un mes"; - else if (el<31536000) return Math.round(el/2628000) + " meses"; - else if (el>31535999) return "más de un año"; -} - -function localTime(timestamp, id) { - id = id || 0; - var lcl = new Date(timestamp*1000); - lcl = ("0"+lcl.getDate()).slice(-2) + "/" + ("0" + (lcl.getMonth()+1)).slice(-2) + "/" + lcl.getFullYear().toString().slice(-2) + "(" + week[lcl.getDay()] + ")" + ("0"+lcl.getHours()).slice(-2) + ":" + ("0"+lcl.getMinutes()).slice(-2) + ":" + ("0"+lcl.getSeconds()).slice(-2) - if (id) lcl = lcl + " " + id; - return lcl; -} - -function postClick(e) { - e.preventDefault(); +function postClick(num) { var sel = window.getSelection().toString(); if (sel) sel = sel.replace(/^/gm, ">") + "\n"; - insert(">>" + this.textContent + "\n" + sel); + insert(">>"+num+"\n"+sel); } function insert(text) { @@ -103,13 +77,13 @@ function highlight(post) { } function expandimg(e) { - var post_id = this.dataset.id; - var img_url = this.href; - var thumb_url = this.dataset.thumb; - var img_w = parseInt(this.dataset.w); - var img_h = parseInt(this.dataset.h); - var thumb_w = parseInt(this.dataset.tw); - var thumb_h = parseInt(this.dataset.th); + var post_id = e.dataset.id; + var img_url = e.href; + var thumb_url = e.dataset.thumb; + var img_w = parseInt(e.dataset.w); + var img_h = parseInt(e.dataset.h); + var thumb_w = parseInt(e.dataset.tw); + var thumb_h = parseInt(e.dataset.th); var format = img_url.substring(img_url.lastIndexOf(".")+1, img_url.length); var exp_vid = 0; @@ -205,11 +179,10 @@ function filePreview(e) { } function togglethread(e) { - e.preventDefault(); - if(this.parentElement.id.startsWith("unhide")) { - var threadid = this.parentElement.id.substr(6); - } else if(this.parentElement.parentElement.id.startsWith("thread")) { - var threadid = this.parentElement.parentElement.id.substr(6); + 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"; @@ -371,7 +344,11 @@ document.addEventListener("DOMContentLoaded", function(e) { if (localStorage.hasOwnProperty("weabot")) weabot = JSON.parse(localStorage.getItem("weabot")); else weabot = {"name":null,"email":null,"password":null}; - board = document.getElementsByName("board")[0].value; + board = document.body.dataset.brd; + var a = document.getElementById("main_nav").getElementsByTagName("a"); + for(var i=0; i<a.length; i++) { + if (a[i].getAttribute("href") == "/"+board+"/") {a[i].className = "cur_brd"; break;} + } if(localStorage.hasOwnProperty("hiddenthreads")) { hiddenthreads = localStorage.getItem("hiddenthreads").split("!"); @@ -394,41 +371,12 @@ document.addEventListener("DOMContentLoaded", function(e) { } } - if(localStorage.getItem("shobon_time") != "false") { - var dts = document.getElementsByClassName("date"); - if (dts[0].dataset.unix) { - week = ["dom", "lun", "mar", "mie", "jue", "vie", "sab"]; - if (board == "2d") week = ["日", "月", "火", "水", "木", "金", "土"]; - 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); - } - } - } - - var ids = document.getElementsByClassName("postid"); - for(var i=0;i<ids.length;i++) { - ids[i].addEventListener('click', postClick); - } - var tts = document.getElementsByClassName("tt"); - for(var i=0;i<tts.length;i++) { - tts[i].addEventListener('click', togglethread); - } - var tts = document.getElementsByClassName("expimg"); - for(var i=0;i<tts.length;i++) { - tts[i].addEventListener('click', expandimg); - } - var styleSelect = document.getElementById("styles"); if (styleSelect) { styleSelect.addEventListener("change", applyTheme, false); styleSelect.value = localStorage.getItem(style_cookie); } - if (document.getElementById(board)) - document.getElementById(board).className = "cur_brd"; - if (document.getElementById("postform")) { setInputs("postform"); setPassword("delform"); @@ -456,4 +404,22 @@ document.addEventListener("DOMContentLoaded", function(e) { var thr = document.getElementsByClassName("thread"); for(var i=0;i<thr.length;i++) { thr[i].addEventListener("mouseenter", catMenu); thr[i].addEventListener("mouseleave", catMenuClose); } } -});
\ No newline at end of file +}); +document.addEventListener("click", function(e) { + var cn = e.target.className; + if (cn == "num") { + e.preventDefault(); + postClick(e.target.textContent); + return; + } + if (cn == "tt") { + e.preventDefault(); + togglethread(e.target); + return; + } + if (cn == "expimg") { + e.preventDefault(); + expandimg(e.target); + return; + } +},false);
\ No newline at end of file |