From f9dc04558f7dd3c077259bbe762569940b035403 Mon Sep 17 00:00:00 2001 From: eight Date: Sun, 14 Oct 2018 18:48:20 +0800 Subject: [PATCH] Fix: drop getStylesInfo --- background/background.js | 1 - background/style-manager.js | 20 ++++++-------------- manage/config-dialog.js | 2 +- manage/manage.js | 17 ++++++++--------- popup/popup.js | 4 ++-- 5 files changed, 17 insertions(+), 27 deletions(-) diff --git a/background/background.js b/background/background.js index a05c6bdd..25944231 100644 --- a/background/background.js +++ b/background/background.js @@ -15,7 +15,6 @@ window.API_METHODS = Object.assign(window.API_METHODS || {}, { getAllStyles: styleManager.getAllStyles, // used by importer getSectionsByUrl: styleManager.getSectionsByUrl, getStyle: styleManager.get, - getStylesInfo: styleManager.getStylesInfo, getStylesInfoByUrl: styleManager.getStylesInfoByUrl, importStyle: styleManager.importStyle, installStyle: styleManager.installStyle, diff --git a/background/style-manager.js b/background/style-manager.js index c8f8fefe..74c2697c 100644 --- a/background/style-manager.js +++ b/background/style-manager.js @@ -49,7 +49,6 @@ const styleManager = (() => { return ensurePrepared({ get, - getStylesInfo, getSectionsByUrl, installStyle, deleteStyle, @@ -92,12 +91,14 @@ const styleManager = (() => { }); } - function get(id) { - return styles.get(id).data; + function get(id, noCode = false) { + const data = styles.get(id).data; + return noCode ? getStyleWithNoCode(data) : data; } - function getAllStyles() { - return [...styles.values()].map(s => s.data); + function getAllStyles(noCode = false) { + const datas = [...styles.values()].map(s => s.data); + return noCode ? datas.map(getStyleWithNoCode) : datas; } function toggleStyle(id, enabled) { @@ -108,15 +109,6 @@ const styleManager = (() => { .then(() => id); } - function getStylesInfo(filter) { - if (filter && filter.id) { - return [getStyleWithNoCode(styles.get(filter.id).data)]; - } - return [...styles.values()] - .filter(s => !filter || filterMatch(filter, s.data)) - .map(s => getStyleWithNoCode(s.data)); - } - // used by install-hook-userstyles.js function findStyle(filter, noCode = false) { for (const style of styles.values()) { diff --git a/manage/config-dialog.js b/manage/config-dialog.js index 73da97f0..4006b9f5 100644 --- a/manage/config-dialog.js +++ b/manage/config-dialog.js @@ -119,7 +119,7 @@ function configDialog(style) { return; } if (!bgStyle) { - API.getStylesInfo({id: style.id}) + API.getStyle(style.id, true) .then(([bgStyle]) => save({anyChangeIsDirty}, bgStyle || {})); return; } diff --git a/manage/manage.js b/manage/manage.js index c11fa825..cb3959c3 100644 --- a/manage/manage.js +++ b/manage/manage.js @@ -35,7 +35,7 @@ const OWN_ICON = chrome.runtime.getManifest().icons['16']; const handleEvent = {}; Promise.all([ - API.getStylesInfo(), + API.getAllStyles(true), urlFilterParam && API.searchDB({query: 'url:' + urlFilterParam}), onDOMready().then(initGlobalEvents), ]).then(args => { @@ -48,8 +48,8 @@ function onRuntimeMessage(msg) { switch (msg.method) { case 'styleUpdated': case 'styleAdded': - API.getStylesInfo({id: msg.style.id}) - .then(([style]) => handleUpdate(style, msg)); + API.getStyle(msg.style.id, true) + .then(style => handleUpdate(style, msg)); break; case 'styleDeleted': handleDelete(msg.style.id); @@ -647,7 +647,7 @@ function switchUI({styleOnly} = {}) { const missingFavicons = newUI.enabled && newUI.favicons && !$('.applies-to img'); if (changed.enabled || (missingFavicons && !createStyleElement.parts)) { installed.textContent = ''; - API.getStylesInfo().then(showStyles); + API.getAllStyles(true).then(showStyles); return; } if (changed.targets) { @@ -671,11 +671,10 @@ function onVisibilityChange() { // assuming other changes aren't important enough to justify making a complicated DOM sync case 'visible': if (sessionStorage.justEditedStyleId) { - API.getStylesInfo({ - id: sessionStorage.justEditedStyleId - }).then(([style]) => { - handleUpdate(style, {method: 'styleUpdated'}); - }); + API.getStyle(Number(sessionStorage.justEditedStyleId), true) + .then(style => { + handleUpdate(style, {method: 'styleUpdated'}); + }); delete sessionStorage.justEditedStyleId; } break; diff --git a/popup/popup.js b/popup/popup.js index 321af757..032c3691 100644 --- a/popup/popup.js +++ b/popup/popup.js @@ -2,7 +2,7 @@ global configDialog hotkeys popupExclusions onTabReady msg getActiveTab FIREFOX getTabRealURL URLS API onDOMready $ $$ prefs CHROME -setupLivePrefs template ignoreChromeError t $create tWordBreak animateElement +setupLivePrefs template t $create tWordBreak animateElement tryJSONparse debounce */ @@ -389,7 +389,7 @@ Object.assign(handleEvent, { configure(event) { const {styleId, styleIsUsercss} = handleEvent.getClickedStyleElement(event); if (styleIsUsercss) { - API.getStylesInfo({id: styleId}).then(([style]) => { + API.getStyle(styleId, true).then(style => { hotkeys.setState(false); configDialog(style).then(() => { hotkeys.setState(true);