try installing from full code if 'sections' is empty in style json

fixes #414
This commit is contained in:
tophf 2018-07-05 15:42:42 +03:00
parent 9992ae3374
commit d8b776bedf
3 changed files with 20 additions and 1 deletions

View File

@ -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),

View File

@ -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);
}

View File

@ -617,5 +617,5 @@ var usercss = (() => {
});
}
return {buildMeta, buildCode, assignVars};
return {buildMeta, buildCode, assignVars, invokeWorker};
})();