-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadmin.html
98 lines (86 loc) · 3.99 KB
/
admin.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Admin Panel - Flag Scoreboard</title>
<!-- Ensure your style.css is properly linked here -->
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="adminControls" style="display: flex;">
<button onclick="resetScoreboard()">Reset Scoreboard</button>
</div>
<div id="allUsersScoreboard">
<!-- The all users scoreboard will be updated here -->
</div>
<script>
// Function to reset the scoreboard with a password
function resetScoreboard() {
const password = prompt('Enter the password (hint: whooopsi):');
if (password === 'WSpass') {
fetch('https://dry-scrubland-90422-a1e12a27055a.herokuapp.com/reset', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
// If your server requires authentication, add your auth headers here
},
})
.then(response => {
if (!response.ok) {
// The server response was not ok. Log and throw an error.
response.text().then(text => console.error('Response error:', text));
throw new Error('Scoreboard reset failed: ' + response.statusText);
}
return response.text();
})
.then(message => {
alert(message);
updateAllUsersScoreboard(); // Refresh the scoreboard on the page
})
.catch((error) => {
console.error('Error during reset:', error);
alert('An error occurred. Please check the console for more details.');
});
} else {
alert('Incorrect password. Reset operation canceled.');
}
}
// Function to update the scoreboard by fetching scores from the backend
function updateAllUsersScoreboard() {
fetch('https://dry-scrubland-90422-a1e12a27055a.herokuapp.com/scores', {
headers: {
'Content-Type': 'application/json'
// If your server requires authentication, add your auth headers here
},
})
.then(response => response.json())
.then(scores => {
const scoreboardElement = document.getElementById('allUsersScoreboard');
let scoreboardHTML = '<h2>All Users Scoreboard</h2>';
// Convert the scores object to an array and sort by score descending
const sortedScores = Object.keys(scores).map(username => ({
username,
score: scores[username]
})).sort((a, b) => b.score - a.score);
// Add a special emoji for the top three scores
sortedScores.forEach((user, index) => {
let medal = '';
if (index === 0) { // First place
medal = '🥇 ';
} else if (index === 1) { // Second place
medal = '🥈 ';
} else if (index === 2) { // Third place
medal = '🥉 ';
}
scoreboardHTML += `<div>${medal}${user.username}: ${user.score} points</div>`;
});
scoreboardElement.innerHTML = scoreboardHTML;
})
.catch((error) => {
console.error('Error fetching scores:', error);
});
}
document.addEventListener('DOMContentLoaded', updateAllUsersScoreboard);
</script>
</body>
</html>