From bc12b1f378d4e1459a4f97c8144ddb7594a22b41 Mon Sep 17 00:00:00 2001 From: blankie Date: Fri, 8 Sep 2023 16:35:14 +1000 Subject: [PATCH] Update Image Loader Placeholder Remover to 1.19.0 - Add support for images blurred by attributes - Add specific support for blog.google --- Image Loader Placeholder Remover.user.js | 49 ++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/Image Loader Placeholder Remover.user.js b/Image Loader Placeholder Remover.user.js index 4af0157..211a5cc 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.18.0 +// @version 1.19.0 // @author blankie // @run-at document-end // @description Removes image loading placeholders @@ -107,6 +107,21 @@ function getLazyloaderClasses(element) { return classes; } +function getLazyloaderAttributes(element) { + let attributes = []; + + for (let attr of element.attributes) { + // Examples of loading: + // - https://blog.google/ + // - https://blog.google/threat-analysis-group/active-north-korean-campaign-targeting-security-researchers/ + if (/loading/.test(attr.name)) { + attributes.push(attr); + } + } + + return attributes; +} + function cloneLazyloaderTree(element, elementLazyLoaderClasses) { let topMostParent = null; let followingTopMostParent = element.parentElement; @@ -115,6 +130,9 @@ function cloneLazyloaderTree(element, elementLazyLoaderClasses) { while (followingTopMostParent.localName !== "body") { let clone = document.createElement(followingTopMostParent.localName); clone.classList.add(...getLazyloaderClasses(followingTopMostParent)); + for (let attr of getLazyloaderAttributes(followingTopMostParent)) { + clone.setAttribute(attr.name, attr.value); + } if (topMostParent) { clone.append(topMostParent); } @@ -128,6 +146,9 @@ function cloneLazyloaderTree(element, elementLazyLoaderClasses) { let clone = document.createElement(element.localName); clone.classList.add(...elementLazyLoaderClasses); + for (let attr of getLazyloaderAttributes(element)) { + clone.setAttribute(attr.name, attr.value); + } if (bottomMostChild) { bottomMostChild.append(clone); @@ -186,6 +207,8 @@ function unhideElement(element, lazyLoaderClasses) { // - https://www.404media.co/welcome-to-404-media/ // - https://restofworld.org/ // - https://restofworld.org/2023/parent-facing-matchmaking-apps-china/ + // - https://blog.google/ + // - https://blog.google/threat-analysis-group/active-north-korean-campaign-targeting-security-researchers/ if (classStyle.filter.includes("blur(")) { element.style.filter = classStyle.filter.replaceAll(/blur\(.+?\)/g, "blur(0px)"); } @@ -212,6 +235,11 @@ function removePlaceholder(img) { } let picture = img.closest("picture"); + // Examples of blurred images with proper URLs: + // - https://blog.google/ + // - https://blog.google/threat-analysis-group/active-north-korean-campaign-targeting-security-researchers/ + unhideElement(img, getLazyloaderClasses(img)); + // Example of a would've been viewable image being blurred: // https://www.washingtonpost.com/nation/2023/07/21/ocean-color-changing-climate-change/ if (window.location.host === "www.washingtonpost.com") { @@ -224,7 +252,6 @@ function removePlaceholder(img) { } let originalUrl = url; - if (window.location.host === "www.vice.com") { img.style.filter = "none"; picture.style.opacity = 1; @@ -246,7 +273,6 @@ function removePlaceholder(img) { } img.src = url; - unhideElement(img, getLazyloaderClasses(img)); // apparently, remaining s can fuck up image rendering (firefox still thinks that the contains an empty image?) // https://gizmodo.com/reddit-news-blackout-protest-is-finally-over-reddit-won-1850707509 @@ -336,4 +362,21 @@ if (window.location.host === "www.forbes.com") { progressiveImage.replaceWith(img); } } +} + +// https://blog.google/ +// https://blog.google/threat-analysis-group/active-north-korean-campaign-targeting-security-researchers/ +if (window.location.host === "blog.google") { + for (let img of document.querySelectorAll("img[data-loading]")) { + let data = JSON.parse(img.getAttribute("data-loading")); + let url = data.desktop || data.mobile; + img.src = url; + + if (!img.closest("a")) { + let wrapper = document.createElement("a"); + wrapper.href = url; + img.replaceWith(wrapper); + wrapper.append(img); + } + } } \ No newline at end of file