-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminepress.js
52 lines (47 loc) · 1.21 KB
/
minepress.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
40
41
42
43
44
45
46
47
48
49
50
51
52
jQuery(function () {
jQuery('.minepress').each(function (index, element) {
var host, now;
element = jQuery(element);
host = element.attr('data-minepress-host');
update('host', {host: host});
refresh();
function refresh() {
now = +new Date;
jQuery.ajax(element.attr('data-minepress-url') + 'query.php', {
data : {host: host},
success : function (data) {
update('load', data);
update('max-players', data);
update('motd', data);
update('ping', (data && data.up) ? ((+new Date - now) + ' ms') : 'down');
update('players', data);
update('ram', data);
update('uptime', data);
},
error : function () {
update('load');
update('max-players');
update('motd');
update('ping', 'down');
update('players');
update('ram');
update('uptime');
},
complete : function () {
setTimeout(refresh, 5000);
}
});
}
function update(key, data) {
var value;
if (data && typeof data === 'object' && key in data) {
value = data[key];
} else if (typeof data === 'string' || typeof data === 'number') {
value = data;
} else {
value = '';
}
element.find('.minepress-' + key).text(value);
}
});
});