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
This commit is contained in:
blankie 2023-07-22 12:39:11 +10:00
parent dcd9c57744
commit 0bbf671a66
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
1 changed files with 16 additions and 7 deletions

View File

@ -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;