diff --git a/background/storage.js b/background/storage.js index b57cdf62..e3c7cfdf 100644 --- a/background/storage.js +++ b/background/storage.js @@ -264,6 +264,15 @@ function filterStyles({ } +// The md5Url provided by USO includes a duplicate "update" subdomain (see #523), +// This fixes any already installed styles containing this error +function fixUsoMd5Issue(style) { + if (style && style.md5Url && style.md5Url.includes('update.update.userstyles')) { + style.md5Url = style.md5Url.replace('update.update.userstyles', 'update.userstyles'); + } + return style; +} + function filterStylesInternal({ // js engines don't like big functions (V8 often deoptimized the original filterStyles) // it also makes sense to extract the less frequently executed code @@ -297,7 +306,7 @@ function filterStylesInternal({ const matchUrlBase = matchUrl && matchUrl.includes('#') && matchUrl.split('#', 1)[0]; let style; - for (let i = 0; (style = styles[i]); i++) { + for (let i = 0; (style = fixUsoMd5Issue(styles[i])); i++) { if ((enabled === null || style.enabled === enabled) && (md5Url === null || style.md5Url === md5Url) && (id === null || style.id === id)) { @@ -350,6 +359,8 @@ function saveStyle(style) { let existed; let codeIsUpdated; + style = fixUsoMd5Issue(style); + return maybeCalcDigest() .then(maybeImportFix) .then(decide); diff --git a/content/install-hook-userstyles.js b/content/install-hook-userstyles.js index d26a88af..7ebdbd22 100644 --- a/content/install-hook-userstyles.js +++ b/content/install-hook-userstyles.js @@ -238,6 +238,14 @@ }); } + // USO providing md5Url as "https://update.update.userstyles.org/#####.md5" + // instead of "https://update.userstyles.org/#####.md5" + function tryFixMd5(style) { + if (style && style.md5Url && style.md5Url.includes('update.update')) { + style.md5Url = style.md5Url.replace('update.update', 'update'); + } + return style; + } function getStyleJson() { return getResource(getStyleURL(), {responseType: 'json'}) @@ -256,6 +264,7 @@ }); })); }) + .then(tryFixMd5) .catch(() => null); }