109 lines
3.1 KiB
JavaScript
109 lines
3.1 KiB
JavaScript
$(document).ready(() => {
|
|
let x13images = [];
|
|
|
|
$("img").each(function () {
|
|
let imgSrc = $(this).attr("src") ?? "";
|
|
|
|
if (typeof x13webp_lazyload_enabled !== 'undefined' && x13webp_lazyload_enabled === '1') {
|
|
imgSrc = $(this).attr("data-src") ?? $(this).attr("data-lazy") ?? $(this).attr("data-original") ?? $(this).attr("src") ?? "";
|
|
}
|
|
|
|
if (imgSrc.includes(".webp")) return;
|
|
if (!imgSrc.includes(".jpg") && !imgSrc.includes(".JPG")
|
|
&& !imgSrc.includes(".jpeg") && !imgSrc.includes(".JPEG")
|
|
&& !imgSrc.includes(".png") && !imgSrc.includes(".PNG")
|
|
) {
|
|
return;
|
|
}
|
|
|
|
// Check X13WEBP_FORCE_WEBP_PCITURE
|
|
if ($(this).siblings("source").length && $(this).siblings("source").attr("srcset") !== undefined) {
|
|
if ($(this).siblings("source").attr("srcset").includes(".webp")) {
|
|
return;
|
|
}
|
|
}
|
|
|
|
x13images.push(imgSrc.trim());
|
|
});
|
|
|
|
$("picture > source").each(function () {
|
|
let imgSrc = $(this).attr("srcset") ?? "";
|
|
|
|
if (typeof x13webp_lazyload_enabled !== 'undefined' && x13webp_lazyload_enabled === '1') {
|
|
imgSrc = $(this).attr("data-srcset") ?? $(this).attr("srcset") ?? "";
|
|
}
|
|
|
|
if (imgSrc.includes(".webp")) return;
|
|
if (!imgSrc.includes(".jpg") && !imgSrc.includes(".JPG")
|
|
&& !imgSrc.includes(".jpeg") && !imgSrc.includes(".JPEG")
|
|
&& !imgSrc.includes(".png") && !imgSrc.includes(".PNG")
|
|
) {
|
|
return;
|
|
}
|
|
|
|
x13images.push(imgSrc.trim());
|
|
});
|
|
|
|
$("[style]").each(function () {
|
|
const bgImage = $(this).css("background-image");
|
|
|
|
if (bgImage.includes(".webp")) return;
|
|
if (!bgImage.includes(".jpg") && !bgImage.includes(".JPG")
|
|
&& !bgImage.includes(".jpeg") && !bgImage.includes(".JPEG")
|
|
&& !bgImage.includes(".png") && !bgImage.includes(".PNG")
|
|
) {
|
|
return;
|
|
}
|
|
|
|
let image = $(this)
|
|
.css("background-image")
|
|
.replace(/url\("([^"]+)"\)/, "$1");
|
|
|
|
x13images.push(image.trim());
|
|
});
|
|
|
|
if (typeof x13webp_lazyload_enabled !== 'undefined' && x13webp_lazyload_enabled === '1') {
|
|
$("[data-bg]").each(function () {
|
|
const bgImage = $(this).attr("data-bg");
|
|
|
|
if (bgImage.includes(".webp")) return;
|
|
if (!bgImage.includes(".jpg") && !bgImage.includes(".JPG")
|
|
&& !bgImage.includes(".jpeg") && !bgImage.includes(".JPEG")
|
|
&& !bgImage.includes(".png") && !bgImage.includes(".PNG")
|
|
) {
|
|
return;
|
|
}
|
|
|
|
x13images.push(bgImage.trim());
|
|
});
|
|
}
|
|
|
|
$("#product #thumbs_list a.fancybox").each(function () {
|
|
const href = $(this).attr("href");
|
|
if (href.length) {
|
|
x13images.push(href.trim());
|
|
}
|
|
});
|
|
|
|
$("#product .images-container .thumb").each(function () {
|
|
const medium = $(this).data("image-medium-src");
|
|
const large = $(this).data("image-large-src");
|
|
if (typeof medium !== 'undefined' && !medium.includes(".webp")) {
|
|
x13images.push(medium.trim());
|
|
}
|
|
if (typeof large !== 'undefined' && !large.includes(".webp")) {
|
|
x13images.push(large.trim());
|
|
}
|
|
});
|
|
|
|
if (x13images.length > 0) {
|
|
$.ajax({
|
|
url: x13webp_ajax_convert_url,
|
|
method: "POST",
|
|
data: {
|
|
x13images,
|
|
},
|
|
});
|
|
}
|
|
});
|