Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name reddit inbox keyboard commands
- // @match https://*.reddit.com/message/*
- // @description RES style keyboard commands, without the bulk. Meant for /r/counting, and only works in inbox.
- // @author TehVulpez
- // ==/UserScript==
- var siteTable = document.getElementById("siteTable");
- var currentNo = 0;
- var currentEl;
- function handleKeys(e) {
- if (document.activeElement.nodeName == "TEXTAREA") { // stop keyboard commands from activating while in textarea
- return;
- }
- else if (e.key == "j" && currentNo != 48) { // down
- currentEl.style.backgroundColor = "#fff";
- currentNo += 2;
- setMessage();
- currentEl.scrollIntoView({block:"center"});
- }
- else if (e.key == "k" && currentNo != 0) { // up
- currentEl.style.backgroundColor = "#fff";
- currentNo -= 2;
- setMessage();
- currentEl.scrollIntoView({block:"center"});
- }
- else if (e.key == "a") { // upvote
- currentEl.getElementsByClassName("arrow")[0].click();
- }
- else if (e.key == "z") { // downvote
- currentEl.getElementsByClassName("arrow")[1].click();
- }
- else if (e.key == "r" && !e.ctrlKey) { // reply
- currentEl.getElementsByClassName("buttons")[0].lastChild.lastChild.click();
- e.preventDefault();
- }
- }
- function setMessage() {
- currentEl = siteTable.children[currentNo];
- currentEl.style.backgroundColor = "#eef";
- }
- setMessage();
- addEventListener("keydown",handleKeys);
Add Comment
Please, Sign In to add comment