-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxkcd.user.js
More file actions
29 lines (27 loc) · 1.15 KB
/
Copy pathxkcd.user.js
File metadata and controls
29 lines (27 loc) · 1.15 KB
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
// ==UserScript==
// @name XKCD - Keystrokes
// @namespace https://hkamran.com
// @version 1.0.1
// @description Next comic (Shift + N), previous comic (Shfit + P), random comic (Shift + R)
// @author H. Kamran
// @downloadUrl https://github.com/hkamran80/userscripts/raw/main/xkcd.user.js
// @updateUrl https://github.com/hkamran80/userscripts/raw/main/xkcd.user.js
// @match https://xkcd.com/*
// @grant none
// ==/UserScript==
function pagination(e) {
var evtobj = window.event ? event : e;
if (evtobj.keyCode == 78 && evtobj.shiftKey) {
// Next Page Keystroke (Shift + N)
const next_button_element = document.querySelector("a[rel=next]");
window.location.href = next_button_element.href;
} else if (evtobj.keyCode == 80 && evtobj.shiftKey) {
// Previous Page Keystroke (Shift + P)
const prev_button_element = document.querySelector("a[rel=prev]");
window.location.href = prev_button_element.href;
} else if (evtobj.keyCode == 82 && evtobj.shiftKey) {
// Random Comic Keystroke (Shift + R)
window.location.href = "https://c.xkcd.com/random/comic/";
}
}
document.onkeydown = pagination;