diff --git a/background/usercss-helper.js b/background/usercss-helper.js index 850130ee..f1c6419c 100644 --- a/background/usercss-helper.js +++ b/background/usercss-helper.js @@ -71,6 +71,7 @@ * @param {Boolean=} _.checkDup * @param {Boolean=} _.metaOnly * @param {Object} _.vars + * @param {Boolean=} _.assignVars * @returns {Promise<{style, dup:Boolean?}>} */ function build({ @@ -78,20 +79,23 @@ checkDup, metaOnly, vars, + assignVars = false, }) { return usercss.buildMeta(sourceCode) - .then(style => - Promise.all([ - metaOnly ? style : doBuild(style), - checkDup ? find(style) : undefined - ]) - ) + .then(style => { + const findDup = checkDup || assignVars ? find(style) : null; + return Promise.all([ + metaOnly ? style : doBuild(style, findDup), + findDup + ]); + }) .then(([style, dup]) => ({style, dup})); - function doBuild(style) { - if (vars) { - const oldStyle = {usercssData: {vars}}; - return usercss.assignVars(style, oldStyle) + function doBuild(style, findDup) { + if (vars || assignVars) { + const getOld = vars ? Promise.resolve({usercssData: {vars}}) : findDup; + return getOld + .then(oldStyle => usercss.assignVars(style, oldStyle)) .then(() => usercss.buildCode(style)); } return usercss.buildCode(style); diff --git a/edit/source-editor.js b/edit/source-editor.js index 7561e832..dcd43a13 100644 --- a/edit/source-editor.js +++ b/edit/source-editor.js @@ -83,7 +83,7 @@ function createSourceEditor(style) { function preprocess(style) { return API.buildUsercss({ sourceCode: style.sourceCode, - vars: style.usercssData.vars + assignVars: true }) .then(({style: newStyle}) => { delete newStyle.enabled;