diff --git a/background/background.js b/background/background.js index 04e08665..6e720b35 100644 --- a/background/background.js +++ b/background/background.js @@ -4,6 +4,7 @@ global handleCssTransitionBug detectSloppyRegexps global openEditor global styleViaAPI global loadScript +global usercss */ 'use strict'; @@ -17,6 +18,9 @@ window.API_METHODS = Object.assign(window.API_METHODS || {}, { delete msg.method; return download(msg.url, msg); }, + parseCss({code}) { + return usercss.invokeWorker({action: 'parse', code}); + }, getPrefs: () => prefs.getAll(), healthCheck: () => dbExec().then(() => true), diff --git a/content/install-hook-userstyles.js b/content/install-hook-userstyles.js index 5c4ffe5f..7406d913 100644 --- a/content/install-hook-userstyles.js +++ b/content/install-hook-userstyles.js @@ -241,6 +241,21 @@ function getStyleJson() { return getResource(getStyleURL(), {responseType: 'json'}) + .then(style => { + if (!style || !Array.isArray(style.sections) || style.sections.length) { + return style; + } + const codeElement = document.getElementById('stylish-code'); + if (codeElement && !codeElement.textContent.trim()) { + return style; + } + return getResource(getMeta('stylish-update-url')).then(code => new Promise(resolve => { + chrome.runtime.sendMessage({method: 'parseCss', code}, ({sections}) => { + style.sections = sections; + resolve(style); + }); + })); + }) .catch(() => null); } diff --git a/js/usercss.js b/js/usercss.js index b23b150f..6c676187 100644 --- a/js/usercss.js +++ b/js/usercss.js @@ -617,5 +617,5 @@ var usercss = (() => { }); } - return {buildMeta, buildCode, assignVars}; + return {buildMeta, buildCode, assignVars, invokeWorker}; })();