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;