Skip to content

Instantly share code, notes, and snippets.

@hkamran80
Last active October 6, 2020 21:56
Show Gist options
  • Save hkamran80/7746d7c2ba47e9ecdff547600635fd51 to your computer and use it in GitHub Desktop.
Save hkamran80/7746d7c2ba47e9ecdff547600635fd51 to your computer and use it in GitHub Desktop.
XKCD - Keystrokes
// ==UserScript==
// @name XKCD - Keystrokes
// @namespace https://hkamran.com
// @version 1.0.1
// @description Keystrokes for XKCD
// @author H. Kamran
// @downloadUrl https://gist.github.com/hkamran80/7746d7c2ba47e9ecdff547600635fd51/raw/xkcd.user.js
// @updateUrl https://gist.github.com/hkamran80/7746d7c2ba47e9ecdff547600635fd51/raw/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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment