Last active
August 29, 2015 14:17
-
-
Save roastedlasagna/d969bbc92b469124eb51 to your computer and use it in GitHub Desktop.
Browse through the list of least popular xkcd comics
This file contains hidden or 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 least popular xkcd browser | |
// @description Browse through the list of least popular xkcd comics | |
// @namespace http://www.reddit.com/user/roastedlasagna | |
// @author roastedlasagna | |
// @include /^https?:\/\/(www\.)?xkcd\.com\/(\d+\/)?$/ | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
/* Use left and right arrow keys while on xkcd.com to navigate between the list of least popular comics. */ | |
var list = [4, 7, 12, 24, 35, 39, 46, 47, 49, 62, 65, 68, 71, 76, 81, 82, 92, 98, 104, 106, 113, 116, 121, 127, 160, 170, 197, 201, 212, 215, 216, 226, 230, 268, 324, 336, 340, 345, 354, 355, 358, 369, 372, 381, 402, 423, 453, 470, 480, 511, 521, 535, 536, 637, 650, 662, 665, 709, 711, 797, 812, 818, 822, 847, 872, 885, 886, 894, 901, 929, 942, 943, 976, 1003, 1005, 1006, 1017, 1021, 1041, 1059, 1064, 1121, 1125, 1126, 1136, 1142, 1154, 1188, 1230, 1249, 1284]; | |
var leftNum; | |
var rightNum; | |
var num; | |
function main(){ | |
getComicNumber(); | |
getLeftAndRight(); | |
} | |
function getComicNumber(){ | |
theurl = document.URL; | |
num = theurl.slice(theurl.indexOf("m/")+2, theurl.length-1); | |
leftNum = num; | |
rightNum = num; | |
} | |
function getLeftAndRight(){ | |
for (var i=0; i<list.length; i++){ | |
if (list[i] > num){ | |
rightNum = list[i] | |
i = 1000; | |
} | |
} | |
for (var j=list.length; j>0; j--){ | |
if (list[j] < num){ | |
leftNum = list[j]; | |
j = -1; | |
} | |
} | |
} | |
$(document).keydown(function(e) { | |
switch(e.which) { | |
case 37: // left | |
window.location.href = "http://www.xkcd.com/" + leftNum; | |
break; | |
case 39: // right | |
window.location.href = "http://www.xkcd.com/" + rightNum; | |
break; | |
default: return; | |
} | |
e.preventDefault(); | |
}); | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment