From 6e2a0f64d910b6ccb4d09846ea313e3f308fd747 Mon Sep 17 00:00:00 2001 From: Señor X Date: Fri, 5 Apr 2019 03:50:25 -0300 Subject: Moviendo funciones de hora local de weabot.js y weabotxt.js a shobon.js + Delegación --- static/js/weabot.js | 108 ++++++++++++++++++---------------------------------- 1 file changed, 37 insertions(+), 71 deletions(-) (limited to 'static/js/weabot.js') 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