//postcount function refreshPostCounts(postCounts, scope = document) { const posterIds = Array.from(scope.getElementsByClassName('poster_id')); posterIds.forEach(e => { const postCount = postCounts[e.textContent]; e.title = `${postCount} post${postCount == 1 ? '' : 's'} by this ID.`; }); } if (active_page === 'thread') { // Media approval auto-refresh messes with the behaviour of the new_post event. // Keep track of seen posts to prevent counting the same post more than once. const seen = []; const postCounts = {}; const posterIds = Array.from(document.getElementsByClassName('poster_id')); if (posterIds.length) { posterIds.forEach(e => { postCounts[e.textContent] = postCounts[e.textContent] + 1 || 1; }); } refreshPostCounts(postCounts); $(document).on('new_post', function(e, post) { let id = post.getElementsByClassName('poster_id'); let postNum = post.getElementsByClassName('post_no')[1].textContent; if (id.length && !seen.includes(postNum)) { id = id[0].textContent; seen.push(postNum); postCounts[id] = postCounts[id] + 1 || 1; refreshPostCounts(postCounts); } else { refreshPostCounts(postCounts, post); // Make sure post has a counter. } }); } //download links function addServerDownloadLinks(element) { Array.from(element.getElementsByClassName('filename-download-link')).forEach(elem => { let serverDownloadLink = elem.cloneNode(); serverDownloadLink.download = ''; serverDownloadLink.textContent = '(s)'; serverDownloadLink.title = 'Download with server filename'; elem.after(document.createTextNode('\u00A0'), serverDownloadLink); }) } addServerDownloadLinks(document); $(document).on('new_post', function(e, post) { addServerDownloadLinks(post); }); //UID capcode function markUID(scope) { $(scope).find("img.flag").each((i, img) => { const alt = img.getAttribute("alt") || ""; if (!alt.startsWith("UID ")) return; const UID = alt.split(" - ")[0]; const name = $(img).closest(".post").find("span.name"); if (name.length === 0) return; const cap = document.createElement("span"); cap.textContent = ` ## ${UID}`; cap.style.color = "green"; cap.style.fontWeight = "normal"; name.append(cap); }); } markUID(document); $(document).on("new_post", (e, post) => { markUID(post); });