-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
35 lines (31 loc) · 1.16 KB
/
script.js
File metadata and controls
35 lines (31 loc) · 1.16 KB
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
async function fetchServerStats() {
try {
const response = await fetch('https://api.battlemetrics.com/servers/26957610');
const data = await response.json();
updateStats(data.data.attributes);
} catch (error) {
console.error('Error fetching server stats:', error);
}
}
function updateStats(data) {
const maxPlayers = parseInt(data.maxPlayers);
const activePlayers = parseInt(data.players);
const progress = document.querySelector('.progress');
const progressBar = document.querySelector('.progress-grey');
document.getElementById('maxPlayers').textContent = maxPlayers;
document.getElementById('activePlayers').textContent = activePlayers;
document.getElementById('serverName').textContent = data.name;
const progressPercentage = (activePlayers / maxPlayers) * 100;
progress.style.width = progressPercentage + '%';
}
function copyToClipboard(element) {
var $temp = $("<input>");
$("body").append($temp);
$temp.val($(element).text()).select();
document.execCommand("copy");
$temp.remove();
}
window.onload = function() {
fetchServerStats();
setInterval(fetchServerStats, 60000);
};