Update Image Loader Placeholder Remover to 1.22.2
- Fix placeholders not being removed on bloomberg.com
This commit is contained in:
parent
88315b095b
commit
077ee05b00
|
@ -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")) {
|
||||
// the reason we reunhide images after 1s after the page loads is because of <noscript> elements being faked by umatrix
|
||||
setTimeout(function() {
|
||||
for (let img of document.querySelectorAll("img")) {
|
||||
removePlaceholder(img);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
observer.observe(document.body, {childList: true, subtree: true});
|
||||
setTimeout(function() {
|
||||
observer.disconnect();
|
||||
}, 1000);
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue