2013-10-17 23:32:49 +02:00
|
|
|
var master;
|
2013-11-04 09:59:55 +01:00
|
|
|
if (!master) master = {};
|
|
|
|
if (typeof(master.root)=='undefined') master.root = "http://servers.minetest.net/";
|
|
|
|
if (!master.output) master.output = '#server_list';
|
|
|
|
if (!master.list) master.list = "list";
|
|
|
|
if (!master.list_root) master.list_root = master.root;
|
|
|
|
if (!master.list_url) master.list_url = master.list_root + master.list;
|
2013-11-02 23:53:51 +01:00
|
|
|
|
|
|
|
function humanTime(seconds) {
|
|
|
|
if (!seconds) return '?';
|
|
|
|
var conv = {
|
|
|
|
y: 31536000,
|
|
|
|
d: 86400,
|
|
|
|
h: 3600,
|
|
|
|
m: 60
|
|
|
|
}
|
|
|
|
for (var i in conv) {
|
|
|
|
if (seconds >= conv[i]) {
|
|
|
|
return (seconds / conv[i]).toFixed(1) + i;
|
|
|
|
}
|
|
|
|
}
|
2013-11-05 18:17:33 +01:00
|
|
|
return seconds + 's';
|
2013-11-02 23:53:51 +01:00
|
|
|
}
|
2013-04-11 18:18:34 +02:00
|
|
|
|
2013-11-02 23:53:51 +01:00
|
|
|
function escapeHTML(str) {
|
|
|
|
return str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
2013-02-21 23:00:44 +01:00
|
|
|
}
|
2013-03-29 23:03:24 +01:00
|
|
|
|
2013-11-02 23:53:51 +01:00
|
|
|
function addressString(server) {
|
|
|
|
var isIPv6 = server.address.indexOf(":") != -1;
|
|
|
|
var addrStr = (isIPv6 ? '[' : '') +
|
|
|
|
escapeHTML(server.address) +
|
|
|
|
(isIPv6 ? ']' : '');
|
|
|
|
var shortStr = addrStr;
|
|
|
|
addrStr += ':' + server.port;
|
|
|
|
var str = '<span'
|
|
|
|
if (shortStr.length > 25) {
|
|
|
|
shortStr = shortStr.substr(0, 23) + "…";
|
2013-11-04 01:55:35 +01:00
|
|
|
str += ' class="mts_tooltip" title="' + addrStr + '"'
|
2013-11-02 23:53:51 +01:00
|
|
|
}
|
|
|
|
if (server.port != 30000)
|
|
|
|
shortStr += ':' + server.port;
|
|
|
|
return str + '>' + shortStr + '</span>';
|
2013-02-21 23:00:44 +01:00
|
|
|
}
|
2013-03-29 23:03:24 +01:00
|
|
|
|
2013-11-02 23:53:51 +01:00
|
|
|
function tooltipString(str, maxLen) {
|
|
|
|
str = escapeHTML(str);
|
|
|
|
var shortStr = str;
|
|
|
|
var ret = '<span';
|
|
|
|
if (shortStr.length > maxLen) {
|
|
|
|
shortStr = shortStr.substr(0, maxLen - 2) + "…";
|
2013-11-04 01:55:35 +01:00
|
|
|
ret += ' class="mts_tooltip" title="' + str + '"';
|
2013-11-02 23:53:51 +01:00
|
|
|
}
|
|
|
|
return ret + '>' + shortStr + '</span>';
|
2013-02-21 23:00:44 +01:00
|
|
|
}
|
2013-03-29 23:03:24 +01:00
|
|
|
|
2013-11-02 23:53:51 +01:00
|
|
|
function hoverList(name, list) {
|
|
|
|
if (!list || list.length == 0) return '';
|
2013-11-04 01:55:35 +01:00
|
|
|
var str = '<div class="mts_hover_list">'
|
2013-11-02 23:53:51 +01:00
|
|
|
str += name + '(' + list.length + ')<br />';
|
|
|
|
for (var i in list) {
|
|
|
|
str += escapeHTML(list[i]) + '<br />';
|
|
|
|
}
|
|
|
|
return str + '</div>';
|
2013-02-21 23:00:44 +01:00
|
|
|
}
|
2013-11-02 23:53:51 +01:00
|
|
|
|
2013-11-04 09:59:55 +01:00
|
|
|
function hoverString(name, string) {
|
|
|
|
if (!string) return '';
|
|
|
|
return '<div class="mts_hover_list">'
|
|
|
|
+ name + ':<br />'
|
|
|
|
+ escapeHTML(string) + '<br />'
|
|
|
|
+ '</div>';
|
|
|
|
}
|
|
|
|
|
2013-11-02 23:53:51 +01:00
|
|
|
function draw(json) {
|
|
|
|
html = window.render.servers(json);
|
2013-11-04 09:59:55 +01:00
|
|
|
jQuery(master.output).html(html);
|
2013-11-02 23:53:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function get() {
|
2013-11-04 09:59:55 +01:00
|
|
|
jQuery.getJSON(master.list_url, draw);
|
2013-11-02 23:53:51 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 01:55:35 +01:00
|
|
|
function loaded(){
|
|
|
|
if (!master.no_refresh) {
|
|
|
|
setInterval(get, 60 * 1000);
|
|
|
|
}
|
|
|
|
get();
|
2013-11-02 23:53:51 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 01:55:35 +01:00
|
|
|
// https://github.com/pyrsmk/toast
|
|
|
|
this.toast=function(){var e=document,t=e.getElementsByTagName("head")[0],n=this.setTimeout,r="createElement",i="appendChild",s="addEventListener",o="onreadystatechange",u="styleSheet",a=10,f=0,l=function(){--f},c,h=function(e,r,i,s){if(!t)n(function(){h(e)},a);else if(e.length){c=-1;while(i=e[++c]){if((s=typeof i)=="function"){r=function(){return i(),!0};break}if(s=="string")p(i);else if(i.pop){p(i[0]),r=i[1];break}}d(r,Array.prototype.slice.call(e,c+1))}},p=function(n,s){++f,/\.css$/.test(n)?(s=e[r]("link"),s.rel=u,s.href=n,t[i](s),v(s)):(s=e[r]("script"),s.src=n,t[i](s),s[o]===null?s[o]=m:s.onload=l)},d=function(e,t){if(!f)if(!e||e()){h(t);return}n(function(){d(e,t)},a)},v=function(e){if(e.sheet||e[u]){l();return}n(function(){v(e)},a)},m=function(){/ded|co/.test(this.readyState)&&l()};h(arguments)};
|
2013-11-02 23:53:51 +01:00
|
|
|
|
2013-11-04 09:59:55 +01:00
|
|
|
toast(master.root+'style.css', master.root+'servers.js', function() {
|
2013-11-04 01:55:35 +01:00
|
|
|
if (typeof(jQuery)!='undefined')
|
|
|
|
loaded();
|
|
|
|
else
|
|
|
|
toast('//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js', loaded);
|
|
|
|
});
|