aboutsummaryrefslogtreecommitdiff
path: root/static/js
diff options
context:
space:
mode:
authorLibravatar Señor X 2019-04-05 03:50:25 -0300
committerLibravatar Señor X 2019-04-05 03:52:47 -0300
commit6e2a0f64d910b6ccb4d09846ea313e3f308fd747 (patch)
treee9752724539336bdf9c14d3af89c2af52ea36ded /static/js
parent7d62e3d0ec4f96d6708e0946dffd81bded9f0aca (diff)
downloadweabot-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')
-rw-r--r--static/js/shobon.js37
-rw-r--r--static/js/weabot.js108
-rw-r--r--static/js/weabotxt.js47
3 files changed, 78 insertions, 114 deletions
diff --git a/static/js/shobon.js b/static/js/shobon.js
index 02d3c71..4b56aae 100644
--- a/static/js/shobon.js
+++ b/static/js/shobon.js
@@ -27,6 +27,13 @@ function shobon() {
loadFilters();
}
+ var shobon_time = localStorage.getItem("shobon_time");
+ if(shobon_time != "false") {
+ if (boardName == "world") week = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
+ else if (boardName == "2d") week = ["日", "月", "火", "水", "木", "金", "土"];
+ else week = ["dom", "lun", "mar", "mie", "jue", "vie", "sab"];
+ }
+
var threadList = document.getElementsByClassName("thread");
for (var i=0; i<threadList.length; i++) {
var threadId;
@@ -48,6 +55,13 @@ function shobon() {
for (var e = 0; e < replyList.length; e++) {
var reply = replyList[e];
var message = reply.getElementsByClassName("msg")[0];
+
+ if(shobon_time != "false") {
+ var date = reply.getElementsByClassName("date")[0];
+ date.addEventListener("mouseover", function(e) { this.title = "Hace "+timeAgo(this.dataset.unix); });
+ if (date.textContent.includes("ID:")) var id = date.textContent.split(" ")[1];
+ date.textContent = localTime(date.dataset.unix, id);
+ }
if(localStorage.getItem("shobon_newposts") == "true") {
var replyId = reply.attributes["data-n"].value;
@@ -150,6 +164,29 @@ function createTh(label, w) {
th.width = w;
return th;
}
+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 loadFilters() {
var filters = JSON.parse(localStorage.getItem("shobon_filters"));
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
diff --git a/static/js/weabotxt.js b/static/js/weabotxt.js
index 269168e..5cf205e 100644
--- a/static/js/weabotxt.js
+++ b/static/js/weabotxt.js
@@ -11,44 +11,6 @@ function set_stylesheet(styletitle) {
localStorage.setItem(style_cookie,styletitle);
}
-function changeDate() {
- var dts = document.getElementsByClassName("date");
- if (dts[0].dataset.unix) {
- week = ["dom", "lun", "mar", "mie", "jue", "vie", "sab"];
- 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].textContent.includes("ID:")) var id = dts[d].textContent.split(" ")[1];
- dts[d].textContent = localTime(dts[d].dataset.unix, id);
- }
- }
-}
-
-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;
-}
-
/* 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*/) {
@@ -248,8 +210,10 @@ document.addEventListener("DOMContentLoaded", function() {
else weabot = {"name":null,"email":null,"password":null};
board = document.body.dataset.brd;
- var where = document.getElementById(board);
- if (where) where.className = "cur_brd";
+ var b = document.getElementById("main_nav").getElementsByTagName("a");
+ for(var i=0; i<b.length; i++) {
+ if (b[i].getAttribute("href") == "/"+board+"/") { b[i].className = "cur_brd"; break; }
+ }
var forms = document.getElementsByTagName("form");
for(var i=0;i<forms.length;i++) { if(forms[i].id.startsWith("postform")) setInputs(forms[i].id); }
@@ -260,9 +224,6 @@ document.addEventListener("DOMContentLoaded", function() {
styleSelect.value = localStorage.getItem(style_cookie);
}
- if(localStorage.getItem("shobon_time") != "false")
- changeDate();
-
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(); }); }