Fix: pull out runtimeSend

This commit is contained in:
eight 2017-11-01 08:17:12 +08:00
parent 79b6266cf9
commit 098dc10f85
6 changed files with 20 additions and 32 deletions

View File

@ -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) {

View File

@ -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;

10
content/util.js Normal file
View File

@ -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)
);
});
}

View File

@ -83,6 +83,7 @@
</div>
</div>
</div>
<script src="/content/util.js"></script>
<script src="/install-usercss/install-usercss.js"></script>
</body>
</html>

View File

@ -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',

View File

@ -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": {