From 98b6310b6f4e5ca536beee4fdcd06eaf8dbd657a Mon Sep 17 00:00:00 2001 From: Gusted Date: Thu, 12 Aug 2021 14:06:02 +0200 Subject: [PATCH] Detect webpsupport on start-up --- popup/search.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/popup/search.js b/popup/search.js index 4feb85f1..232a36c1 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'); @@ -287,17 +294,11 @@ const elShot = $('.search-result-screenshot-default', entry); if (isUsw) { if (/^https?:/i.test(shotName)) { - elShot.src = shotName; - // USw has by default a screenshot of the style in webp format. - // But for compatability reasons always deliver the jpg format. - // Webp format is more efficient and thus is preffered to be used. - // When supported. - const webpElShot = $create('source', { - type: 'image/webp', - srcset: shotName.replace(/\.jpg$/, '.webp'), - }); - const pictureEl = $('.search-result-screenshot', entry); - pictureEl.insertBefore(webpElShot, pictureEl.firstChild); + if (imgType !== '.jpg') { + elShot.src = shotName.replace(/\.jpg$/, imgType); + } else { + elShot.src = shotName; + } } else { elShot.src = BLANK_PIXEL; }