mirror of
https://github.com/librespeed/speedtest.git
synced 2026-06-28 04:42:06 +00:00
feat: sort server list by country name instead of city name
Sort the server dropdown by country first, then by city within the same country. This makes it easier to find servers in a specific country when the list is long. Applies to both modern and classic UIs.
This commit is contained in:
parent
c11ee9f68a
commit
4ec3a755fa
2 changed files with 21 additions and 0 deletions
|
|
@ -230,6 +230,17 @@ function populateDropdown(servers) {
|
|||
});
|
||||
}
|
||||
|
||||
// Sort servers by country, then by city within the same country
|
||||
servers.sort((a, b) => {
|
||||
const commaA = a.name.lastIndexOf(",");
|
||||
const commaB = b.name.lastIndexOf(",");
|
||||
const countryA = commaA >= 0 ? a.name.substring(commaA + 1).trim() : a.name;
|
||||
const countryB = commaB >= 0 ? b.name.substring(commaB + 1).trim() : b.name;
|
||||
const cityA = commaA >= 0 ? a.name.substring(0, commaA).trim() : "";
|
||||
const cityB = commaB >= 0 ? b.name.substring(0, commaB).trim() : "";
|
||||
return countryA.localeCompare(countryB) || cityA.localeCompare(cityB);
|
||||
});
|
||||
|
||||
// Populate the list to choose from
|
||||
servers.forEach((server) => {
|
||||
const item = document.createElement("li");
|
||||
|
|
|
|||
|
|
@ -50,6 +50,16 @@
|
|||
s.selectServer(function (server) {
|
||||
if (server != null) { //at least 1 server is available
|
||||
I("loading").className = "hidden"; //hide loading message
|
||||
//sort servers by country, then by city
|
||||
SPEEDTEST_SERVERS.sort(function (a, b) {
|
||||
var commaA = a.name.lastIndexOf(",");
|
||||
var commaB = b.name.lastIndexOf(",");
|
||||
var countryA = commaA >= 0 ? a.name.substring(commaA + 1).trim() : a.name;
|
||||
var countryB = commaB >= 0 ? b.name.substring(commaB + 1).trim() : b.name;
|
||||
var cityA = commaA >= 0 ? a.name.substring(0, commaA).trim() : "";
|
||||
var cityB = commaB >= 0 ? b.name.substring(0, commaB).trim() : "";
|
||||
return countryA.localeCompare(countryB) || cityA.localeCompare(cityB);
|
||||
});
|
||||
//populate server list for manual selection
|
||||
for (var i = 0; i < SPEEDTEST_SERVERS.length; i++) {
|
||||
if (SPEEDTEST_SERVERS[i].pingT == -1) continue;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue