Skip to content

Commit fdb1681

Browse files
author
Stefan Stidl
committed
Use server-list.json in classic frontend by default
1 parent debd40b commit fdb1681

1 file changed

Lines changed: 47 additions & 41 deletions

File tree

index-classic.html

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -36,52 +36,58 @@
3636

3737
//SERVER AUTO SELECTION
3838
function initServers() {
39-
if (SPEEDTEST_SERVERS.length == 0) { //standalone installation
40-
//just make the UI visible
39+
var showStandaloneUI = function () {
4140
I("loading").className = "hidden";
4241
I("serverArea").style.display = "none";
4342
I("testWrapper").className = "visible";
4443
initUI();
45-
} else { //multiple servers
46-
var noServersAvailable = function () {
47-
I("message").innerHTML = "No servers available";
48-
}
49-
var runServerSelect = function () {
50-
s.selectServer(function (server) {
51-
if (server != null) { //at least 1 server is available
52-
I("loading").className = "hidden"; //hide loading message
53-
//populate server list for manual selection
54-
for (var i = 0; i < SPEEDTEST_SERVERS.length; i++) {
55-
if (SPEEDTEST_SERVERS[i].pingT == -1) continue;
56-
var option = document.createElement("option");
57-
option.value = i;
58-
option.textContent = SPEEDTEST_SERVERS[i].name;
59-
if (SPEEDTEST_SERVERS[i] === server) option.selected = true;
60-
I("server").appendChild(option);
61-
}
62-
//show test UI
63-
I("testWrapper").className = "visible";
64-
initUI();
65-
} else { //no servers are available, the test cannot proceed
66-
noServersAvailable();
67-
}
68-
});
69-
}
70-
if (typeof SPEEDTEST_SERVERS === "string") {
71-
//need to fetch list of servers from specified URL
72-
s.loadServerList(SPEEDTEST_SERVERS, function (servers) {
73-
if (servers == null) { //failed to load server list
74-
noServersAvailable();
75-
} else { //server list loaded
76-
SPEEDTEST_SERVERS = servers;
77-
runServerSelect();
44+
}
45+
var noServersAvailable = function () {
46+
I("message").innerHTML = "No servers available";
47+
}
48+
var runServerSelect = function () {
49+
s.selectServer(function (server) {
50+
if (server != null) { //at least 1 server is available
51+
I("loading").className = "hidden"; //hide loading message
52+
//populate server list for manual selection
53+
for (var i = 0; i < SPEEDTEST_SERVERS.length; i++) {
54+
if (SPEEDTEST_SERVERS[i].pingT == -1) continue;
55+
var option = document.createElement("option");
56+
option.value = i;
57+
option.textContent = SPEEDTEST_SERVERS[i].name;
58+
if (SPEEDTEST_SERVERS[i] === server) option.selected = true;
59+
I("server").appendChild(option);
7860
}
79-
});
80-
} else {
81-
//hardcoded server list
82-
s.addTestPoints(SPEEDTEST_SERVERS);
83-
runServerSelect();
84-
}
61+
//show test UI
62+
I("testWrapper").className = "visible";
63+
initUI();
64+
} else { //no servers are available, the test cannot proceed
65+
noServersAvailable();
66+
}
67+
});
68+
}
69+
var loadServerList = function (serverListUrl, onFailure) {
70+
s.loadServerList(serverListUrl, function (servers) {
71+
if (servers == null || servers.length == 0) {
72+
onFailure();
73+
} else {
74+
SPEEDTEST_SERVERS = servers;
75+
s.addTestPoints(SPEEDTEST_SERVERS);
76+
runServerSelect();
77+
}
78+
});
79+
}
80+
81+
if (typeof SPEEDTEST_SERVERS === "string") {
82+
//need to fetch list of servers from specified URL
83+
loadServerList(SPEEDTEST_SERVERS, noServersAvailable);
84+
} else if (SPEEDTEST_SERVERS.length == 0) {
85+
//standalone installation by default, but use server-list.json if present
86+
loadServerList("server-list.json", showStandaloneUI);
87+
} else { //multiple servers
88+
//hardcoded server list
89+
s.addTestPoints(SPEEDTEST_SERVERS);
90+
runServerSelect();
8591
}
8692
}
8793

0 commit comments

Comments
 (0)