From 0c9a7e76bc0394ae62f12f667b16bf4e50d29265 Mon Sep 17 00:00:00 2001 From: Aevann Date: Fri, 15 Sep 2023 03:33:08 +0300 Subject: [PATCH] do this https://watchpeopledie.tv/h/meta/post/61549/megathread-for-bugs-and-suggestions/1685005#context --- files/assets/js/chat.js | 32 ++++++++++---------------------- files/templates/util/macros.html | 2 +- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/files/assets/js/chat.js b/files/assets/js/chat.js index 9e40c67a4..213dfaafd 100644 --- a/files/assets/js/chat.js +++ b/files/assets/js/chat.js @@ -1,23 +1,14 @@ -function timeSince(timeStamp) { - const now = new Date(), - secondsPast = (now.getTime() - timeStamp) / 1000; - if (secondsPast < 60) { - return parseInt(secondsPast) + 's'; - } - if (secondsPast < 3600) { - return parseInt(secondsPast / 60) + 'm'; - } - if (secondsPast <= 86400) { - return parseInt(secondsPast / 3600) + 'h'; - } - if (secondsPast > 86400) { - day = timeStamp.getDate(); - month = timeStamp.toDateString().match(/ [a-zA-Z]*/)[0].replace(" ", ""); - year = timeStamp.getFullYear() == now.getFullYear() ? "" : " " + timeStamp.getFullYear(); - return day + " " + month + year; - } +function formatDate(d) { + const hour = ("0" + d.getHours()).slice(-2); + const minute = ("0" + d.getMinutes()).slice(-2); + const second = ("0" + d.getSeconds()).slice(-2); + return hour + ":" + minute + ":" + second; } +for (const e of timestamps) { + e.innerHTML = formatDate(new Date(e.dataset.time*1000)); +}; + const ua=window.navigator.userAgent let socket @@ -125,10 +116,7 @@ socket.on('speak', function(json) { document.getElementsByClassName('user_id')[0].value = json.user_id - if (Date.now() - json.time*1000 > 5000) - document.getElementsByClassName('time')[0].innerHTML = timeSince(json.time*1000) + ' ago' - else - document.getElementsByClassName('time')[0].innerHTML = "just now" + document.getElementsByClassName('time')[0].innerHTML = formatDate(new Date(json.time*1000)) } document.getElementsByClassName('chat-line')[0].id = json.id diff --git a/files/templates/util/macros.html b/files/templates/util/macros.html index ed6322e9b..4b2047bc3 100644 --- a/files/templates/util/macros.html +++ b/files/templates/util/macros.html @@ -235,7 +235,7 @@ {% if m %}{{m.username}}{% endif %} - {% if m %}{{m.time | timestamp}}{% else %}just now{% endif %} + {% endmacro %}