Skip to content

Commit

Permalink
fix: show "Delete" option in the popover if score is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
double-beep authored Jul 6, 2024
1 parent faaca22 commit 9c99d76
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/UserscriptTools/Post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,15 +403,17 @@ export default class Post {
iconLocation?.append(...icons);
}

public canDelete(): boolean {
public canDelete(popover = false): boolean {
const selector = '.js-delete-post[title^="Vote to delete"]';
const deleteButton = this.element.querySelector(selector);

const userRep = StackExchange.options.user.rep;

// >20k rep users can vote to delete answers with score < 0
return (Boolean(deleteButton) || (userRep > 20_000 && this.score < 0))
// can delete if post isn't already deleted
return (
Boolean(deleteButton)
|| (userRep >= 20_000 && (popover ? this.score <= 0 : this.score < 0))
) // can delete if post isn't already deleted
&& !this.deleted;
}

Expand Down
2 changes: 1 addition & 1 deletion src/popover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export class Popover {
// hide delete checkbox when user can't delete vote
.filter(([ text ]) => {
if (text === 'Leave comment') return Page.isStackOverflow;
else if (text === 'Delete') return this.post.canDelete();
else if (text === 'Delete') return this.post.canDelete(true);

return true;
})
Expand Down

0 comments on commit 9c99d76

Please sign in to comment.