From 4ec3a755fae94f818bdc5edcc81e9bfba9790dc7 Mon Sep 17 00:00:00 2001 From: valer23 Date: Fri, 17 Apr 2026 10:28:38 +0200 Subject: [PATCH] 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. --- frontend/javascript/index.js | 11 +++++++++++ index-classic.html | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/frontend/javascript/index.js b/frontend/javascript/index.js index ba4eb0e..146ae3d 100644 --- a/frontend/javascript/index.js +++ b/frontend/javascript/index.js @@ -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"); diff --git a/index-classic.html b/index-classic.html index 19bf2e2..7b55926 100644 --- a/index-classic.html +++ b/index-classic.html @@ -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;