From 2dbccf71dbfa8b54ffd13ab3a3d9d7fab3309201 Mon Sep 17 00:00:00 2001 From: Gusted Date: Thu, 12 Aug 2021 15:02:48 +0200 Subject: [PATCH] Prefer webp when available (#1306) --- popup/search.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/popup/search.js b/popup/search.js index a474e344..13e727e0 100644 --- a/popup/search.js +++ b/popup/search.js @@ -54,6 +54,13 @@ let totalPages = 1; let ready; + let imgType = '.jpg'; + // detect WebP support + $create('img', { + src: 'data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA=', + onload: () => (imgType = '.webp'), + }); + const $class = sel => (sel instanceof Node ? sel : $(sel)).classList; const show = sel => $class(sel).remove('hidden'); const hide = sel => $class(sel).add('hidden'); @@ -286,7 +293,9 @@ // screenshot const elShot = $('.search-result-screenshot', entry); if (isUsw) { - elShot.src = /^https?:/i.test(shotName) ? shotName : BLANK_PIXEL; + elShot.src = !/^https?:/i.test(shotName) ? BLANK_PIXEL : + imgType !== '.jpg' ? shotName.replace(/\.jpg$/, imgType) : + shotName; } else { const auto = URLS.uso + `auto_style_screenshots/${id}${USO_AUTO_PIC_SUFFIX}`; Object.assign(elShot, {