Skip to content

Commit

Permalink
fix: upvoteSameComments should be compatible with the `addAuthorNam…
Browse files Browse the repository at this point in the history
…e` option
  • Loading branch information
double-beep authored May 28, 2024
1 parent 82bbc85 commit 7ef7ff3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
14 changes: 12 additions & 2 deletions src/UserscriptTools/Post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,22 @@ export default class Post {
}

public upvoteSameComments(comment: string): void {
const strippedComment = Post.getStrippedComment(comment);
const alternative = Store.config.addAuthorName
? comment.split(', ').slice(1).join(', ') // remove author's name
: `${this.opName}, ${comment}`; // add author's name

// convert comment texts to lowercase before comparing them
// compare both possible versions of the cached comment
// - the one without the author's name prepended
// - the one with author's name prepended
const stripped = Post.getStrippedComment(comment).toLowerCase();
const strippedAlt = Post.getStrippedComment(alternative).toLowerCase();

this.element
.querySelectorAll<HTMLElement>('.comment-body .comment-copy')
.forEach(element => {
if (element.innerText !== strippedComment) return;
const text = element.innerText.toLowerCase();
if (text !== stripped || text !== strippedAlt) return;

const parent = element.closest('li');

Expand Down
8 changes: 4 additions & 4 deletions src/popover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,13 @@ export class Popover {
private getCommentText({ comments }: CachedFlag): string | null {
// Adds the author name before the comment if the option is enabled
// and determines if the comment should be low/high rep
const { addAuthorName: AddAuthorName } = Store.config;
const { addAuthorName } = Store.config;

const commentType = (this.post.opReputation || 0) > 50 ? 'high' : 'low';
const comment = comments?.[commentType] || comments?.low;
const type = (this.post.opReputation || 0) > 50 ? 'high' : 'low';
const comment = comments?.[type] || comments?.low;

return (
comment && AddAuthorName
comment && addAuthorName
? `${this.post.opName}, ${comment[0].toLowerCase()}${comment.slice(1)}`
: comment
) || null;
Expand Down

0 comments on commit 7ef7ff3

Please sign in to comment.