Auto-reload server status every 15 sec

This commit is contained in:
Tyler Hallada 2017-11-30 17:01:07 -05:00
parent 66612c01ec
commit 6323a7d128

View File

@ -1,29 +1,37 @@
MinecraftAPI.getServerStatus('panic-shack.hallada.net', { function getStatus() {
port: 25565 MinecraftAPI.getServerStatus('panic-shack.hallada.net', {
}, function (err, status) { port: 25565
var serverError = document.getElementById('server-status-error'); }, function (err, status) {
var serverStatus = document.getElementById('server-status'); var serverError = document.getElementById('server-status-error');
var serverStatus = document.getElementById('server-status');
if (err) { if (err) {
serverError.style.color = 'red'; serverError.style.color = 'red';
return serverError.textContent = 'Error loading server status'; return serverError.textContent = 'Error loading server status';
} else { } else {
serverError.style.display = 'none'; serverError.style.display = 'none';
} }
serverStatus.style.display = 'block'; serverStatus.style.display = 'block';
if (status.online == true) { if (status.online == true) {
document.getElementById('status-online').style.display = 'inline-block'; document.getElementById('status-online').style.display = 'inline-block';
document.getElementById('status-offline').style.display = 'none'; document.getElementById('status-offline').style.display = 'none';
} }
document.getElementById('status-motd').textContent = status.motd; document.getElementById('status-motd').textContent = status.motd;
document.getElementById('status-players-now').textContent = status.players.now; document.getElementById('status-players-now').textContent = status.players.now;
document.getElementById('status-players-max').textContent = status.players.max; document.getElementById('status-players-max').textContent = status.players.max;
document.getElementById('status-server-name').textContent = status.server.name; document.getElementById('status-server-name').textContent = status.server.name;
document.getElementById('info-server-name').textContent = status.server.name; document.getElementById('info-server-name').textContent = status.server.name;
document.getElementById('status-server-protocol').textContent = status.server.protocol; document.getElementById('status-server-protocol').textContent = status.server.protocol;
document.getElementById('status-last-online').textContent = moment.unix(parseInt(status.last_online, 10)).fromNow(); document.getElementById('status-last-online').textContent = moment.unix(parseInt(status.last_online, 10)).fromNow();
document.getElementById('status-last-updated').textContent = moment.unix(parseInt(status.last_updated, 10)).fromNow(); document.getElementById('status-last-updated').textContent = moment.unix(parseInt(status.last_updated, 10)).fromNow();
}); });
}
getStatus();
setInterval(function () {
getStatus();
}, 15000);