-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREDDIT thread shortcuts.user.js
56 lines (52 loc) · 1.58 KB
/
REDDIT thread shortcuts.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// ==UserScript==
// @name REDDIT thread shortcuts
// @namespace http://github.com/steventheworker
// @version 0.1
// @description T N O C B - top new old controversial best
// @author steventheworker
// @grant none
// @icon https://www.redditstatic.com/desktop2x/img/favicon/android-icon-192x192.png
// @match https://www.reddit.com/r/*/comments/*
// ==/UserScript==
function addGlobalStyle(css) {
//https://greasyfork.org/en/scripts/405073-wide-new-reddit-userscript
var head, style;
head = document.getElementsByTagName("head")[0];
if (!head) {
return;
}
style = document.createElement("style");
style.type = "text/css";
style.innerHTML = css;
head.appendChild(style);
}
function menuClick(select) {
//open menu, then click menu-item
document.querySelector("button#CommentSort--SortPicker").click();
Array.prototype.slice
.call(document.querySelectorAll('div[role="menu"] button'))
[select].click();
}
(function () {
"use strict";
addGlobalStyle(
"._1OVBBWLtHoSPfGCRaPzpTf._3nSp9cdBpqL13CqjdMr2L_ { width: 90% !important;}"
);
addGlobalStyle("div { max-width: none !important; }");
window.addEventListener("keydown", function (e) {
const nn = document.activeElement.nodeName;
if (
nn === "INPUT" ||
nn === "TEXTAREA" ||
(nn == "DIV" && document.activeElement.contentEditable === "true")
)
return;
//sort
if (e.key === "B") menuClick(0);
if (e.key === "T") menuClick(1);
if (e.key === "N") menuClick(2);
if (e.key === "O") menuClick(4);
if (e.key === "C") menuClick(3);
if (e.key === "Q") menuClick(5);
});
})();