function htmlspecialchars(str){
if(str === null){
return "<Empty>";
}
var map = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''
}
return str.replace(/[&<>"']/g, function(m){return map[m];});
}
// initialize garbage
var list = [];
var pinged_list = [];
var reqs = 0;
var errors = 0;
var sort = 6; // highest version first
// check for instance redirect stuff
var redir = [];
var target = "/web?";
new URL(window.location.href)
.searchParams
.forEach(
function(value, key){
if(key == "target"){
target = "/" + encodeURIComponent(value) + "?";
return;
}
if(key == "npt"){ return; }
redir.push(encodeURIComponent(key) + "=" + encodeURIComponent(value))
}
);
if(redir.length !== 0){
redir = target + redir.join("&");
}else{
redir = "";
}
var quote = document.createElement("div");
quote.className = "quote";
quote.innerHTML = 'Pinged 0 servers (0 failed requests)';
var [div_servercount, div_failedreqs] =
quote.getElementsByTagName("b");
var noscript = document.getElementsByTagName("noscript")[0];
document.body.insertBefore(quote, noscript.nextSibling);
// create table
var table = document.createElement("table");
table.innerHTML =
'' +
'' +
'Server | ' +
'Address | ' +
'Bot protection | ' +
'Real reqs (?) | ' +
'Bot reqs (?) | ' +
'API | ' +
'Version | ' +
'
' +
'' +
'
';
document.body.insertBefore(table, quote.nextSibling);
// handle sorting clicks
var tbody = table.getElementsByTagName("tbody")[0];
var th = table.getElementsByTagName("th");
for(var i=0; i';
for(var i=0; i<7; i++){
html += '' + htmlspecialchars(sorted_list[k].server.name); break;
case 1: html += '>' + htmlspecialchars(new URL(sorted_list[k].server.ip).host); break;
case 2: // bot protection
switch(sorted_list[k].server.bot_protection){
case 0:
html += '>Disabled';
break;
case 1:
html += '>Image captcha';
break;
case 2:
html += '>Invite only';
break;
default:
html += '>Unknown';
}
break;
case 3: // real reqs
html += '>' + number_format(sorted_list[k].server.real_requests);
break;
case 4: // bot reqs
html += '>' + number_format(sorted_list[k].server.bot_requests);
break;
case 5: // api enabled
if(sorted_list[k].server.api_enabled){
html += '>Yes';
}else{
html += '>No';
}
break;
// version
case 6: html += ">v" + sorted_list[k].server.version; break;
}
html += ' | ';
}
html += '';
}
console.log(html);
tbody.innerHTML = html;
}
var popup_bg = document.getElementById("popup-bg");
var popup_wrapper = document.getElementsByClassName("popup-wrapper")[0];
var popup = popup_wrapper.getElementsByClassName("popup")[0];
var popup_shown = false;
popup_bg.addEventListener("click", function(){
popup_wrapper.style.display = "none";
popup_bg.style.display = "none";
});
function show_server(serverid){
var html =
'' + htmlspecialchars(pinged_list[serverid].server.name) + '
' +
'Description' +
'' + htmlspecialchars(pinged_list[serverid].server.description) + '
';
var url_obj = new URL(pinged_list[serverid].server.ip);
var url = htmlspecialchars(url_obj.origin);
var domain = url_obj.hostname;
html +=
'URL: ' + url + ' (IP lookup)' +
'
Alt addresses:';
var len = pinged_list[serverid].server.alt_addresses.length;
if(len === 0){
html += ' <Empty>';
}else{
html += '';
for(var i=0; i' + url + ' (IP lookup)';
}else{
console.warn(pinged_list[serverid].server.ip + ": Invalid peer URL => " + pinged_list[serverid].server.alt_addresses[i]);
}
}
html += '
';
}
popup.innerHTML = html;
popup_wrapper.style.display = "block";
popup_bg.style.display = "block";
}
function hide_server(){
popup_wrapper.style.display = "none";
popup_bg.style.display = "none";
}