diff --git a/source/content-scripts/features/hide-votes.ts b/source/content-scripts/features/hide-votes.ts index 90917f3..cce483a 100644 --- a/source/content-scripts/features/hide-votes.ts +++ b/source/content-scripts/features/hide-votes.ts @@ -9,52 +9,116 @@ export function runHideVotesFeature(data: HideVotesData) { function hideVotes(data: HideVotesData): number { let count = 0; - if (data.otherComments) { - const commentVotes = querySelectorAll( - '.btn-post-action[data-ic-put-to*="/vote"]:not(.trx-votes-hidden)', - '.btn-post-action[data-ic-delete-from*="/vote"]:not(.trx-votes-hidden)', - ); - count += commentVotes.length; + // Get the username of the currently logged in user. When not logged in, set + // it to "" which isn't a valid username, so matching against it + // will always return false. Meaning all comments are never the current user's. + const currentUser = + document.querySelector(".logged-in-user-username")?.textContent?.trim() ?? + ""; - for (const vote of commentVotes) { - vote.classList.add("trx-votes-hidden"); - if (!vote.textContent!.includes(" ")) { - continue; - } - - vote.textContent = vote.textContent!.slice( - 0, - vote.textContent!.indexOf(" "), - ); - } - } - - if (data.ownComments) { - const ownComments = querySelectorAll(".comment-votes"); - count += ownComments.length; - for (const vote of ownComments) { - vote.classList.add("trx-hidden"); - } + if (data.otherComments || data.ownComments) { + count += hideCommentVotes(data, currentUser); } if (data.otherTopics || data.ownTopics) { - const selectors: string[] = []; + count += hideTopicVotes(data, currentUser); + } - // Topics by other people will be encapsulated with a `