-
Notifications
You must be signed in to change notification settings - Fork 0
/
down.js
190 lines (161 loc) · 5.13 KB
/
down.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// v2
setInterval(function()
{
var address = "http://comic.studio";
var t1 = Date.now();
var t2;
var max = 90000; // 100 (Cloudflare's timeout time) - 10 (if not responding, i'm just too lazy :/ ) = 90
var failed = false;
var blank = "";
var timetaken = "";
var httpReq = (window.XMLHttpRequest)?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");
if(httpReq == null) {
console.log("Error: XMLHttpRequest failed to initiate.");
}
httpReq.onreadystatechange = function() {
var failTimer = setTimeout(function() {
failed = true;
httpReq.abort();
}, max);
if (httpReq.readyState == 4) { //Completed loading
if (!failed && (httpReq.status == 200 || httpReq.status == 0)) {
clearTimeout(failTimer);
t2 = Date.now();
var timeTotal = (t2 - t1);
if(timeTotal > max) {
onFail();
} else {
onSuccess(timeTotal);
}
}
else { //Otherwise, there was a problem while loading
console.log("Error " + httpReq.status + " has occurred.");
onFail();
}
}
}
try {
httpReq.open("GET", address, true);
httpReq.send(null);
} catch(e) {
console.log("Error retrieving data httpReq. Some browsers only accept cross-domain request with HTTP.");
onFail();
}
function onSuccess(timeTotal)
{
document.getElementById("isdown").innerHTML = "No";
timetaken = blank.concat("Time taken: ", timeTotal);
document.getElementById("time").innerHTML = timetaken;
}
function onFail() {
document.getElementById("isdown").innerHTML = "Yes";
timetaken = blank.concat("Time taken: ", max);
document.getElementById("time").innerHTML = timetaken;
}
timeTotal = 0;
timetaken = "";
}, 5000);
setInterval(function()
{
function ping() {
// The custom URL
var URL = "https://comic.studio";
var settings = {
cache: false,
dataType: "jsonp",
async: true,
crossDomain: true,
url: URL,
method: "GET",
// For response
statusCode: {
200: function (response) {
document.getElementById("isdown2").innerHTML = "No (200)";
},
400: function (response) {
document.getElementById("isdown2").innerHTML = "Yes (400)";
},
500: function (response) {
document.getElementById("isdown2").innerHTML = "Yes (500 - internal server error)";
},
502: function (response) {
document.getElementById("isdown2").innerHTML = "Yes (502 - bad gateway)";
},
503: function (response) {
document.getElementById("isdown2").innerHTML = "Yes (503 - service temporarily unavailable)";
},
504: function (response) {
document.getElementById("isdown2").innerHTML = "Yes (504 - gateway timeout)";
},
520: function (response) {
document.getElementById("isdown2").innerHTML = "Yes (520 - I have no idea.)";
},
521: function (response) {
document.getElementById("isdown2").innerHTML = "Yes (521 - WEB SERVER IS DOWN)";
},
522: function (response) {
document.getElementById("isdown2").innerHTML = "Yes (522 - connection timeout)";
},
523: function (response) {
document.getElementById("isdown2").innerHTML = "Yes (523 - UVC lamp. Just kidding, origin is unreachable.)";
},
524: function (response) {
document.getElementById("isdown2").innerHTML = "Yes (524 - Default, a timeout occurred)";
},
0: function (response) {
document.getElementById("isdown2").innerHTML = "Yes (0)";
},
},
};
// Sends the request and observes the response
$.ajax(settings).done(function (response) {
console.log(response);
});
}
ping()
}, 5000);
setInterval(function()
{
function isSiteOnline(url,callback) {
// try to load favicon
var timer = setTimeout(function(){
// timeout after 5 seconds
callback(false);
},5000)
var img = document.createElement("img");
img.onload = function() {
clearTimeout(timer);
callback(true);
}
img.onerror = function() {
clearTimeout(timer);
callback(false);
}
img.src = url+"/images/cookierun/icons/1e2ef5c3c84e065c7a6bdcb8a6f91bca.png";
}
isSiteOnline("http://cdn.comic.studio",function(found){
if(found) {
document.getElementById("isdown3").innerHTML = "No";
}
else {
document.getElementById("isdown3").innerHTML = "Yes";
}
})
}, 5000);
setInterval(function()
{
function checkServerStatus( url )
{
var script = document.body.appendChild(document.createElement("script"));
script.onload = function()
{
document.getElementById("isdown4").innerHTML = "No";
}
script.onerror = function()
{
document.getElementById("isdown4").innerHTML = "Yes";
};
script.src = url;
}
checkServerStatus( "https://comic.studio" );
}, 5000);