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.

Revisions

  1. orng renamed this gist Mar 25, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. orng created this gist Mar 25, 2015.
    34 changes: 34 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    // ==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;
    }
    };