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 | |
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
-rw-r--r-- | cgi/templates/base_top.html | 2 | ||||
-rw-r--r-- | cgi/templates/board.html | 4 | ||||
-rw-r--r-- | cgi/templates/board.jp.html | 8 | ||||
-rw-r--r-- | cgi/templates/navbar.html | 28 | ||||
-rw-r--r-- | static/css/txt/postal.css | 2 | ||||
-rw-r--r-- | static/js/shobon.js | 37 | ||||
-rw-r--r-- | static/js/weabot.js | 108 | ||||
-rw-r--r-- | static/js/weabotxt.js | 47 |
8 files changed, 103 insertions, 133 deletions
diff --git a/cgi/templates/base_top.html b/cgi/templates/base_top.html index a95a257..6c51bef 100644 --- a/cgi/templates/base_top.html +++ b/cgi/templates/base_top.html @@ -39,7 +39,7 @@ <script type="text/javascript" src="#{static_url}js/aquiencitas.js"></script> <script type="text/javascript" src="#{static_url}js/autorefresh.js?v=3"></script> </head> -<body#{' class="res"' if replythread else ''}> +<body#{' class="res"' if replythread else ''} data-brd="#{board}"> <div id="main_nav">[<a href="/" target="_top">Bienvenido a Internet</a>] [<?py include('templates/navbar.html') ?>]</div> <div class="logo"> <?py if board: ?> diff --git a/cgi/templates/board.html b/cgi/templates/board.html index 09ed67d..0583230 100644 --- a/cgi/templates/board.html +++ b/cgi/templates/board.html @@ -184,7 +184,7 @@ <?py #endif ?> <span class="date" data-unix="#{post['timestamp']}">#{post['timestamp_formatted']}</span> <?py if replythread: ?> - <span class="reflink"><a href="##{post['id']}">No.</a><a href="#" class="postid">#{post['id']}</a></span> + <span class="reflink"><a href="##{post['id']}">No.</a><a href="#" class="num">#{post['id']}</a></span> <?py else: ?> <span class="reflink"><a href="#{boards_url}#{board}/res/#{post['parentid'] if post['parentid'] != "0" else post['id']}.html##{post['id']}">No.</a><a href="#{boards_url}#{board}/res/#{post['parentid'] if post['parentid'] != "0" else post['id']}.html#i#{post['id']}">#{post['id']}</a></span> <?py #endif ?> @@ -262,7 +262,7 @@ <div class="pg">#{pagenav}</div> <?py #endif ?> <?py if not force_css: ?> - <div class="selector"><b>Apariencia:</b><select id="styles"> + <div class="selector"><b>Estilo:</b><select id="styles"> <?py for title in styles: ?><option value="#{title}">#{title}</option><?py #endfor ?> </select> </div> diff --git a/cgi/templates/board.jp.html b/cgi/templates/board.jp.html index 8045ab1..12772e8 100644 --- a/cgi/templates/board.jp.html +++ b/cgi/templates/board.jp.html @@ -186,7 +186,7 @@ <?py #endif ?> <span class="date" data-unix="#{post['timestamp']}">#{post['timestamp_formatted']}</span> <?py if replythread: ?> - <span class="reflink"><a href="##{post['id']}">No.</a><a href="#" class="postid">#{post['id']}</a></span> + <span class="reflink"><a href="##{post['id']}">No.</a><a href="#" class="num">#{post['id']}</a></span> <?py else: ?> <span class="reflink"><a href="#{boards_url}#{board}/res/#{post['parentid'] if post['parentid'] != "0" else post['id']}.html##{post['id']}">No.</a><a href="#{boards_url}#{board}/res/#{post['parentid'] if post['parentid'] != "0" else post['id']}.html#i#{post['id']}">#{post['id']}</a></span> <?py #endif ?> @@ -268,4 +268,10 @@ <?py if pagenav: ?> <div class="pg">#{pagenav}</div> <?py #endif ?> +<?py if not force_css: ?> + <div class="selector"><b>外観:</b><select id="styles"> + <?py for title in styles: ?><option value="#{title}">#{title}</option><?py #endfor ?> + </select> + </div> +<?py #endif ?> <?py include('templates/base_bottom.html') ?>
\ No newline at end of file diff --git a/cgi/templates/navbar.html b/cgi/templates/navbar.html index 1655f0b..986c7c6 100644 --- a/cgi/templates/navbar.html +++ b/cgi/templates/navbar.html @@ -1,16 +1,16 @@ -<a id="noticias" href="/noticias/">Actualidad</a> -<a id="tech" href="/tech/">Tecnología</a> -<a id="juegos" href="/juegos/">Juegos</a> -<a id="musica" href="/musica/">Música</a> -<a id="tv" href="/tv/">TV y Cine</a> -<a id="letras" href="/letras/">Humanidades</a> -<a id="zonavip" href="/zonavip/">Club VIP</a> -<a id="world" href="/world/">World Lobby</a> +<a href="/noticias/">Actualidad</a> +<a href="/tech/">Tecnología</a> +<a href="/juegos/">Juegos</a> +<a href="/musica/">Música</a> +<a href="/tv/">TV y Cine</a> +<a href="/letras/">Humanidades</a> +<a href="/zonavip/">Club VIP</a> +<a href="/world/">World Lobby</a> | -<a id="img" href="/img/">Imágenes</a> -<a id="2d" href="/2d/">二次元画像</a> -<a id="n" href="/n/">Naturaleza</a> -<a id="o" href="/o/">Oekaki</a> -<a id="0" href="/0/">Cero</a> +<a href="/img/">Imágenes</a> +<a href="/2d/">二次元画像</a> +<a href="/n/">Naturaleza</a> +<a href="/o/">Oekaki</a> +<a href="/0/">Cero</a> | -<a id="bai" href="/bai/">Meta</a>
\ No newline at end of file +<a href="/bai/">Meta</a>
\ No newline at end of file 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; 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(); }); } |