|
() => { |
|
return new Promise((resolve) => { |
|
const filterImage = (img) => { |
|
|
|
if (img.width < 100 && img.height < 100) return false; |
|
|
|
|
|
const rect = img.getBoundingClientRect(); |
|
if (rect.width === 0 || rect.height === 0) return false; |
|
|
|
|
|
if (img.classList.contains("icon") || img.classList.contains("thumbnail")) return false; |
|
|
|
|
|
if (img.src.includes("placeholder") || img.src.includes("icon")) return false; |
|
|
|
return true; |
|
}; |
|
|
|
const images = Array.from(document.querySelectorAll("img")).filter(filterImage); |
|
let imagesLeft = images.length; |
|
|
|
if (imagesLeft === 0) { |
|
resolve(); |
|
return; |
|
} |
|
|
|
const checkImage = (img) => { |
|
if (img.complete && img.naturalWidth !== 0) { |
|
img.setAttribute("width", img.naturalWidth); |
|
img.setAttribute("height", img.naturalHeight); |
|
imagesLeft--; |
|
if (imagesLeft === 0) resolve(); |
|
} |
|
}; |
|
|
|
images.forEach((img) => { |
|
checkImage(img); |
|
if (!img.complete) { |
|
img.onload = () => { |
|
checkImage(img); |
|
}; |
|
img.onerror = () => { |
|
imagesLeft--; |
|
if (imagesLeft === 0) resolve(); |
|
}; |
|
} |
|
}); |
|
|
|
|
|
|
|
resolve(); |
|
}); |
|
}; |
|
|