From 992b89f0eb295eb480f8fc192992ce5cc6b5a17e Mon Sep 17 00:00:00 2001 From: tophf Date: Tue, 12 Oct 2021 20:12:26 +0300 Subject: [PATCH] more stuff in fixKnownProblems fixes #1342 --- background/style-manager.js | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/background/style-manager.js b/background/style-manager.js index 53923466..9a92d2ff 100644 --- a/background/style-manager.js +++ b/background/style-manager.js @@ -234,12 +234,6 @@ const styleMan = (() => { if (ready.then) await ready; reason = reason || dataMap.has(style.id) ? 'update' : 'install'; style = mergeWithMapped(style); - const url = !style.url && style.updateUrl && ( - URLS.extractUsoArchiveInstallUrl(style.updateUrl) || - URLS.extractGreasyForkInstallUrl(style.updateUrl) || - URLS.extractUSwInstallUrl(style.updateUrl) - ); - if (url) style.url = style.installationUrl = url; style.originalDigest = await calcStyleDigest(style); // FIXME: update updateDate? what about usercss config? return saveStyle(style, {reason}); @@ -427,7 +421,7 @@ const styleMan = (() => { style._id = uuidv4(); } style._rev = Date.now(); - fixUsoMd5Issue(style); + fixKnownProblems(style); } function afterSave(style, newId) { @@ -478,7 +472,6 @@ const styleMan = (() => { await db.exec('putMany', updated); } for (const style of styles) { - fixUsoMd5Issue(style); storeInMap(style); uuidIndex.set(style._id, style.id); } @@ -513,7 +506,21 @@ const styleMan = (() => { style[key] = fixedUrl; } } - return res; + let url; + /* USO bug, duplicate "update" subdomain, see #523 */ + if ((url = style.md5Url) && url.includes('update.update.userstyles')) { + res = style.md5Url = url.replace('update.update.userstyles', 'update.userstyles'); + } + /* Default homepage URL for external styles installed from a known distro */ + if ((url = style.updateUrl) && (url = + URLS.extractGreasyForkInstallUrl(url) || + URLS.extractUsoArchiveInstallUrl(url) || + URLS.extractUSwInstallUrl(url) + )) { + if (!style.url) res = style.url = url; + if (style.installationUrl !== url) res = style.installationUrl = url; + } + return Boolean(res); } function urlMatchStyle(query, style) { @@ -602,14 +609,6 @@ const styleMan = (() => { '$'; } - // 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'); - } - } - function createMatchQuery(url) { let urlWithoutHash; let urlWithoutParams;