From b0051867aadf2cadc01e029ef79b79814b4c34c8 Mon Sep 17 00:00:00 2001 From: "Max L." Date: Fri, 24 Nov 2023 12:25:34 +0100 Subject: [PATCH] Fix wrong links getting their time updated --- script.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/script.js b/script.js index 02e5f8d..d7b2b46 100644 --- a/script.js +++ b/script.js @@ -95,8 +95,10 @@ const fetchPosts = async function(serverUrl, hashtag) { // updateTimesOnPage updates the time information displayed for each post const updateTimesOnPage = function() { - $('.card-text a').each(function() { - const date = new Date($(this).attr('data-time')); + $('.card-text a.time').each(function() { + const timeValue = $(this).attr('data-time'); + if (timeValue === '') return; + const date = new Date(timeValue); const newTimeAgo = timeAgo(secondsAgo(date)); $(this).text(newTimeAgo); }); @@ -118,7 +120,7 @@ const displayPost = function(post) { ${post.media_attachments[0] ? `` : ''}

${DOMPurify.sanitize(post.content)}

${post.spoiler_text ? `

${DOMPurify.sanitize(post.spoiler_text)}

` : ''} -

${timeAgo(secondsAgo(new Date(post.created_at)))}

+

${timeAgo(secondsAgo(new Date(post.created_at)))}

`; @@ -196,7 +198,7 @@ const updateCarousel = function(slides, posts) {

- ${timeAgo(secondsAgo(new Date(post.created_at)))} + ${timeAgo(secondsAgo(new Date(post.created_at)))} ${post.favourites_count ? `, ${post.favourites_count} mal favorisiert` : '' } ${post.replies_count ? `, ${post.replies_count} mal kommentiert` : '' } ${post.reblogs_count ? `, ${post.reblogs_count} mal geteilt` : '' }