-
Notifications
You must be signed in to change notification settings - Fork 0
/
leaderboard.html
218 lines (218 loc) · 8.99 KB
/
leaderboard.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
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<!DOCTYPE html>
<html>
<head>
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
<link rel="stylesheet" type="text/css" href="/theme.css" />
<script src="/background.js"></script>
<link rel="stylesheet" type="text/css" href="/table.css" />
<link rel="stylesheet" type="text/css" href="/badges.css" />
<link rel="stylesheet" type="text/css" href="/tooltip.css" />
<style>
.bar {
font-size: 0.7em;
margin-left: 1em;
display: inline-block;
font-family: sans-serif;
background: #03fccf;
border-radius: 1em;
padding: 0 0.5em;
position: relative;
overflow: hidden;
color: black;
text-decoration: none;
}
.bar::before {
content: "";
display: inline-block;
position: absolute;
top: 0;
left: 0;
background: #0005;
width: calc(var(--amount) * 100%);
height: 100%;
}
.admin-buttons {
display: none;
}
</style>
</head>
<body>
<div class="tabs"></div>
<h1 class="no-outline"><span class="outline">Leaderboard for <b>{{NAME}}</b></span> <span class="tooltip" style="--tooltip-text: 'Entries marked with a T are tied. The rank shown is the maximum rank of all the tied entries.';" tabindex="0"></span></h1>
<p><button onclick="scrollToEntry()">Scroll</button> to place value: <input type="number" id="e" min="1" value="1"></p>
<p>Time range: <select oninput="filter(Number(this.value))">
<option value="10000">All time</option>
<option value="365">Yearly</option>
<option value="30">Monthly</option>
<option value="7">Weekly</option>
<option value="1">Daily</option>
</select></p>
<p class="admin-buttons">
<button>Remove Leaderboard</button>
</p>
<p id="desc"></p>
<table>
<tr>
<th>Rank</th>
<th>Name</th>
<th id="score_head">Score</th>
<th id="badge_head">Badges</th>
<th>Note</th>
</tr>
</table>
<h2>Badges for {{NAME}}</h2>
<div id="badges"></div>
<script src="/data.js"></script>
<script src="/tabs.js"></script>
<script>
tabs.extra(2, "Leaderboard for {{NAME}}");
getData().then((info) => { try {
tabs.userfix(info.profile);
// Admin buttons header
if (info.profile.length == 1 && info.profile[0].admin) {
var th = document.createElement("th")
th.innerText = "Admin Buttons"
document.querySelector("table").children[0].children[0].appendChild(th)
}
// Get description
var leaderboard_desc = info.data["{{NAME}}"].leaderboard_desc
document.querySelector("#desc").innerText = `${leaderboard_desc}`
// Find ranks
var ranks = info.getLeaderboardRanks("{{NAME}}")
var is_specialty = info.data["{{NAME}}"].badges.length == 0
if (is_specialty) {
document.querySelector("#badge_head").remove()
}
if (info.data["{{NAME}}"].isTime) document.querySelector("#score_head").innerText = "Time"
var i = 0;
for (; i < ranks.length; i++) {
// Get real score + duplicates
var duplicates = info.getDuplicates("{{NAME}}", info.getScore(ranks[i], "{{NAME}}"))
var pcscore = i + 0
for (var n = i - 1; n >= 0; n--) {
if (duplicates.includes(ranks[n])) {
pcscore -= 1
}
}
// Create element
var e = document.createElement("tr")
e._EntryTime = info.getTimeForEntry(ranks[i], "{{NAME}}")
// 1st column: Place value
e.appendChild(document.createElement("td"))
e.children[0].appendChild(document.createElement("span"))
e.children[0].children[0].classList.add("outline")
e.children[0].children[0].setAttribute("style", `color: ${getColor(pcscore)}; opacity: 0.7;${pcscore >= 3 ? " font-size: 0.8em;" : ""}`)
e.children[0].children[0].innerHTML = (duplicates.length > 1 ? "<i>T</i> " : "") + String(pcscore + 1) + getSuffix(pcscore + 1)
// Progress bar: Distance to next place value
if (pcscore > 0) {
if (! info.data["{{NAME}}"].reverseOrder) {
var bar = document.createElement("a")
bar.classList.add("bar")
bar.innerText = String(pcscore) + getSuffix(pcscore)
var nextValue = info.getScore(ranks[pcscore - 1], "{{NAME}}")
var thisValue = info.getScore(ranks[pcscore], "{{NAME}}")
var prevValue = info.getScore(ranks[pcscore + 1], "{{NAME}}")
if (prevValue == undefined) prevValue = 0
bar.setAttribute("style", `--amount: ${(thisValue - prevValue) / (nextValue - prevValue)}; background: ${getColor(pcscore - 1)};`);
// bar.innerText += `, ${prevValue}, ${thisValue}, ${nextValue}`
e.children[0].appendChild(bar)
} else if (pcscore != ranks.length - 1) {
var bar = document.createElement("a")
bar.classList.add("bar")
bar.innerText = String(pcscore) + getSuffix(pcscore)
var nextValue = -info.getScore(ranks[pcscore - 1], "{{NAME}}")
var thisValue = -info.getScore(ranks[pcscore], "{{NAME}}")
var prevValue = -info.getScore(ranks[pcscore + 1], "{{NAME}}")
if (prevValue == undefined) prevValue = 0
bar.setAttribute("style", `--amount: ${(thisValue - prevValue) / (nextValue - prevValue)}; background: ${getColor(pcscore - 1)};`);
// bar.innerText += `, ${prevValue}, ${thisValue}, ${nextValue}`
e.children[0].appendChild(bar)
}
}
// 2nd column: User name
e.appendChild(document.createElement("td"))
e.children[1].appendChild(document.createElement("a"))
e.children[1].children[0].href = "/profile/" + ranks[i] + location.search
e.children[1].children[0].setAttribute("style", "color: rgb(0, 0, 200);")
e.children[1].children[0].innerText = ranks[i]
// 3rd column: Score
e.appendChild(document.createElement("td"))
e.children[2].classList.add("outline")
e.children[2].setAttribute("style", `color: ${getColor(pcscore)}; opacity: 0.7;${pcscore >= 3 ? " font-size: 0.8em;" : ""}`)
var score = info.getScore(ranks[i], "{{NAME}}")
if (info.data["{{NAME}}"].isTime) {
e.children[2].innerText = formatTime(score)
} else {
e.children[2].innerText = addCommas(score)
}
// 4th column: Badges
if (!is_specialty) {
e.appendChild(document.createElement("td"))
// Badges
var badgeno = info.getBadgeCount(ranks[i], "{{NAME}}")
for (var x = 0; x < badgeno; x++) {
e.children[3].innerHTML += `<a href="/badges/{{NAME}}/${x}${location.search}"><div class="badge badge-${['bronze', 'bronze', 'bronze', 'silver', 'silver', 'gold', 'gold', 'platinum'][x]}">${'NVAPREMU'[x]}</div></a>`
}
// Progress bar: Distance to next badge
if (badgeno < 8) {
var bar = document.createElement("a")
bar.setAttribute("href", `/badges/{{NAME}}/${badgeno}${location.search}`)
bar.classList.add("bar")
bar.innerText = ["Novice", "Vassal", "Apprentice", "Prospect", "Artisan", "Expert", "Master", "Ultimate Master"][badgeno]
var nextValue = info.data["{{NAME}}"].badges[badgeno]
var prevValue = [0, ...info.data["{{NAME}}"].badges][badgeno]
bar.setAttribute("style", `--amount: ${(score - prevValue) / (nextValue - prevValue)};`);
e.children[3].appendChild(bar)
}
}
// 5th column: Description
var newE = document.createElement("td")
newE.innerText = info.getDesc(ranks[i], "{{NAME}}")
e.appendChild(newE)
// 6th column (if needed): Admin buttons
if (info.profile.length == 1 && info.profile[0].admin) {
var admin = document.createElement("td")
admin.innerHTML = `<button>Remove entry</button>`;
((name) => admin.children[0].addEventListener("click", () => {
// funny thing: alert(name)
var x = new XMLHttpRequest()
x.open("POST", "/remove_entry")
x.addEventListener("loadend", () => location.reload())
x.send(location.search.substr(1) + "\n{{NAME}}\n" + name)
}))(ranks[i]);
e.appendChild(admin)
}
// Add the row to the table
document.querySelector("table tbody").appendChild(e)
}
if (!is_specialty) {
var e = document.querySelector("#badges") // NVAPREMU
e.innerHTML += `<a href="/badges/{{NAME}}/0${location.search}"><div class="badge badge-bronze">N</div></a>`
e.innerHTML += `<a href="/badges/{{NAME}}/1${location.search}"><div class="badge badge-bronze">V</div></a>`
e.innerHTML += `<a href="/badges/{{NAME}}/2${location.search}"><div class="badge badge-bronze">A</div></a>`
e.innerHTML += `<a href="/badges/{{NAME}}/3${location.search}"><div class="badge badge-silver">P</div></a>`
e.innerHTML += `<a href="/badges/{{NAME}}/4${location.search}"><div class="badge badge-silver">R</div></a>`
e.innerHTML += `<a href="/badges/{{NAME}}/5${location.search}"><div class="badge badge-gold">E</div></a>`
e.innerHTML += `<a href="/badges/{{NAME}}/6${location.search}"><div class="badge badge-gold">M</div></a>`
e.innerHTML += `<a href="/badges/{{NAME}}/7${location.search}"><div class="badge badge-platinum">U</div></a>`
} else {
document.querySelectorAll("#badges, :has( + #badges)").forEach((e) => e.remove())
}
document.querySelector("#e").setAttribute("max", i)
}catch(e){alert(e)}
})
function filter(days) {
var rows = [...document.querySelectorAll("table tbody tr:not(:first-child)")]
var targetDate = new Date()
targetDate.setDate(targetDate.getDate() - days)
for (var i = 0; i < rows.length; i++) {
if (rows[i]._EntryTime.getTime() < targetDate.getTime()) {
rows[i].setAttribute("style", `display: none;`)
} else rows[i].removeAttribute("style")
}
}
</script>
<script src="https://matterjstest.jasonroman.repl.co/matter.js"></script>
<script src="/matter2.js"></script>
</body>
</html>