From 098dc10f856437334a237394d70cb77f323e0461 Mon Sep 17 00:00:00 2001 From: eight Date: Wed, 1 Nov 2017 08:17:12 +0800 Subject: [PATCH] Fix: pull out runtimeSend --- background/usercss-helper.js | 18 ++++++------------ content/install-user-css.js | 10 +--------- content/util.js | 10 ++++++++++ install-usercss.html | 1 + install-usercss/install-usercss.js | 11 +---------- manifest.json | 2 +- 6 files changed, 20 insertions(+), 32 deletions(-) create mode 100644 content/util.js diff --git a/background/usercss-helper.js b/background/usercss-helper.js index 8a9a3a0c..26bf92d8 100644 --- a/background/usercss-helper.js +++ b/background/usercss-helper.js @@ -27,24 +27,18 @@ var usercssHelper = (() => { } // Parse the source and find the duplication - // style: {sourceCode: string, checkDup: boolean} - function build(request, noReject) { - const pending = buildMeta(request) - .then(style => Promise.all([buildCode(style), checkDup(style)])) + function build({sourceCode, checkDup = false}, noReject) { + const pending = buildMeta({sourceCode}) + .then(style => Promise.all([ + buildCode(style), + checkDup && findDup(style) + ])) .then(([style, dup]) => ({style, dup})); if (noReject) { return wrapReject(pending); } return pending; - - function checkDup(style) { - const {checkDup} = style; - delete style.checkDup; - if (checkDup) { - return findDup(style); - } - } } function save(style, noReject) { diff --git a/content/install-user-css.js b/content/install-user-css.js index 99c31496..8e4c61fc 100644 --- a/content/install-user-css.js +++ b/content/install-user-css.js @@ -1,14 +1,6 @@ +/* global runtimeSend */ 'use strict'; -function runtimeSend(request) { - return new Promise((resolve, reject) => { - chrome.runtime.sendMessage( - request, - ({status, result}) => (status === 'error' ? reject : resolve)(result) - ); - }); -} - function createSourceLoader() { let source; diff --git a/content/util.js b/content/util.js new file mode 100644 index 00000000..c639440f --- /dev/null +++ b/content/util.js @@ -0,0 +1,10 @@ +'use strict'; + +function runtimeSend(request) { + return new Promise((resolve, reject) => { + chrome.runtime.sendMessage( + request, + ({status, result}) => (status === 'error' ? reject : resolve)(result) + ); + }); +} diff --git a/install-usercss.html b/install-usercss.html index b2f6b78a..aa7762e1 100644 --- a/install-usercss.html +++ b/install-usercss.html @@ -83,6 +83,7 @@ + \ No newline at end of file diff --git a/install-usercss/install-usercss.js b/install-usercss/install-usercss.js index 7a2862fc..0a8846d4 100644 --- a/install-usercss/install-usercss.js +++ b/install-usercss/install-usercss.js @@ -1,4 +1,4 @@ -/* global CodeMirror semverCompare makeLink closeCurrentTab */ +/* global CodeMirror semverCompare makeLink closeCurrentTab runtimeSend */ 'use strict'; (() => { @@ -153,15 +153,6 @@ main.insertBefore(buildWarning(err), main.firstChild); } - function runtimeSend(request) { - return new Promise((resolve, reject) => { - chrome.runtime.sendMessage( - request, - ({status, result}) => (status === 'error' ? reject : resolve)(result) - ); - }); - } - function install(style) { const request = Object.assign(style, { method: 'saveUsercss', diff --git a/manifest.json b/manifest.json index ffc059b5..4d567ffb 100644 --- a/manifest.json +++ b/manifest.json @@ -59,7 +59,7 @@ "include_globs": ["*.user.css", "*.user.styl"], "run_at": "document_idle", "all_frames": false, - "js": ["content/install-user-css.js"] + "js": ["content/util.js", "content/install-user-css.js"] } ], "browser_action": {