From 7dfe8cb8630bd08ff77e596bc07cfee8c22a4993 Mon Sep 17 00:00:00 2001 From: Mihir Chaturvedi Date: Tue, 2 Jul 2019 14:47:43 +0530 Subject: [PATCH] Feat: Add support for downvoting a comment by pressing 'D' --- src/features/key-bindings-on-items.js | 12 +++++++++++- src/libs/handle-item-keydowns.js | 22 +++++++++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/features/key-bindings-on-items.js b/src/features/key-bindings-on-items.js index a1697a5..39ec1c6 100644 --- a/src/features/key-bindings-on-items.js +++ b/src/features/key-bindings-on-items.js @@ -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; diff --git a/src/libs/handle-item-keydowns.js b/src/libs/handle-item-keydowns.js index f48817c..39b7244 100644 --- a/src/libs/handle-item-keydowns.js +++ b/src/libs/handle-item-keydowns.js @@ -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(); } },