From 24a6217f26911ba4e934f4a7bff8bcd30c227163 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 23 Oct 2016 16:50:48 +0100 Subject: Move SearchEngines to bg-utils.coffee. `SearchEngines` was previously in `utils.coffee`, which means it was loaded in *every* content frame. This is unnecessary, since it is only used on the background page. So this PR moves it there. Also: - Simplify some unnecessarily complex logic in `vomnibar.coffee`. - Re-use `Utils.parseLines()` to parse the custom search engine configuation text. --- lib/utils.coffee | 34 ---------------------------------- 1 file changed, 34 deletions(-) (limited to 'lib') diff --git a/lib/utils.coffee b/lib/utils.coffee index 5a028186..babb5f96 100644 --- a/lib/utils.coffee +++ b/lib/utils.coffee @@ -216,39 +216,6 @@ Utils = chrome.storage.onChanged.addListener (changes, area) => setter changes[key].newValue if changes[key]?.newValue? -# Utility for parsing and using the custom search-engine configuration. We re-use the previous parse if the -# search-engine configuration is unchanged. -SearchEngines = - previousSearchEngines: null - searchEngines: null - - refresh: (searchEngines) -> - unless @previousSearchEngines? and searchEngines == @previousSearchEngines - @previousSearchEngines = searchEngines - @searchEngines = new AsyncDataFetcher (callback) -> - engines = {} - for line in searchEngines.split "\n" - line = line.trim() - continue if /^[#"]/.test line - tokens = line.split /\s+/ - continue unless 2 <= tokens.length - keyword = tokens[0].split(":")[0] - searchUrl = tokens[1] - description = tokens[2..].join(" ") || "search (#{keyword})" - continue unless Utils.hasFullUrlPrefix searchUrl - engines[keyword] = { keyword, searchUrl, description } - - callback engines - - # Use the parsed search-engine configuration, possibly asynchronously. - use: (callback) -> - @searchEngines.use callback - - # Both set (refresh) the search-engine configuration and use it at the same time. - refreshAndUse: (searchEngines, callback) -> - @refresh searchEngines - @use callback - # This creates a new function out of an existing function, where the new function takes fewer arguments. This # allows us to pass around functions instead of functions + a partial list of arguments. Function::curry = -> @@ -347,7 +314,6 @@ class JobRunner root = exports ? window root.Utils = Utils -root.SearchEngines = SearchEngines root.SimpleCache = SimpleCache root.AsyncDataFetcher = AsyncDataFetcher root.JobRunner = JobRunner -- cgit v1.2.3