57 lines
1.3 KiB
JavaScript
57 lines
1.3 KiB
JavaScript
$(document).ready(() => {
|
|
let x13images = [];
|
|
|
|
$("img").each(function () {
|
|
const imgSrc = $(this).attr("data-src") ?? $(this).attr("data-original") ?? $(this).attr("src");
|
|
|
|
if (!imgSrc) return;
|
|
if (imgSrc.includes(".webp")) return;
|
|
|
|
if ($(this).siblings("source").length && $(this).siblings("source").attr("srcset") !== undefined) {
|
|
if ($(this).siblings("source").attr("srcset").includes(".webp")) {
|
|
return;
|
|
}
|
|
}
|
|
|
|
x13images.push(imgSrc.trim());
|
|
});
|
|
|
|
$("[style]").each(function () {
|
|
const bgImage = $(this).css("background-image");
|
|
|
|
if (bgImage.includes(".webp") || (!bgImage.includes(".jpg") && !bgImage.includes(".png"))) {
|
|
return;
|
|
}
|
|
|
|
let image = $(this)
|
|
.css("background-image")
|
|
.replace(/url\("([^"]+)"\)/, "$1");
|
|
x13images.push(image.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') {
|
|
x13images.push(medium.trim());
|
|
}
|
|
if (typeof large !== 'undefined') {
|
|
x13images.push(large.trim());
|
|
}
|
|
});
|
|
|
|
$.ajax({
|
|
url: x13webp_ajax_convert_url,
|
|
method: "POST",
|
|
data: {
|
|
x13images,
|
|
},
|
|
});
|
|
});
|