diff --git a/background/background.js b/background/background.js
index 7bf69067..7e242e2e 100644
--- a/background/background.js
+++ b/background/background.js
@@ -15,6 +15,7 @@ window.API_METHODS = Object.assign(window.API_METHODS || {}, {
deleteStyle: styleManager.deleteStyle,
getStylesInfoByUrl: styleManager.getStylesInfoByUrl,
installStyle: styleManager.installStyle,
+ editSave: styleManager.editSave,
getStyleFromDB: id =>
db.exec('get', id).then(event => event.target.result),
@@ -96,7 +97,10 @@ navigatorUtil.onUrlChange(({tabId, frameId}, type) => {
// styles would be updated when content script is injected.
return;
}
- msg.sendTab(tabId, {method: 'urlChanged'}, {frameId});
+ msg.sendTab(tabId, {method: 'urlChanged'}, {frameId})
+ .catch(err => {
+ console.warn(tabId, frameId, err);
+ });
});
if (FIREFOX) {
diff --git a/background/search-db.js b/background/search-db.js
index 9d5bece6..d6aef03d 100644
--- a/background/search-db.js
+++ b/background/search-db.js
@@ -1,4 +1,4 @@
-/* global API_METHODS filterStyles cachedStyles */
+/* global API_METHODS styleManager */
'use strict';
(() => {
@@ -25,7 +25,8 @@
if (/^url:/i.test(query)) {
matchUrl = query.slice(query.indexOf(':') + 1).trim();
if (matchUrl) {
- return filterStyles({matchUrl}).map(style => style.id);
+ return styleManager.getStylesInfoByUrl(matchUrl)
+ .then(styles => styles.map(style => style.id));
}
}
if (query.startsWith('/') && /^\/(.+?)\/([gimsuy]*)$/.test(query)) {
@@ -44,25 +45,32 @@
}
const results = [];
- for (const item of ids || cachedStyles.list) {
- const id = isNaN(item) ? item.id : item;
- if (!query || words && !words.length) {
- results.push(id);
- continue;
+ return styleManager.getAllStyles(styles => {
+ if (ids) {
+ const idSet = new Set(ids);
+ return styles.filter(s => idSet.has(s.id));
}
- const style = isNaN(item) ? item : cachedStyles.byId.get(item);
- if (!style) continue;
- for (const part in PARTS) {
- const text = style[part];
- if (text && PARTS[part](text, rx, words, icase)) {
- results.push(id);
- break;
+ return styles;
+ })
+ .then(styles => {
+ for (const style of styles) {
+ const id = style.id;
+ if (!query || words && !words.length) {
+ results.push(id);
+ continue;
+ }
+ for (const part in PARTS) {
+ const text = style[part];
+ if (text && PARTS[part](text, rx, words, icase)) {
+ results.push(id);
+ break;
+ }
+ }
}
- }
- }
- if (cache.size) debounce(clearCache, 60e3);
- return results;
+ if (cache.size) debounce(clearCache, 60e3);
+ return results;
+ });
};
function searchText(text, rx, words, icase) {
diff --git a/edit.html b/edit.html
index e40afd44..b1908c79 100644
--- a/edit.html
+++ b/edit.html
@@ -460,11 +460,15 @@
+
+