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/shobon.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/shobon.js')
-rw-r--r-- | static/js/shobon.js | 37 |
1 files changed, 37 insertions, 0 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")); |