-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
25 lines (21 loc) · 848 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
var phdstr = /archive_print.php\?comicid=(....)/;
window.addEventListener("load", function(){
var maxID = 1;
var theURL = "https://crossorigin.me/http://phdcomics.com/";
var randFrame = document.getElementById("frame");
var randButton = document.getElementById("randButton");
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
foundMaxID = xmlHttp.responseText.match(phdstr);
maxID = foundMaxID[1];
randButton.addEventListener("click",function(){
var randID = Math.ceil((Math.random() * maxID));
var randComicID = ("0000" + randID).substr(-4,4);
randFrame.src = 'http://phdcomics.com/comics/archive.php?comicid=' + randComicID;
});
}
}
xmlHttp.open("GET", theURL, true); // true for asynchronous
xmlHttp.send(null);
});