From 8d533d3f6a0c2e9f2c71fa781af1c2b5abf58713 Mon Sep 17 00:00:00 2001 From: kapypara Date: Sat, 16 Dec 2023 20:26:41 +0300 Subject: [PATCH] added updater for the items post time --- static/index.js | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/static/index.js b/static/index.js index dc735e6..267010d 100644 --- a/static/index.js +++ b/static/index.js @@ -143,7 +143,13 @@ function makeItemListing(itemObj) { ` const item = document.createElement('a') item.href = "index.html?id=" + id + + // i got lazy item.time = time + item.points = points + item.comments = comments + item.author = author + item.innerHTML = element_string if (url === undefined || hostname === undefined) { @@ -431,7 +437,7 @@ async function loadFresh() { const newEnd = newMax - if (newMax == endItem) { + if (newMax <= endItem) { return } @@ -440,7 +446,7 @@ async function loadFresh() { let intervalId = setInterval(async () => { - if (newMax == endItem) { + if (newMax <= endItem) { endItem = newEnd notify(count) return clearInterval(intervalId) @@ -471,3 +477,31 @@ if (newMode) { setTimeout(setInterval, 5e3, loadFresh, 5e3) } + +if (!isQuery) { + setInterval(() => { + Array.from(pageItemBox.getElementsByTagName('a')).map(c => { + + if (!c.time) { + return + } + + const sub = c.getElementsByClassName('subtitle')[0] + + const date = timeSince(c.time) + const points = c.points + const author = c.author + const comments = c.comments + + let subtitle = `${points} points by ${author} ${date} ago` + + console.log(comments) + + if (comments !== undefined) { + subtitle += ` | ${comments} comments` + } + + sub.innerHTML = subtitle + }) + }, 1e3) +}