let existingPosts = []; // Function to calculate relative time const timeAgo = function(date) { let seconds = Math.floor((new Date() - date) / 1000); let interval = seconds / 31536000; if (interval > 1) { return Math.floor(interval) + " years ago"; } interval = seconds / 2592000; if (interval > 1) { return Math.floor(interval) + " months ago"; } interval = seconds / 86400; if (interval > 1) { return Math.floor(interval) + " days ago"; } interval = seconds / 3600; if (interval > 1) { return Math.floor(interval) + " hours ago"; } interval = seconds / 60; if (interval > 1) { return Math.floor(interval) + " minutes ago"; } return Math.floor(seconds) + " seconds ago"; } // Function to fetch posts for a given hashtag const getPosts = function(hashtag) { return $.get(`https://openbiblio.social/api/v1/timelines/tag/${hashtag}`); } // Function to fetch and display posts const fetchAndDisplayPosts = function() { // Fetch posts for each hashtag $.when(getPosts('bibliocon23'), getPosts('111bibliocon'), getPosts('bibliocon')).then(function(bibliocon23Posts, bibliocon111Posts, biblioconPosts) { let allPosts = bibliocon23Posts[0].concat(bibliocon111Posts[0], biblioconPosts[0]); // Sort the posts by date/time allPosts.sort((a, b) => new Date(a.created_at) - new Date(b.created_at)); // Loop through the sorted posts $.each(allPosts, function(i, post) { // Check if the post is not already displayed and is not a mention if (!existingPosts.includes(post.id) && post.in_reply_to_id === null) { // Add the post id to existingPosts existingPosts.push(post.id); let cardHTML = `
${post.content}
${post.media_attachments.length > 0 ? `` : ''}