From 0bbf671a66dc8ae7a287a6bf11b323340f26a1dc Mon Sep 17 00:00:00 2001 From: blankie Date: Sat, 22 Jul 2023 12:39:11 +1000 Subject: [PATCH] Update Image Loader Placeholder Remover to 1.12.1 - Properly check if an image has a link parent. This can be seen on https://legendsoflocalization.com/an-inside-look-at-video-game-control-codes/#related --- Image Loader Placeholder Remover.user.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/Image Loader Placeholder Remover.user.js b/Image Loader Placeholder Remover.user.js index c811ff8..1fe24e9 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.12.0 +// @version 1.12.1 // @author blankie // @run-at document-end // @description Removes image loading placeholders @@ -22,7 +22,7 @@ function closeronline() { continue; } let url = new URL(imageElement.attributes["data-src"].value, location); - let dontAddLink = element.parentNode.tagName === "A"; + let dontAddLink = hasLinkParent(element); if (!dontAddLink) { let newImageElement = imageElement.cloneNode(); @@ -52,8 +52,7 @@ function indiatoday() { continue; } let url = new URL(element.attributes["data-src"].value, location); - let dontAddLink = element.parentNode.tagName === "A" || - (element.parentNode.tagName === "DIV" && element.parentNode.classList.contains("reporter_img")); + let dontAddLink = hasLinkParent(element); if (!dontAddLink) { let newElement = element.cloneNode(); @@ -145,7 +144,7 @@ function theautopian() { // https://www.bleepingcomputer.com/news/microsoft/windows-11-snipping-tool-privacy-bug-exposes-cropped-image-content/ function bleepingcomputer() { for (element of document.querySelectorAll(".b-lazy")) { - const addLink = element.parentNode.tagName !== "A"; + const addLink = !hasLinkParent(element); const dataSrc = element.getAttribute("data-src"); if (dataSrc === null) { return; @@ -177,7 +176,7 @@ function securelist() { // https://vulcan.io/blog/ai-hallucinations-package-risk function vulcan() { for (let element of document.querySelectorAll("img[nitro-lazy-src]")) { - const addLink = element.parentNode.tagName !== "A"; + const addLink = !hasLinkParent(element); const url = new URL(element.getAttribute("nitro-lazy-src"), location); if (addLink) { @@ -199,7 +198,7 @@ function vulcan() { // https://knowyourmeme.com/memes/saddam-husseins-hiding-place function datasrc() { for (let element of document.querySelectorAll("img[data-src]")) { - const addLink = element.parentNode.tagName !== "A"; + const addLink = !hasLinkParent(element); const url = new URL(element.getAttribute("data-src"), location); if (addLink) { @@ -215,6 +214,16 @@ function datasrc() { } } +function hasLinkParent(element) { + while (element) { + if (element.localName === "a") { + return true; + } + element = element.parentElement; + } + return false; +} + switch (location.host) { case "closeronline.co.uk": closeronline(); break; case "www.indiatoday.in": indiatoday(); break;