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
|
// Parse the source and find the duplication
|
||||||
// style: {sourceCode: string, checkDup: boolean}
|
function build({sourceCode, checkDup = false}, noReject) {
|
||||||
function build(request, noReject) {
|
const pending = buildMeta({sourceCode})
|
||||||
const pending = buildMeta(request)
|
.then(style => Promise.all([
|
||||||
.then(style => Promise.all([buildCode(style), checkDup(style)]))
|
buildCode(style),
|
||||||
|
checkDup && findDup(style)
|
||||||
|
]))
|
||||||
.then(([style, dup]) => ({style, dup}));
|
.then(([style, dup]) => ({style, dup}));
|
||||||
|
|
||||||
if (noReject) {
|
if (noReject) {
|
||||||
return wrapReject(pending);
|
return wrapReject(pending);
|
||||||
}
|
}
|
||||||
return pending;
|
return pending;
|
||||||
|
|
||||||
function checkDup(style) {
|
|
||||||
const {checkDup} = style;
|
|
||||||
delete style.checkDup;
|
|
||||||
if (checkDup) {
|
|
||||||
return findDup(style);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function save(style, noReject) {
|
function save(style, noReject) {
|
||||||
|
|
|
@ -1,14 +1,6 @@
|
||||||
|
/* global runtimeSend */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function runtimeSend(request) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
chrome.runtime.sendMessage(
|
|
||||||
request,
|
|
||||||
({status, result}) => (status === 'error' ? reject : resolve)(result)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function createSourceLoader() {
|
function createSourceLoader() {
|
||||||
let source;
|
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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<script src="/content/util.js"></script>
|
||||||
<script src="/install-usercss/install-usercss.js"></script>
|
<script src="/install-usercss/install-usercss.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -1,4 +1,4 @@
|
||||||
/* global CodeMirror semverCompare makeLink closeCurrentTab */
|
/* global CodeMirror semverCompare makeLink closeCurrentTab runtimeSend */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
(() => {
|
(() => {
|
||||||
|
@ -153,15 +153,6 @@
|
||||||
main.insertBefore(buildWarning(err), main.firstChild);
|
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) {
|
function install(style) {
|
||||||
const request = Object.assign(style, {
|
const request = Object.assign(style, {
|
||||||
method: 'saveUsercss',
|
method: 'saveUsercss',
|
||||||
|
|
|
@ -59,7 +59,7 @@
|
||||||
"include_globs": ["*.user.css", "*.user.styl"],
|
"include_globs": ["*.user.css", "*.user.styl"],
|
||||||
"run_at": "document_idle",
|
"run_at": "document_idle",
|
||||||
"all_frames": false,
|
"all_frames": false,
|
||||||
"js": ["content/install-user-css.js"]
|
"js": ["content/util.js", "content/install-user-css.js"]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"browser_action": {
|
"browser_action": {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user