|
69 | 69 | country = country.replace(/\s*\([^)]*\)\s*/g, "").trim(); |
70 | 70 | return { country: country, city: city }; |
71 | 71 | } |
72 | | - var sortedServers = SPEEDTEST_SERVERS.slice().sort(function (a, b) { |
73 | | - var pa = parseServerName(a.name); |
74 | | - var pb = parseServerName(b.name); |
| 72 | + var indexed = []; |
| 73 | + for (var j = 0; j < SPEEDTEST_SERVERS.length; j++) { |
| 74 | + indexed.push({ idx: j, server: SPEEDTEST_SERVERS[j] }); |
| 75 | + } |
| 76 | + indexed.sort(function (a, b) { |
| 77 | + var pa = parseServerName(a.server.name); |
| 78 | + var pb = parseServerName(b.server.name); |
75 | 79 | return pa.country.localeCompare(pb.country) || pa.city.localeCompare(pb.city); |
76 | 80 | }); |
77 | 81 | //populate server list for manual selection |
78 | | - for (var i = 0; i < sortedServers.length; i++) { |
79 | | - if (sortedServers[i].pingT == -1) continue; |
| 82 | + for (var i = 0; i < indexed.length; i++) { |
| 83 | + if (indexed[i].server.pingT == -1) continue; |
80 | 84 | var option = document.createElement("option"); |
81 | | - option.value = SPEEDTEST_SERVERS.indexOf(sortedServers[i]); |
82 | | - option.textContent = sortedServers[i].name; |
83 | | - if (sortedServers[i] === server) option.selected = true; |
| 85 | + option.value = indexed[i].idx; |
| 86 | + option.textContent = indexed[i].server.name; |
| 87 | + if (indexed[i].server === server) option.selected = true; |
84 | 88 | I("server").appendChild(option); |
85 | 89 | } |
86 | 90 | //show test UI |
|
0 commit comments