-
Notifications
You must be signed in to change notification settings - Fork 3
/
top.js
47 lines (40 loc) · 1.4 KB
/
top.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
function topjsonget(url, id)
{
var r = new XMLHttpRequest();
r.open("GET", url, true);
r.setRequestHeader("Content-type", "application/json")
r.onreadystatechange = function()
{
if (r.readyState == 4 && r.status == 200)
{
var tbl = JSON.parse(r.responseText);
if (id == "box") {
var s = "<table style=\"width: 80%;margin: 0 auto;\">";
s += "<tr><th width=\"5%\">Rank</th><th width=\"15%\">Number</th><th>Name</th><th>Builder</th></tr>\n";
for (i = 1; i <= 25; i++)
{
s += "<tr>";
s += "<td>" + i.toString() + "</td>";
s += "<td>" + tbl[i].split(/: /, 1)[0] + "</td>";
var ss = tbl[i].split(/: /, 2);
s += "<td>" + getbox(tbl[i].split(/: /, 1)[0], ss[1].split(/ by /, 1)[0].replace(/"/g, '')) + "</td>";
s += "<td>" + ss[1].split(/ by /, 2)[1] + "</td>";
s += "</tr>\n";
}
s += "</table>\n";
} else {
var s = "<table style=\"width: 80%;margin: 0 auto;\"><tr><th width=\"15%\">Rank</th><th>Name</th></tr>\n";
for (i = 1; i <= 25; i++)
{
s += "<tr><td>" + i.toString() + "</td><td>" + tbl[i] + "</td></tr>\n";
}
s += "</table>\n";
}
document.getElementById(id).innerHTML = s;
}
}
r.send();
}
topjsonget("https://minetest.foo-projects.org/top_players.json", "player");
topjsonget("https://minetest.foo-projects.org/top_boxes.json", "box");
topjsonget("https://minetest.foo-projects.org/top_builders.json", "builder");