From 1b10ebe803f73ba16c29657fa736d23262709601 Mon Sep 17 00:00:00 2001 From: blankie Date: Fri, 4 Aug 2023 17:15:45 +1000 Subject: [PATCH] Update Image Loader Placeholder Remover to 1.14.0 - Remove lazyloader-related classes from images and their parents --- Image Loader Placeholder Remover.user.js | 25 +++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/Image Loader Placeholder Remover.user.js b/Image Loader Placeholder Remover.user.js index 15ca90d..59e57df 100644 --- a/Image Loader Placeholder Remover.user.js +++ b/Image Loader Placeholder Remover.user.js @@ -3,7 +3,7 @@ // @namespace blankie-scripts // @match http*://*/* // @grant none -// @version 1.13.0 +// @version 1.14.0 // @author blankie // @run-at document-end // @description Removes image loading placeholders @@ -90,10 +90,8 @@ function unhideElement(element) { } } -function isElementLazyloader(element) { - if (element.dataset.src) { - return true; - } +function getLazyloaderClasses(element) { + let classes = []; for (let className of element.classList) { // 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.wired.com (it's a parent of lazyloaded s) // - https://www.wired.com/story/researcher-fooled-a-google-ai-into-thinking-a-rifle-was-a-helicopter/ (it's a parent of lazyloaded s) - if (className.includes("loading") || className.includes("lazy") || className.includes("responsive")) { - return true; + // Examples of preload: + // - 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: // - https://www.wired.com/ // - 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); + // 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; @@ -167,6 +173,7 @@ function removePlaceholder(img) { img.src = url; unhideElement(img); + img.classList.remove(...getLazyloaderClasses(img)); if (!hasLinkParent) { let wrapper = document.createElement("a");