diff --git a/popup/search-results.js b/popup/search-results.js index 590a2337..f596553e 100755 --- a/popup/search-results.js +++ b/popup/search-results.js @@ -54,7 +54,7 @@ window.addEventListener('showStyles:done', () => { href: URLS.usoArchive, onclick(event) { if (!prefs.get('popup.findStylesInline') || dom.container) { - this.search = `${new URLSearchParams({category, search: $('#search-query').value})}`; + this.search = new URLSearchParams({category, search: $('#search-query').value}); handleEvent.openURLandHide.call(this, event); return; } @@ -83,6 +83,9 @@ window.addEventListener('showStyles:done', () => { const n = Number(m[2]); query.push(n >= 2000 && n <= thisYear ? n : m[1] || m[2]); } + if (category === STYLUS_CATEGORY && !query.includes('stylus')) { + query.push('stylus'); + } ready = ready.then(start); }; $('#search-order').value = order; @@ -464,13 +467,18 @@ window.addEventListener('showStyles:done', () => { } function isResultMatching(res) { + // We're trying to call calcHaystack only when needed, not on all 100K items + const {c} = res; return ( - res.c === category || - searchGlobals && res.c === 'global' && (query.length || calcHaystack(res)._nLC.includes(category)) + c === category || + category !== STYLUS_CATEGORY && ( + searchGlobals && + c === 'global' && + (query.length || calcHaystack(res)._nLC.includes(category)) + ) ) && ( - category === STYLUS_CATEGORY - ? /\bStylus\b/.test(res.n) - : !query.length || query.every(isInHaystack, calcHaystack(res)) + !query.length || // to skip calling calcHaystack + query.every(isInHaystack, calcHaystack(res)) ); }