forked from GameChaos/gckzstats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaptop.html
152 lines (131 loc) · 3.95 KB
/
maptop.html
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
<!doctype html>
<head>
<title>GCKZStats - Maptop</title>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script src="js/helpers.js"></script>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<!-- TODO: make this stuff into a function so it isn't repeated all over the place or something -->
<select onchange="OnTPRunDropdownChanged()" id="tpRun-dropdown" name="TP/Pro">
<option value="false">Pro</option>
<option value="true">TP</option>
</select>
<select onchange="OnModeDropdownChanged()" id="mode-dropdown" name="Mode">
<option value="kz_timer">KZTimer</option>
<option value="kz_simple">SimpleKZ</option>
<option value="kz_vanilla">Vanilla</option>
</select>
<div id="map-info">
<h1 id="map-name">---</h1>
<nobr><b>Pro WR: </b><span id="pro-wr-info">00:00:00 by Unknown Player</span></nobr>
<br>
<nobr><b>TP WR: </b><span id="tp-wr-info">00:00:00 by Unknown Player</span></nobr>
</div>
<br>
<div style="padding:0px 1% 0px 1%; float: left">
<table id="leaderboard" style="width:75%;">
<tr>
<th>Place</th>
<th>Name</th>
<th>Run time</th>
<th>Teleports</th>
<th>Date</th>
<th>Server</th>
</tr>
</table>
</div>
</body>
<script>
g_MapName = ""
function OnTPRunDropdownChanged()
{
UpdateMaptop(g_MapName, 0)
}
function OnModeDropdownChanged()
{
UpdateMaptop(g_MapName, 0)
}
function UpdateMaptop(mapName, stage)
{
RemoveAllChildrenFromNode(document.getElementById("leaderboard"))
$('#leaderboard').append('\
<tr>\
<th>Place</th>\
<th>Name</th>\
<th>Run time</th>\
<th>Teleports</th>\
<th>Date</th>\
<th>Server</th>\
</tr>')
$.getJSON("https://kztimerglobal.com/api/v1.0/records/top?map_name="
+ mapName + "&tickrate=128&stage=" + stage + "&modes_list=" + GetRunMode() + "&has_teleports=" + GetRunType() + "&limit=100", function (data)
{
if (data.length == 0)
{
return
}
// if run is tp ((lol))
if (GetRunType() == "true")
{
RemoveAllChildrenFromNode(document.getElementById("tp-wr-info"))
$('#tp-wr-info').text(data[0].time + ' by ' + data[0].player_name)
}
else
{
RemoveAllChildrenFromNode(document.getElementById("pro-wr-info"))
$('#pro-wr-info').text(data[0].time + ' by ' + data[0].player_name)
}
$.each(data, function (index, value)
{
$('#leaderboard').append('\
<tr>\
<td>' + (index + 1) + '</td>\
<td>' + CreatePlayerProfileLink(data[index].steam_id, data[index].player_name) + '</td>\
<td>' + FormatTime(data[index].time) + '</td>\
<td>' + data[index].teleports + '</td>\
<td>' + new Date(data[index].created_on).toLocaleDateString("en-GB", g_DateOptions) + '</td>\
<td>' + data[index].server_name + '</td>\
</tr>')
})
})
// need to do a second api call for other run type wr (tp/pro)
$.getJSON("https://kztimerglobal.com/api/v1.0/records/top?map_name="
+ mapName + "&tickrate=128&stage=" + stage + "&modes_list=" + GetRunMode() + "&has_teleports=" + (GetRunType() == "true" ? "false" : "true") + "&limit=100", function (data)
{
if (GetRunType() == "true")
{
// if the run type we originally wanted is tp, then update pro wr info
RemoveAllChildrenFromNode(document.getElementById("pro-wr-info"))
$('#pro-wr-info').text(data[0].time + ' by ' + CreatePlayerProfileLink(data[index].steam_id, data[0].player_name))
}
else
{
RemoveAllChildrenFromNode(document.getElementById("tp-wr-info"))
$('#tp-wr-info').text(data[0].time + ' by ' + CreatePlayerProfileLink(data[index].steam_id, data[0].player_name))
}
})
}
function OnPageOpened()
{
let params = GetParams(window.location.href)
for (let key in params)
{
if (key == "mapname")
{
g_MapName = params[key]
break
}
}
$('#map-name').text(g_MapName)
if ((typeof g_MapName) !== "string")
{
// TODO: maybe fall back on some other map or something else idk.
g_MapName = kz_beginnerblock_go
}
UpdateMaptop(g_MapName, 0)
}
OnPageOpened()
</script>
</html>