Skip to content

Commit

Permalink
Feat: Add support for downvoting a comment by pressing 'D'
Browse files Browse the repository at this point in the history
  • Loading branch information
plibither8 committed Jul 2, 2019
1 parent 16f8c0d commit 7dfe8cb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
12 changes: 11 additions & 1 deletion src/features/key-bindings-on-items.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,17 @@ function init(metadata) {
return;
}

keydown.comment.vote(itemData.activeItem);
keydown.comment.upvote(itemData.activeItem);

return;

// D: downvote comment/reply
case 68:
if (combo) {
return;
}

keydown.comment.downvote(itemData.activeItem);

return;

Expand Down
22 changes: 17 additions & 5 deletions src/libs/handle-item-keydowns.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,27 @@ const comment = {
}
},

// Vote/unvote comment
vote(activeItem) {
const vote = activeItem.previousSibling.querySelector('div.votearrow');
// Upvote/unvote comment
upvote(activeItem) {
const upvoteBtn = activeItem.previousSibling.querySelector('div.votearrow[title="upvote"]');
const unvote = activeItem.querySelector('a[id^="un_"]');

if (unvote) {
unvote.click();
} else if (vote) {
vote.click();
} else if (upvoteBtn) {
upvoteBtn.click();
}
},

// Downvote/undown comment
downvote(activeItem) {
const downvoteBtn = activeItem.previousSibling.querySelector('div.votearrow[title="downvote"]');
const undown = activeItem.querySelector('a[id^="un_"]');

if (undown) {
undown.click();
} else if (downvoteBtn) {
downvoteBtn.click();
}
},

Expand Down

0 comments on commit 7dfe8cb

Please sign in to comment.