From 3e8585d37ef0b750c9f2f5f3d5ef0d9073fc7e35 Mon Sep 17 00:00:00 2001 From: Vince Jerald Villamora <1276544+vincejv@users.noreply.github.com> Date: Sat, 25 Nov 2023 05:16:22 +0800 Subject: [PATCH] Use natural sort for categories --- private/scripts/client.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/private/scripts/client.js b/private/scripts/client.js index 8cd2fbc..ecb4bc5 100755 --- a/private/scripts/client.js +++ b/private/scripts/client.js @@ -488,7 +488,19 @@ window.addEvent('load', function() { Object.each(category_list, function(category) { sortedCategories.push(category.name); }); - sortedCategories.sort(); + sortedCategories.sort((leftCategory, rightCategory) => { + const leftSegments = leftCategory.split('/'); + const rightSegments = rightCategory.split('/'); + + for (let i = 0, iMax = Math.min(leftSegments.length, rightSegments.length); i < iMax; ++i) { + const compareResult = window.qBittorrent.Misc.naturalSortCollator.compare( + leftSegments[i], rightSegments[i]); + if (compareResult !== 0) + return compareResult; + } + + return leftSegments.length - rightSegments.length; + }); for (let i = 0; i < sortedCategories.length; ++i) { const categoryName = sortedCategories[i];