From d8b776bedf576ac78811ec75deaeea43155613ac Mon Sep 17 00:00:00 2001 From: tophf Date: Thu, 5 Jul 2018 15:42:42 +0300 Subject: [PATCH] try installing from full code if 'sections' is empty in style json fixes #414 --- background/background.js | 4 ++++ content/install-hook-userstyles.js | 15 +++++++++++++++ js/usercss.js | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) 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}; })();