Skip to content

Instantly share code, notes, and snippets.

@orng
Last active August 29, 2015 14:17
Show Gist options
  • Save orng/c44890bf962056cb6fc5 to your computer and use it in GitHub Desktop.
Save orng/c44890bf962056cb6fc5 to your computer and use it in GitHub Desktop.
Crude UserScript hack that enables arrow navigation for the html version of "Artificial Intelligence - Foundations of Computational Agents"
// ==UserScript==
// @name ArtInt Navigator
// @namespace gorn/aiNav
// @description Enables back and forth navigation using the arrow keys on AI book webpage
// @include http://artint.info/html/ArtInt_*.html
// @version 1
// @grant none
// ==/UserScript==
var base = "http://artint.info/html/ArtInt_";
var end = ".html"
function getNumber()
{
var url = document.URL;
var number = parseInt(url.match("[0-9]+"));
return number;
}
document.onkeydown = function(evt) {
evt = evt || window.event;
switch (evt.keyCode) {
case 37:
newUrl = base + (getNumber() - 1) + end;
document.location.href = newUrl;
break;
case 39:
newUrl = base + (getNumber() + 1) + end;
document.location.href = newUrl;
break;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment