jarlefo / XKCD keyboard navigation

// ==UserScript==
// @name         XKCD keyboard navigation
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Easily navigate XKCD with keyboard arrows
// @author       jarlefosen
// @match        *://xkcd.com/*
// @grant        none
// ==/UserScript==
/* jshint -W097 */
(function() {
    'use strict';
    function navigateXKCDLeft() {
        location.href=document.querySelector('a[rel="prev"]').href;
    }
    function navigateXKCDRight() {
        location.href=document.querySelector('a[rel="next"]').href;
    }

    function navigateXKCD(e) {
        var c=e.keyCode;
        if(c==37) // Arrow left
            navigateXKCDLeft();
        if(c==39) // Arrow right
            navigateXKCDRight();
    }

    if (document.onkeydown !== undefined && document.querySelector('#comic script') === null){
        document.onkeydown=navigateXKCD;
    }
})();