use .meta.css in update check on greasyfork

This commit is contained in:
tophf 2021-01-01 17:46:04 +03:00
parent c35302dff6
commit d26dd92f44

View File

@ -1,7 +1,7 @@
/* global API */// msg.js /* global API */// msg.js
/* global URLS debounce download ignoreChromeError */// toolbox.js
/* global calcStyleDigest styleJSONseemsValid styleSectionsEqual */ // sections-util.js /* global calcStyleDigest styleJSONseemsValid styleSectionsEqual */ // sections-util.js
/* global chromeLocal */// storage-util.js /* global chromeLocal */// storage-util.js
/* global debounce download ignoreChromeError */// toolbox.js
/* global prefs */ /* global prefs */
'use strict'; 'use strict';
@ -150,19 +150,25 @@ const updateMan = (() => {
async function updateUsercss() { async function updateUsercss() {
// TODO: when sourceCode is > 100kB use http range request(s) for version check // TODO: when sourceCode is > 100kB use http range request(s) for version check
const text = await tryDownload(style.updateUrl); const url = style.updateUrl;
const metaUrl = URLS.extractGreasyForkInstallUrl(url) &&
url.replace(/\.user\.css$/, '.meta.css');
const text = await tryDownload(metaUrl || url);
const json = await API.usercss.buildMeta({sourceCode: text}); const json = await API.usercss.buildMeta({sourceCode: text});
await require(['/vendor/semver-bundle/semver']); /* global semverCompare */ await require(['/vendor/semver-bundle/semver']); /* global semverCompare */
const delta = semverCompare(json.usercssData.version, ucd.version); const delta = semverCompare(json.usercssData.version, ucd.version);
if (!delta && !ignoreDigest) { if (!delta && !ignoreDigest) {
// re-install is invalid in a soft upgrade // re-install is invalid in a soft upgrade
const sameCode = text === style.sourceCode; const sameCode = !metaUrl && text === style.sourceCode;
return Promise.reject(sameCode ? STATES.SAME_CODE : STATES.SAME_VERSION); return Promise.reject(sameCode ? STATES.SAME_CODE : STATES.SAME_VERSION);
} }
if (delta < 0) { if (delta < 0) {
// downgrade is always invalid // downgrade is always invalid
return Promise.reject(STATES.ERROR_VERSION); return Promise.reject(STATES.ERROR_VERSION);
} }
if (metaUrl) {
json.sourceCode = await tryDownload(url);
}
return API.usercss.buildCode(json); return API.usercss.buildCode(json);
} }