Update Image Loader Placeholder Remover to 1.14.0
- Remove lazyloader-related classes from images and their parents
This commit is contained in:
parent
1c576bf970
commit
1b10ebe803
|
@ -3,7 +3,7 @@
|
||||||
// @namespace blankie-scripts
|
// @namespace blankie-scripts
|
||||||
// @match http*://*/*
|
// @match http*://*/*
|
||||||
// @grant none
|
// @grant none
|
||||||
// @version 1.13.0
|
// @version 1.14.0
|
||||||
// @author blankie
|
// @author blankie
|
||||||
// @run-at document-end
|
// @run-at document-end
|
||||||
// @description Removes image loading placeholders
|
// @description Removes image loading placeholders
|
||||||
|
@ -90,10 +90,8 @@ function unhideElement(element) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function isElementLazyloader(element) {
|
function getLazyloaderClasses(element) {
|
||||||
if (element.dataset.src) {
|
let classes = [];
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let className of element.classList) {
|
for (let className of element.classList) {
|
||||||
// Examples of loading:
|
// Examples of loading:
|
||||||
|
@ -111,12 +109,15 @@ function isElementLazyloader(element) {
|
||||||
// - https://www.vice.com/en/article/dy73n7/ehallpass-1000-thousand-schools-monitor-bathroom
|
// - https://www.vice.com/en/article/dy73n7/ehallpass-1000-thousand-schools-monitor-bathroom
|
||||||
// - https://www.wired.com (it's a parent of lazyloaded <img>s)
|
// - https://www.wired.com (it's a parent of lazyloaded <img>s)
|
||||||
// - https://www.wired.com/story/researcher-fooled-a-google-ai-into-thinking-a-rifle-was-a-helicopter/ (it's a parent of lazyloaded <img>s)
|
// - https://www.wired.com/story/researcher-fooled-a-google-ai-into-thinking-a-rifle-was-a-helicopter/ (it's a parent of lazyloaded <img>s)
|
||||||
if (className.includes("loading") || className.includes("lazy") || className.includes("responsive")) {
|
// Examples of preload:
|
||||||
return true;
|
// - https://restofworld.org/
|
||||||
|
// - https://restofworld.org/2023/parent-facing-matchmaking-apps-china/
|
||||||
|
if (className.includes("loading") || className.includes("lazy") || className.includes("responsive") || className.includes("preload")) {
|
||||||
|
classes.push(className);;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -129,8 +130,13 @@ function removePlaceholder(img) {
|
||||||
// Examples of hidden parents:
|
// Examples of hidden parents:
|
||||||
// - https://www.wired.com/
|
// - https://www.wired.com/
|
||||||
// - https://www.wired.com/story/researcher-fooled-a-google-ai-into-thinking-a-rifle-was-a-helicopter/
|
// - https://www.wired.com/story/researcher-fooled-a-google-ai-into-thinking-a-rifle-was-a-helicopter/
|
||||||
if (isElementLazyloader(parentElement)) {
|
let lazyLoaderClasses = getLazyloaderClasses(parentElement);
|
||||||
|
if (lazyLoaderClasses) {
|
||||||
unhideElement(parentElement);
|
unhideElement(parentElement);
|
||||||
|
// Examples of pages with a blur applied to lazyloader classes:
|
||||||
|
// - https://restofworld.org/
|
||||||
|
// - https://restofworld.org/2023/parent-facing-matchmaking-apps-china/
|
||||||
|
parentElement.classList.remove(...lazyLoaderClasses);
|
||||||
}
|
}
|
||||||
|
|
||||||
parentElement = parentElement.parentElement;
|
parentElement = parentElement.parentElement;
|
||||||
|
@ -167,6 +173,7 @@ function removePlaceholder(img) {
|
||||||
|
|
||||||
img.src = url;
|
img.src = url;
|
||||||
unhideElement(img);
|
unhideElement(img);
|
||||||
|
img.classList.remove(...getLazyloaderClasses(img));
|
||||||
|
|
||||||
if (!hasLinkParent) {
|
if (!hasLinkParent) {
|
||||||
let wrapper = document.createElement("a");
|
let wrapper = document.createElement("a");
|
||||||
|
|
Loading…
Reference in New Issue