Update Image Loader Placeholder Remover to 1.22.2

- Fix placeholders not being removed on bloomberg.com
This commit is contained in:
blankie 2023-10-05 09:06:08 +11:00
parent 88315b095b
commit 077ee05b00
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
1 changed files with 18 additions and 27 deletions

View File

@ -4,7 +4,7 @@
// @match http*://*/*
// @exclude-match http*://solar.lowtechmagazine.com/*
// @grant none
// @version 1.22.1
// @version 1.22.2
// @author blankie
// @run-at document-end
// @description Removes image loading placeholders
@ -126,6 +126,9 @@ function getLazyloaderClasses(element) {
// Examples of image (though admittedly a hack for cloneLazyloaderTree):
// - https://restofworld.org/
// - https://restofworld.org/2023/parent-facing-matchmaking-apps-china/
// Example of img:
// - https://www.bloomberg.com/news/features/2023-05-11/the-plot-to-steal-the-secret-coke-can-liner-formula
// - https://www.bloomberg.com/news/features/2023-09-28/google-user-data-is-police-s-top-shortcut-for-solving-crimes
if (/loading|lazy|responsive|preload|placeholder|image/.test(className)) {
classes.push(className);
}
@ -138,11 +141,15 @@ function getLazyloaderAttributes(element) {
let attributes = [];
for (let attr of element.attributes) {
if (attr.name === "class") {
continue;
}
// Examples of loading in name:
// - https://blog.google/
// - https://blog.google/threat-analysis-group/active-north-korean-campaign-targeting-security-researchers/
// Example of img in value:
// https://www.bloomberg.com/news/features/2023-05-11/the-plot-to-steal-the-secret-coke-can-liner-formula
// Examples of img in value:
// - https://www.bloomberg.com/news/features/2023-05-11/the-plot-to-steal-the-secret-coke-can-liner-formula
// - https://www.bloomberg.com/news/features/2023-09-28/google-user-data-is-police-s-top-shortcut-for-solving-crimes
if (/loading/.test(attr.name) || /img/.test(attr.value)) {
attributes.push(attr);
}
@ -238,6 +245,9 @@ function unhideElement(element, lazyLoaderClasses) {
// - https://restofworld.org/2023/parent-facing-matchmaking-apps-china/
// - https://blog.google/
// - https://blog.google/threat-analysis-group/active-north-korean-campaign-targeting-security-researchers/
// - https://www.bloomberg.com/news/features/2023-05-11/the-plot-to-steal-the-secret-coke-can-liner-formula
// - https://www.bloomberg.com/news/features/2023-09-28/google-user-data-is-police-s-top-shortcut-for-solving-crimes
// - https://www.washingtonpost.com/nation/2023/07/21/ocean-color-changing-climate-change/
if (classStyle.filter.includes("blur(")) {
element.style.filter = classStyle.filter.replaceAll(/blur\(.+?\)/g, "blur(0px)");
}
@ -273,11 +283,7 @@ function removePlaceholder(img) {
}
let picture = img.closest("picture");
// Example of a would've been viewable image being blurred:
// https://www.washingtonpost.com/nation/2023/07/21/ocean-color-changing-climate-change/
if (window.location.host === "www.washingtonpost.com") {
img.parentElement.style.filter = img.parentElement.style.filter.replaceAll(/blur\(.+?\)/g, "blur(0)");
}
unhideElement(img, getLazyloaderClasses(img));
let srcset = findSrcset(img);
let url = findUrl(img);
@ -309,7 +315,6 @@ function removePlaceholder(img) {
}
}
unhideElement(img, getLazyloaderClasses(img));
if (srcset) {
img.srcset = srcset;
}
@ -339,25 +344,11 @@ function removePlaceholder(img) {
for (let img of document.querySelectorAll("img")) {
removePlaceholder(img);
}
// the reason we check for mutations for 1s after the page loads is because of <noscript> elements being faked by umatrix
let observer = new MutationObserver(function (mutations) {
for (let mutation of mutations) {
if (mutation.type !== "childList") {
continue;
}
for (let node of mutation.addedNodes) {
if (node.nodeType !== 1) {
continue;
}
for (let img of node.querySelectorAll("img")) {
removePlaceholder(img);
}
}
}
});
observer.observe(document.body, {childList: true, subtree: true});
// the reason we reunhide images after 1s after the page loads is because of <noscript> elements being faked by umatrix
setTimeout(function() {
observer.disconnect();
for (let img of document.querySelectorAll("img")) {
removePlaceholder(img);
}
}, 1000);