Update Image Loader Placeholder Remover to 1.22.0

- Add specific support for www.independent.co.uk
- Fix wrapping <img>s with <a>
This commit is contained in:
blankie 2023-09-14 15:58:02 +10:00
parent 29d26e7153
commit 75f8ab9924
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
1 changed files with 25 additions and 9 deletions

View File

@ -3,7 +3,7 @@
// @namespace blankie-scripts // @namespace blankie-scripts
// @match http*://*/* // @match http*://*/*
// @grant none // @grant none
// @version 1.21.0 // @version 1.22.0
// @author blankie // @author blankie
// @run-at document-end // @run-at document-end
// @description Removes image loading placeholders // @description Removes image loading placeholders
@ -245,15 +245,14 @@ function unhideElement(element, lazyLoaderClasses) {
} }
function wrapImage(img, url) { function wrapImage(img, url) {
if (img.closest("a")) { if (img.closest("a") || !url) {
return img; return;
} }
let wrapper = document.createElement("a"); let wrapper = document.createElement("a");
img.replaceWith(wrapper); img.replaceWith(wrapper);
wrapper.href = url; wrapper.href = url;
wrapper.append(img); wrapper.append(img);
return wrapper;
} }
@ -331,10 +330,8 @@ function removePlaceholder(img) {
} }
} }
if (originalUrl) {
wrapImage(img, originalUrl); wrapImage(img, originalUrl);
} }
}
@ -390,7 +387,6 @@ if (window.location.host === "www.forbes.com") {
img.setAttribute(attr.name, attr.value); img.setAttribute(attr.name, attr.value);
} }
img.src = url; img.src = url;
img.append(...progressiveImage.childNodes);
let placeholder = progressiveImage.closest(".image-embed__placeholder"); let placeholder = progressiveImage.closest(".image-embed__placeholder");
if (placeholder) { if (placeholder) {
@ -398,6 +394,26 @@ if (window.location.host === "www.forbes.com") {
placeholder.style.paddingTop = 0; placeholder.style.paddingTop = 0;
} }
progressiveImage.replaceWith(wrapImage(img, url)); progressiveImage.replaceWith(img);
wrapImage(img, url);
}
}
// https://www.independent.co.uk/news/world/americas/abortion-lawsuit-tennessee-idaho-oklahoma-b2410109.html
if (window.location.host === "www.independent.co.uk") {
for (let ampImg of document.querySelectorAll("amp-img")) {
let img = document.createElement("img");
for (let attr of ampImg.attributes) {
img.setAttribute(attr.name, attr.value);
}
// fix some images blowing past the viewport
if (!img.style.width && !img.style.height) {
img.style.width = "100%";
img.style.height = "auto";
}
ampImg.replaceWith(img);
wrapImage(img, img.src);
} }
} }