Skip to content

Instantly share code, notes, and snippets.

@danthemango
Last active July 26, 2021 02:53
Show Gist options
  • Save danthemango/2391a9210c0e395af2a54df5a70b3cb9 to your computer and use it in GitHub Desktop.
Save danthemango/2391a9210c0e395af2a54df5a70b3cb9 to your computer and use it in GitHub Desktop.
userscript to navigate XKCD with J and K
// ==UserScript==
// @name XKCD Nav
// @namespace http://tampermonkey.net/
// @version 0.1
// @description move back and forth in xkcd comic with J and K
// @match https://*.xkcd.com/*
// @grant none
// ==/UserScript==
// main
(function() {
'use strict';
window.addEventListener("keydown", function(event) {
if (event.key == 'j' || event.key == 'J') {
const bts = document.querySelectorAll('[rel="next"]')
if (bts.length > 0) {
bts[0].click();
}
} else if (event.key == 'k' || event.key == 'K') {
const bts = document.querySelectorAll('[rel="prev"]')
if (bts.length > 0) {
bts[0].click();
}
}
}, true);
window.addEventListener("load", function() {
document.querySelector('#ctitle').scrollIntoView();
}, false);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment