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/css/txt/postal.css | 2 +- static/js/shobon.js | 37 ++++++++++++++++ static/js/weabot.js | 108 ++++++++++++++++------------------------------ static/js/weabotxt.js | 47 ++------------------ 4 files changed, 79 insertions(+), 115 deletions(-) (limited to 'static') diff --git a/static/css/txt/postal.css b/static/css/txt/postal.css index fc5957e..87f03af 100644 --- a/static/css/txt/postal.css +++ b/static/css/txt/postal.css @@ -21,7 +21,7 @@ h4{background:#F0E7CE;color:#686868;padding-left:3px} .thread .innerbox{background:#FFF;box-shadow:1px 1px 0 rgba(0,0,0,0.1),3px 3px 0 rgba(255,255,255,1),4px 4px 0 rgba(0,0,0,0.125),6px 6px 0 rgba(255,255,255,1),7px 7px 0 rgba(0,0,0,0.15),9px 9px 0 rgba(255,255,255,1),10px 10px 0 rgba(0,0,0,0.175),12px 12px 0 rgba(255,255,255,1),13px 13px 0 rgba(0,0,0,0.175);margin:8px 12px 8px 0;padding:8px} #thread_nav{background:#FFF;font-style:italic;padding:1.5em 8px .5em} .threadpage .thread{background-color:#FFF;background-position:bottom;background-repeat:repeat-x;background-size:100% 1em;overflow:hidden;padding:0 10px 1em} -.innerbox.links {border-top:2px solid #E5B98D;margin:-1px;padding:12px} +.innerbox.links{border-top:1px solid #E5B98D;margin:0 -1px} .name,.abbrev{color:#416D91} .name em{color:#009} .del a{color:#000} 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; i31535999) 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; i31535999) 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