Fix: pull out runtimeSend
This commit is contained in:
parent
79b6266cf9
commit
098dc10f85
|
@ -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) {
|
||||
|
|
|
@ -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
10
content/util.js
Normal 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)
|
||||
);
|
||||
});
|
||||
}
|
|
@ -83,6 +83,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="/content/util.js"></script>
|
||||
<script src="/install-usercss/install-usercss.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -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',
|
||||
|
|
|
@ -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": {
|
||||
|
|
Loading…
Reference in New Issue
Block a user