Created
April 20, 2015 23:39
-
-
Save LHSimon/ad13dc99ff3b6fbf1a95 to your computer and use it in GitHub Desktop.
This is designed to redirect to a random Netrunner card from http://netrunnerbd.com. I threw it together to work with the New Tab Redirect Chrome extension (https://chrome.google.com/webstore/detail/new-tab-redirect/icpgjfneehieebagbmdbhnlpiopdcmna?hl=en). It could all be done a lot better, but this was quick and it's done :-)
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
<html> | |
<head> | |
<script type="text/javascript"> | |
var baseUrl = 'http://netrunnerdb.com/en/card/'; | |
var maxSetId = 8; | |
var cardsCoreSet = 119; | |
var cardsBigBox = 55; | |
var cardsCycle = 120; | |
function generateUrl() | |
{ | |
var setId = randomSetId(); | |
var cardId = randomCardId(setId); | |
var url = baseUrl + setId + cardId; | |
return url; | |
} | |
function randomSetId() | |
{ | |
var setId = Math.floor((Math.random() * maxSetId) + 1); | |
if(setId < 10) | |
{ | |
return "0" + setId; | |
} | |
return setId; | |
} | |
function randomCardId(setId) | |
{ | |
var maxCardId = getMaxCardId(setId) | |
var cardId = Math.floor((Math.random() * maxCardId) + 1); | |
if(cardId < 100) | |
{ | |
if(cardId < 10) | |
{ | |
return "00" + cardId; | |
} | |
return "0" + cardId; | |
} | |
return cardId; | |
} | |
function getMaxCardId(setId) | |
{ | |
if(setId == 1) | |
{ | |
return cardsCoreSet; | |
} | |
else if(setId == 3 || setId == 5 || setId == 7) | |
{ | |
return cardsBigBox; | |
} | |
else | |
{ | |
if(setId == 8) | |
{ | |
//current cycle - not all cards available | |
} | |
return cardsCycle; | |
} | |
} | |
function go() | |
{ | |
window.location.replace(generateUrl()); | |
} | |
</script> | |
</head> | |
<body onload="go()"> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instructions: