diff --git a/js/toolbox.js b/js/toolbox.js index 3252465a..589a35e9 100644 --- a/js/toolbox.js +++ b/js/toolbox.js @@ -102,7 +102,7 @@ const URLS = { const id = URLS.extractUSwId(url); return id ? `${URLS.usw}style/${id}` : ''; }, - makeUSwArchiveCodeUrl: id => `${URLS.usw}api/style/${id}.user.css`, + makeUswCodeUrl: id => `${URLS.usw}api/style/${id}.user.css`, supported: url => ( url.startsWith('http') || diff --git a/popup/search.js b/popup/search.js index 521b1c82..f05f477f 100644 --- a/popup/search.js +++ b/popup/search.js @@ -291,7 +291,7 @@ // Note to Tophf, we send a direct image link over shotName, as we are currently not // hosting any images. Which soon will be different. - const isDirectImageLink = /(.jpg|.webp|.avif|.jpeg|.png)$/g.match(shotName); + const isDirectImageLink = /(.jpg|.webp|.avif|.jpeg|.png)$/g.test(shotName); const auto = URLS.uso + `auto_style_screenshots/${id}${USO_AUTO_PIC_SUFFIX}`; Object.assign($('.search-result-screenshot', entry), { src: isDirectImageLink ? shotName @@ -407,7 +407,7 @@ async function install() { const entry = this.closest('.search-result'); const result = /** @type IndexEntry */ entry._result; - const {i: id} = result; + const {i: id, isUsw} = result; const installButton = $('.search-result-install', entry); showSpinner(entry); @@ -418,10 +418,7 @@ result.pingbackTimer = setTimeout(download, PINGBACK_DELAY, `${URLS.uso}styles/install/${id}?source=stylish-ch`); - // Any recommendation how to detect USw here? - // the `uw` was purely for this situation to make sure if we need - // create a USw url or an Uso-Archive url. - const updateUrl = URLS.makeUsoArchiveCodeUrl(id); + const updateUrl = isUsw ? URLS.makeUswCodeUrl(id) : URLS.makeUsoArchiveCodeUrl(id); try { const sourceCode = await download(updateUrl); @@ -488,6 +485,9 @@ index = index.concat(res.filter(res => res.f === 'uso')); }).catch(() => {}), download(USW_INDEX_URL, {responseType: 'json'}).then(res => { + res.data.map(style => { + style.isUsw = true; + }); index = index.concat(res.data); }).catch(() => {}), ]);