diff --git a/.vscode/settings.json b/.vscode/settings.json index 2a30943..a1e07be 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,6 +8,7 @@ "fuzzysort", "Heimler", "idxs", + "iife", "jsyaml", "leeoniya", "malus", @@ -33,4 +34,4 @@ "source.fixAll.eslint": "explicit" }, "eslint.experimental.useFlatConfig": true -} \ No newline at end of file +} diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a19a53..2a778dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,11 @@ ## [unreleased] -- **IMPROVED**: Performance of CSS initial load +- **IMPROVED**: Performance of initial load - Cleaned up and simplified CSS - Lazy load CSS necessary for bookmark tagging and options view + - Lazy load uFuzzy library only when fuzzy search is used +- **CHANGED**: Initial load now only looks for bookmarks matching the current URL, not starting with it ## [v1.10.3] diff --git a/popup/index.html b/popup/index.html index c128305..6a6f305 100644 --- a/popup/index.html +++ b/popup/index.html @@ -5,7 +5,6 @@ - @@ -61,7 +60,6 @@ - diff --git a/popup/js/initSearch.js b/popup/js/initSearch.js index 3589db5..f725bae 100644 --- a/popup/js/initSearch.js +++ b/popup/js/initSearch.js @@ -47,10 +47,6 @@ export async function initExtension() { updateSearchApproachToggle() - if (ext.opts.debug) { - performance.mark('init-dom') - } - const { bookmarks, tabs, history } = await getSearchData() ext.model.tabs = tabs ext.model.bookmarks = bookmarks diff --git a/popup/js/search/defaultEntries.js b/popup/js/search/defaultEntries.js index 69f76ed..93ec05d 100644 --- a/popup/js/search/defaultEntries.js +++ b/popup/js/search/defaultEntries.js @@ -37,26 +37,18 @@ export async function addDefaultEntries() { } }) } else { - // All other modes: Find bookmark / history that matches current page URL + // All other modes: Find bookmarks / history that matches current page URL let currentUrl = window.location.href const [tab] = await getBrowserTabs({ active: true, currentWindow: true }) - - // If we find no open tab, we're most likely not having a browser API. Return nothing. if (!tab) { return [] } - currentUrl = tab.url - // Remove trailing slash from URL, so the startsWith search works better - currentUrl = currentUrl.replace(/\/$/, '') - - // Find if current URL has corresponding bookmark(s) - const foundBookmarks = ext.model.bookmarks.filter((el) => el.originalUrl.startsWith(currentUrl)) - results.push(...foundBookmarks) + // Remove trailing slash or hash from URL, so the comparison works better + currentUrl = tab.url.replace(/[/#]$/, '') - // Find if we have browser history that has the same URL - let foundHistory = ext.model.history.filter((el) => currentUrl === el.originalUrl) - results.push(...foundHistory) + results.push(...ext.model.bookmarks.filter((el) => el.originalUrl === currentUrl)) + results.push(...ext.model.history.filter((el) => el.originalUrl === currentUrl)) } ext.model.result = results diff --git a/popup/js/search/fuzzySearch.js b/popup/js/search/fuzzySearch.js index c86c7c8..2a4d186 100644 --- a/popup/js/search/fuzzySearch.js +++ b/popup/js/search/fuzzySearch.js @@ -2,17 +2,14 @@ // FUZZY SEARCH SUPPORT // ////////////////////////////////////////// -import { printError } from '../helper/utils.js' +import { loadScript, printError } from '../helper/utils.js' -/** - * Memoize some state, to avoid re-creating haystack and fuzzy search instances - */ +/** Memoize some state, to avoid re-creating haystack and fuzzy search instances */ let state = {} /** * Resets state for fuzzy search. Necessary when search data changes or search string is reset. * If searchMode is given, will only reset that particular state. - * Otherwise state will be reset entirely. */ export function resetFuzzySearchState(searchMode) { if (searchMode) { @@ -20,12 +17,16 @@ export function resetFuzzySearchState(searchMode) { } } -/** - * Uses uFuzzy to do a fuzzy search - * - * @see https://github.com/leeoniya/uFuzzy - */ export async function fuzzySearch(searchMode, searchTerm) { + // Lazy load the uFuzzy library if not there already + if (!window['uFuzzy']) { + try { + await loadScript('./lib/uFuzzy.iife.min.js') + } catch (err) { + printError(err, 'Could not load uFuzzy') + } + } + if (searchMode === 'history') { return [...fuzzySearchWithScoring(searchTerm, 'tabs'), ...fuzzySearchWithScoring(searchTerm, 'history')] } else if (searchMode === 'bookmarks' || searchMode === 'tabs') {