Created
July 7, 2013 02:31
-
-
Save sarahzrf/5942038 to your computer and use it in GitHub Desktop.
"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name prev/next with left/right arrows on sites | |
// @namespace http://omgmog.net | |
// @description Binds left/right arrow keys to click on urls with rel="prev" and rel="next" -- useful for navigating comic sites and image galleries | |
// @include http://* | |
// @version 1.0 | |
// ==/UserScript== | |
function addJQuery(a){var b=document.createElement("script");b.setAttribute("src","http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js");b.addEventListener("load",function(){var b=document.createElement("script");b.textContent="("+a.toString()+")();";document.body.appendChild(b)},false);document.body.appendChild(b)} | |
function main(){ | |
jQuery.noConflict(); | |
jQuery(document).ready(function() { | |
// Code that uses jQuery's $ can follow here. | |
jQuery(document).keydown(function(e){ | |
var url ="" | |
if (matches = window.location.match(/(.+?)(\d+)/)) | |
{ | |
if(e.keyCode == 37) { | |
url = matches[1] + toString(parseInt(matches[2] + 1)) | |
} | |
if(e.keyCode == 39) { | |
url = matches[1] + toString(parseInt(matches[2] - 1)) | |
} | |
if(url && url!="" && url!=undefined) window.location = url; | |
} | |
}); | |
}); | |
}; | |
addJQuery(main); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment