fix duplicate ~new~ indicators being sent (#642)

we also make the JS we're generating about 7% the size it was before.
This commit is contained in:
justcool393 2023-07-22 17:52:09 -07:00 committed by GitHub
parent 2541737833
commit a5a344f084
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 36 deletions

View file

@ -56,4 +56,22 @@ function expandMarkdown(t,id) {
let val = t.getElementsByTagName('span')[0]
if (val.innerHTML == 'View source') val.innerHTML = 'Hide source'
else val.innerHTML = 'View source'
};
};
function commentsAddUnreadIndicator(commentIds) {
commentIds.forEach(element => {
const commentOnly = document.getElementById(`comment-${element}-only`);
if (!commentOnly) {
console.warn(`Couldn't find comment (comment ID ${element}) in page while attempting to add an unread indicator.`);
return;
}
if (commentOnly.classList.contains("unread")) return;
commentOnly.classList.add("unread");
const commentUserInfo = document.getElementById(`comment-${element}`)?.querySelector(".comment-user-info");
if (!commentUserInfo) {
console.warn(`Couldn't find comment user info (comment ID ${element}) in page while attempting to add an unread indicator.`);
return;
}
commentUserInfo.innerHTML += "<span class=\"new-indicator\">~new~</span>";
});
}