Skip to content

Instantly share code, notes, and snippets.

@georgestephanis
Last active September 22, 2021 13:11
Show Gist options
  • Save georgestephanis/d96ce4766c091f01a53544d1e45d59f8 to your computer and use it in GitHub Desktop.
Save georgestephanis/d96ce4766c091f01a53544d1e45d59f8 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name OGLAF Keyboard Navigation
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Add left/right arrow keyboard navigation.
// @author You
// @match https://www.oglaf.com/*
// @icon https://static.oglaf.com/favicon.png
// @grant none
// ==/UserScript==
(function() {
'use strict';
const keyNav = function( e ) {
let url = false;
if ( e.code == 'ArrowLeft' ) { // Left arrow key code
url = document.querySelector( '#nav .previous' ).href;
} else if ( e.code == 'ArrowRight' ) { // Right arrow key code
url = document.querySelector( '#nav .next' ).href;
}
if ( url ) {
window.location = url;
}
}
document.addEventListener( 'keydown', keyNav );
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment