Detect webpsupport on start-up

This commit is contained in:
Gusted 2021-08-12 14:06:02 +02:00
parent e63df156d9
commit 98b6310b6f
No known key found for this signature in database
GPG Key ID: FD821B732837125F

View File

@ -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)) {
if (imgType !== '.jpg') {
elShot.src = shotName.replace(/\.jpg$/, imgType);
} else {
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);
}
} else {
elShot.src = BLANK_PIXEL;
}