diff options
-rw-r--r-- | cgi/templates/manage/recent.html | 6 | ||||
-rw-r--r-- | static/js/manage.js | 22 |
2 files changed, 25 insertions, 3 deletions
diff --git a/cgi/templates/manage/recent.html b/cgi/templates/manage/recent.html index 236094f..3fed05f 100644 --- a/cgi/templates/manage/recent.html +++ b/cgi/templates/manage/recent.html @@ -23,14 +23,14 @@ <?py #endif ?> </td> <td> - <div data-ts="#{post['timestamp']}">#{post['timestamp_formatted']}</div> + <div name="timestamp" data-ts="#{post['timestamp']}">#{post['timestamp_formatted']}</div> </td> <td> - <div style="display: block; margin-bottom: 0.5em; font-weight: bold;">#{post['subject']} #{post['name']} + <div style="display: block; margin-bottom: 0.5em; font-weight: bold;">#{post['subject']} <i>#{post['name']}</i> <code>#{post['email']}</code> #{post['tripcode']} </div> <div style="display: block">#{post['message']}</div> - <?py if post['parentid'] != 0: ?> + <?py if post['parentid'] != '0': ?> <div style="display: block; margin-top: 0.5em; font-size: 0.75em;"><a href="#{cgi_url}manage/mod/${post['dir']}?thread=#{post['parentid']}">Ver hilo completo</a> </div> diff --git a/static/js/manage.js b/static/js/manage.js index 10898d0..475361d 100644 --- a/static/js/manage.js +++ b/static/js/manage.js @@ -10,12 +10,34 @@ function pvw(e) { prev.addEventListener("input", function() { desc.value = prev.innerHTML; }); } +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"; +} + document.addEventListener("DOMContentLoaded", function(e) { var list = document.getElementById("timelist"); if (list) { var secs = document.getElementById("timelist").getElementsByTagName("a"); for(var i=0;i<secs.length;i++) secs[i].addEventListener("click", addtime); } + var tss = document.getElementsByName("timestamp"); + for (var i = 0; i < tss.length; i++){ + tss[i].title = tss[i].textContent; + tss[i].textContent = timeAgo(tss[i].dataset.ts); + } desc = document.getElementById("brd_desc"); if (desc) desc.addEventListener("input", pvw); |