-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleaderboard.js
39 lines (30 loc) · 951 Bytes
/
leaderboard.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
function config() {
document.getElementById('listings-li').classList.add("active");
var playersRef = firebase.database().ref('players')
playersRef.on('value',gotData, gotErr)
}
config();
function gotData(data) {
fillTable(data);
}
function gotErr(err) {
console.log('Error!')
console.log(err);
}
function fillTable(data) {
var playerArray = []
data.forEach(function(child) {
playerArray.push([child.val().name,child.val().rating]);
});
playerArray.sort(function(a ,b) {
return b[1] - a[1];
})
console.log(playerArray);
const tableBody = document.getElementById('tableBody');
let dataHtml = '';
for (let i = 0; i < playerArray.length; i++) {
var href = "profile.html?id=" + playerArray[i][0];
dataHtml += `<tr><td><a href="${href}">${i+1}</a></td><td><a href="${href}">${playerArray[i][0]}</a></td><td><a href="${href}">${playerArray[i][1]}</a></td></tr>`
}
tableBody.innerHTML = dataHtml;
}