From fd2391e8f8aaf9e692a354684671da88a97d2bbf Mon Sep 17 00:00:00 2001 From: Maxim Baz Date: Wed, 20 Mar 2019 00:01:16 +0100 Subject: [PATCH] Include specificity in popup ordering algorithm (#47) --- src/popup/interface.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/popup/interface.js b/src/popup/interface.js index d1f1d9e..f3b8cbe 100644 --- a/src/popup/interface.js +++ b/src/popup/interface.js @@ -154,8 +154,8 @@ function search(s) { ); candidates = recent.concat(remainingInCurrentDomain); } - candidates.sort(function(a, b) { - // sort most recent first + candidates.sort((a, b) => { + // show most recent first if (a === mostRecent) { return -1; } @@ -163,12 +163,21 @@ function search(s) { return 1; } - // sort by count + // sort by frequency var countDiff = b.recent.count - a.recent.count; if (countDiff) { return countDiff; } + // sort by specificity, only if filtering for one domain + if (this.currentDomainOnly) { + var domainLevelsDiff = + (b.login.match(/\./g) || []).length - (a.login.match(/\./g) || []).length; + if (domainLevelsDiff) { + return domainLevelsDiff; + } + } + // sort alphabetically return a.login.localeCompare(b.login); });