From 1e5f118d2dd1f5e8169ba13ee3e0312caa468a35 Mon Sep 17 00:00:00 2001 From: tophf Date: Thu, 12 Aug 2021 20:35:56 +0300 Subject: [PATCH] update USO-archive urls (#1308) --- background/update-manager.js | 2 +- background/usercss-install-helper.js | 5 ++--- js/toolbox.js | 13 ++++++++----- manage/render.js | 2 +- popup/search.js | 23 +++++++++++------------ 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/background/update-manager.js b/background/update-manager.js index 2ef3a357..023006ef 100644 --- a/background/update-manager.js +++ b/background/update-manager.js @@ -277,7 +277,7 @@ const updateMan = (() => { } function getDateFromVer(style) { - const m = style.updateUrl.startsWith(URLS.usoArchiveRaw) && + const m = URLS.extractUsoArchiveId(style.updateUrl) && style.usercssData.version.match(RX_DATE2VER); if (m) { m[2]--; // month is 0-based in `Date` constructor diff --git a/background/usercss-install-helper.js b/background/usercss-install-helper.js index 20e75536..a51af3a5 100644 --- a/background/usercss-install-helper.js +++ b/background/usercss-install-helper.js @@ -35,10 +35,9 @@ bgReady.all.then(() => { chrome.webRequest.onBeforeSendHeaders.addListener(maybeInstallFromDistro, { urls: [ - URLS.usoArchiveRaw + 'usercss/*.user.css', URLS.usw + 'api/style/*.user.css', - '*://greasyfork.org/scripts/*/code/*.user.css', - '*://sleazyfork.org/scripts/*/code/*.user.css', + ...URLS.usoArchiveRaw.map(s => s + 'usercss/*.user.css'), + ...['greasy', 'sleazy'].map(s => `*://${s}fork.org/scripts/*/code/*.user.css`), ...[].concat( ...Object.entries(maybeDistro) .map(([host, {glob}]) => makeUsercssGlobs(host, glob))), diff --git a/js/toolbox.js b/js/toolbox.js index 55f5422b..dc3ddbb7 100644 --- a/js/toolbox.js +++ b/js/toolbox.js @@ -77,20 +77,23 @@ const URLS = { uso: 'https://userstyles.org/', usoJson: 'https://userstyles.org/styles/chrome/', - usoArchive: 'https://33kk.github.io/uso-archive/', - usoArchiveRaw: 'https://raw.githubusercontent.com/33kk/uso-archive/flomaster/data/', + usoArchive: 'https://uso.kkx.one/', + usoArchiveRaw: [ + 'https://cdn.jsdelivr.net/gh/33kk/uso-archive@flomaster/data/', + 'https://raw.githubusercontent.com/33kk/uso-archive/flomaster/data/', + ], usw: 'https://userstyles.world/', extractUsoArchiveId: url => url && - url.startsWith(URLS.usoArchiveRaw) && + URLS.usoArchiveRaw.some(u => url.startsWith(u)) && Number(url.match(/\/(\d+)\.user\.css|$/)[1]), extractUsoArchiveInstallUrl: url => { const id = URLS.extractUsoArchiveId(url); - return id ? `${URLS.usoArchive}?style=${id}` : ''; + return id ? `${URLS.usoArchive}/style/${id}` : ''; }, - makeUsoArchiveCodeUrl: id => `${URLS.usoArchiveRaw}usercss/${id}.user.css`, + makeUsoArchiveCodeUrl: id => `${URLS.usoArchiveRaw[0]}usercss/${id}.user.css`, extractGreasyForkInstallUrl: url => /^(https:\/\/(?:greasy|sleazy)fork\.org\/scripts\/\d+)[^/]*\/code\/[^/]*\.user\.css$|$/.exec(url)[1], diff --git a/manage/render.js b/manage/render.js index cc0afb6d..1ee013bd 100644 --- a/manage/render.js +++ b/manage/render.js @@ -83,7 +83,7 @@ function createStyleElement({style, name: nameLC}) { parts.homepage.href = parts.homepage.title = style.url || ''; parts.infoVer.textContent = ud ? ud.version : ''; parts.infoVer.dataset.value = ud ? ud.version : ''; - if (`${style.updateUrl}`.startsWith(URLS.usoArchiveRaw)) { + if (URLS.extractUsoArchiveId(style.updateUrl)) { parts.infoVer.dataset.isDate = ''; } else { delete parts.infoVer.dataset.isDate; diff --git a/popup/search.js b/popup/search.js index 4842c69d..bdbeb636 100644 --- a/popup/search.js +++ b/popup/search.js @@ -11,7 +11,7 @@ require(['/popup/search.css']); const RESULT_ID_PREFIX = 'search-result-'; - const INDEX_URL = URLS.usoArchiveRaw + 'search-index.json'; + const INDEX_URL = URLS.usoArchiveRaw[0] + 'search-index.json'; const USW_INDEX_URL = URLS.usw + 'api/index/uso-format'; const USW_ICON = $create('img', { src: `${URLS.usw}favicon.ico`, @@ -275,17 +275,17 @@ u: updateTime, w: weeklyInstalls, t: totalInstalls, + ai: authorId, an: author, sa: shotArchived, - sn: shotName, + sn: shot, isUsw, } = entry._result = result; entry.id = RESULT_ID_PREFIX + id; // title Object.assign($('.search-result-title', entry), { onclick: Events.openURLandHide, - href: isUsw ? `${URLS.usw}style/${id}` : - `${URLS.usoArchive}?category=${category}&style=${id}`, + href: `${isUsw ? URLS.usw : URLS.usoArchive}style/${id}`, }); if (isUsw) $('.search-result-title', entry).prepend(USW_ICON.cloneNode(true)); $('.search-result-title span', entry).textContent = @@ -293,26 +293,25 @@ // screenshot const elShot = $('.search-result-screenshot', entry); if (isUsw) { - elShot.src = !/^https?:/i.test(shotName) ? BLANK_PIXEL : - imgType !== '.jpg' ? shotName.replace(/\.jpg$/, imgType) : - shotName; + elShot.src = !/^https?:/i.test(shot) ? BLANK_PIXEL : + imgType !== '.jpg' ? shot.replace(/\.jpg$/, imgType) : + shot; } else { const auto = URLS.uso + `auto_style_screenshots/${id}${USO_AUTO_PIC_SUFFIX}`; Object.assign(elShot, { - src: shotName && !shotName.endsWith(USO_AUTO_PIC_SUFFIX) - ? `${shotArchived ? URLS.usoArchiveRaw : URLS.uso + 'style_'}screenshots/${shotName}` + src: shot && !shot.endsWith(USO_AUTO_PIC_SUFFIX) + ? `${shotArchived ? URLS.usoArchiveRaw[0] : URLS.uso + 'style_'}screenshots/${shot}` : auto, _src: auto, onerror: fixScreenshot, }); } // author - const eAuthor = encodeURIComponent(author); Object.assign($('[data-type="author"] a', entry), { textContent: author, title: author, - href: isUsw ? `${URLS.usw}user/${eAuthor}` : - `${URLS.usoArchive}?author=${eAuthor.replace(/%20/g, '+')}`, + href: isUsw ? `${URLS.usw}user/${encodeURIComponent(author)}` : + `${URLS.usoArchive}browse/styles?search=%40${authorId}`, onclick: Events.openURLandHide, }); // rating