diff --git a/background/background.js b/background/background.js index cd947d31..b5e803eb 100644 --- a/background/background.js +++ b/background/background.js @@ -10,13 +10,13 @@ var backgroundWorker = workerUtil.createWorker({ window.API_METHODS = Object.assign(window.API_METHODS || {}, { getSectionsByUrl: styleManager.getSectionsByUrl, - getSectionsById: styleManager.getSectionsById, getStylesInfo: styleManager.getStylesInfo, + getStylesInfoByUrl: styleManager.getStylesInfoByUrl, toggleStyle: styleManager.toggleStyle, deleteStyle: styleManager.deleteStyle, - getStylesInfoByUrl: styleManager.getStylesInfoByUrl, installStyle: styleManager.installStyle, editSave: styleManager.editSave, + styleExists: styleManager.styleExists, getTabUrlPrefix() { return this.sender.tab.url.match(/^([\w-]+:\/+[^/#]+)/)[1]; diff --git a/background/style-manager.js b/background/style-manager.js index 121071c1..a0d11f6e 100644 --- a/background/style-manager.js +++ b/background/style-manager.js @@ -34,8 +34,7 @@ const styleManager = (() => { toggleStyle, getAllStyles, // used by import-export getStylesInfoByUrl, // used by popup - countStyles, - countStylesByUrl, // used by icon badge + styleExists, }); function handleLivePreviewConnections() { @@ -112,16 +111,8 @@ const styleManager = (() => { .map(s => getStyleWithNoCode(s.data)); } - function countStyles(filter) { - if (!filter) { - return styles.size; - } - if (filter.id) { - return styles.has(filter.id) ? 1 : 0; - } - return [...styles.values()] - .filter(s => filterMatch(filter, s.data)) - .length; + function styleExists(filter) { + return [...styles.value()].some(s => filterMatch(filter, s.data)); } function filterMatch(filter, target) { @@ -291,11 +282,6 @@ const styleManager = (() => { .map(k => getStyleWithNoCode(styles.get(Number(k)).data)); } - function countStylesByUrl(url, filter) { - const sections = getSectionsByUrl(url, filter); - return Object.keys(sections).length; - } - function getSectionsByUrl(url, filter) { let cache = cachedStyleForUrl.get(url); if (!cache) { diff --git a/popup/search-results.js b/popup/search-results.js index 438652d3..962d0baa 100755 --- a/popup/search-results.js +++ b/popup/search-results.js @@ -289,14 +289,14 @@ window.addEventListener('showStyles:done', function _() { return; } const md5Url = UPDATE_URL.replace('%', result.id); - API.countStyles({md5Url}).then(installedStyle => { - if (installedStyle) { + API.styleExists({md5Url}).then(exist => { + if (exist) { totalResults = Math.max(0, totalResults - 1); } else { processedResults.push(result); render(); } - setTimeout(processNextResult, !installedStyle && DELAY_AFTER_FETCHING_STYLES); + setTimeout(processNextResult, !exist && DELAY_AFTER_FETCHING_STYLES); }); }