-
Notifications
You must be signed in to change notification settings - Fork 0
/
challenges.js
62 lines (56 loc) · 1.24 KB
/
challenges.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
function fetchHints()
{
var fetcher = new XMLHttpRequest();
fetcher.addEventListener( "load", parseHints );
fetcher.open( "GET", "api/hints.py" );
fetcher.send();
}
function parseHints()
{
if(this.status != 200)
{
throw this;
}
killAllChildren(document.getElementById("hintlist"));
var hints = JSON.parse(this.responseText);
for(var hintid in hints)
{
var hint = hints[ hintid ];
var hintdom = document.createElement("li");
if( hint.url )
{
var anchor = document.createElement("a");
anchor.href = hint.url;
anchor.appendChild( document.createTextNode( hint.description ) );
hintdom.appendChild( anchor );
} else {
hintdom.appendChild( document.createTextNode( hint.description ) );
}
document.getElementById("hintlist").appendChild(hintdom);
}
}
function fetchNextDrop()
{
var fetcher = new XMLHttpRequest();
fetcher.addEventListener( "load", parseDrop );
fetcher.open( "GET", "api/nextchallenge.py" );
fetcher.send();
}
fetchNextDrop();
function parseDrop()
{
if(this.status != 200)
{
throw this;
}
var time = JSON.parse( this.responseText );
document.getElementById( "nextdrop" ).innerHTML = time;
}
function killAllChildren(dom)
{
while(dom.firstChild)
{
dom.removeChild(dom.firstChild);
}
}
fetchHints();