Update Image Loader Placeholder Remover to 1.13.0
- Automatically identify and remove image loaders, even from unknown sites - Add support for Wikihow
This commit is contained in:
parent
a00a99bcee
commit
45f190ebcd
|
@ -3,243 +3,218 @@
|
||||||
// @namespace blankie-scripts
|
// @namespace blankie-scripts
|
||||||
// @match http*://*/*
|
// @match http*://*/*
|
||||||
// @grant none
|
// @grant none
|
||||||
// @version 1.12.1
|
// @version 1.13.0
|
||||||
// @author blankie
|
// @author blankie
|
||||||
// @run-at document-end
|
// @run-at document-end
|
||||||
// @description Removes image loading placeholders
|
// @description Removes image loading placeholders
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
// https://closeronline.co.uk
|
"use strict";
|
||||||
// https://closeronline.co.uk/real-life/news/ever-used-excuses-documented-spreadsheet-man-used-expose-wife-s-lack-sex
|
|
||||||
function closeronline() {
|
|
||||||
for (element of document.querySelectorAll(".image-container")) {
|
|
||||||
let imageElement = element.querySelector("img");
|
|
||||||
let loadingElement = element.querySelector(".image-loading");
|
|
||||||
if (imageElement === null || loadingElement === null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (imageElement.attributes["data-src"] === undefined || imageElement.attributes["data-src"].value.length <= 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let url = new URL(imageElement.attributes["data-src"].value, location);
|
|
||||||
let dontAddLink = hasLinkParent(element);
|
|
||||||
|
|
||||||
if (!dontAddLink) {
|
function isUrlLike(url) {
|
||||||
let newImageElement = imageElement.cloneNode();
|
return url && /^(?:\/|https?:\/\/)\S+$/.test(url);
|
||||||
newImageElement.src = url.href;
|
|
||||||
newImageElement.style.opacity = 100;
|
|
||||||
newImageElement.style.display = "block";
|
|
||||||
url.search = "";
|
|
||||||
let imageWrapper = document.createElement("a");
|
|
||||||
imageWrapper.href = url.href;
|
|
||||||
imageWrapper.appendChild(newImageElement);
|
|
||||||
imageElement.replaceWith(imageWrapper);
|
|
||||||
} else {
|
|
||||||
imageElement.src = url.href;
|
|
||||||
imageElement.style.opacity = 100;
|
|
||||||
imageElement.style.display = "block";
|
|
||||||
}
|
|
||||||
|
|
||||||
loadingElement.remove();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
function findUrl(element) {
|
||||||
// https://www.indiatoday.in
|
if (window.location.host === "www.vice.com") {
|
||||||
// https://www.indiatoday.in/technology/news/story/vivo-v25-pro-launched-in-india-price-starts-from-rs-35-999-1988971-2022-08-17
|
let picture = element.parentElement;
|
||||||
function indiatoday() {
|
let source = picture && picture.localName === "picture" ? picture.querySelector("source") : null;
|
||||||
for (element of document.querySelectorAll("img.lazyload")) {
|
if (source) {
|
||||||
if (element.attributes["data-src"] === undefined || element.attributes["data-src"].value.length <= 0) {
|
return source.srcset;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let url = new URL(element.attributes["data-src"].value, location);
|
|
||||||
let dontAddLink = hasLinkParent(element);
|
|
||||||
|
|
||||||
if (!dontAddLink) {
|
|
||||||
let newElement = element.cloneNode();
|
|
||||||
newElement.src = url.href;
|
|
||||||
url.search = "";
|
|
||||||
let wrapper = document.createElement("a");
|
|
||||||
wrapper.href = url.href;
|
|
||||||
wrapper.appendChild(newElement);
|
|
||||||
element.replaceWith(wrapper);
|
|
||||||
} else {
|
|
||||||
element.src = url.href;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// TODO add support for home page, i'm too lazy
|
// Examples of data-src:
|
||||||
// https://www.vice.com/en/article/dy73n7/ehallpass-1000-thousand-schools-monitor-bathroom
|
// - https://closeronline.co.uk
|
||||||
function vice() {
|
// - https://closeronline.co.uk/real-life/news/ever-used-excuses-documented-spreadsheet-man-used-expose-wife-s-lack-sex
|
||||||
for (element of document.querySelectorAll(".lazyloader--lowres")) {
|
// - https://daramiblog.com
|
||||||
let sourceElement = element.querySelector("source");
|
// - https://daramiblog.com/how-to-group-irregular-verbs-for-more-efficient-learning/
|
||||||
let imgElement = element.querySelector("img");
|
// - https://www.bleepingcomputer.com/
|
||||||
if (sourceElement === null || imgElement === null) {
|
// - https://www.bleepingcomputer.com/news/microsoft/windows-11-snipping-tool-privacy-bug-exposes-cropped-image-content/
|
||||||
|
// - https://blog.joshumax.me/general/2021/08/11/running-doom-on-captioncall.html
|
||||||
|
// - https://legendsoflocalization.com/common-problems-when-translating-games-into-japanese/
|
||||||
|
// - https://knowyourmeme.com/
|
||||||
|
// - https://knowyourmeme.com/memes/saddam-husseins-hiding-place
|
||||||
|
if (isUrlLike(element.dataset.src)) {
|
||||||
|
return element.dataset.src;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let attr of element.attributes) {
|
||||||
|
// Examples of lazy:
|
||||||
|
// - https://daramiblog.com/
|
||||||
|
// - https://daramiblog.com/how-to-group-irregular-verbs-for-more-efficient-learning/
|
||||||
|
// - https://www.theautopian.com/
|
||||||
|
// - https://www.theautopian.com/nobody-wants-touch-screen-glove-box-latches-and-it-needs-to-stop-now/
|
||||||
|
// - https://vulcan.io/blog/
|
||||||
|
// - https://vulcan.io/blog/ai-hallucinations-package-risk
|
||||||
|
// Examples of src:
|
||||||
|
// - https://vulcan.io/blog/
|
||||||
|
// - https://vulcan.io/blog/ai-hallucinations-package-risk
|
||||||
|
// Examples of loading:
|
||||||
|
// - https://closeronline.co.uk
|
||||||
|
// - https://closeronline.co.uk/real-life/news/ever-used-excuses-documented-spreadsheet-man-used-expose-wife-s-lack-sex
|
||||||
|
// Examples of original:
|
||||||
|
// - https://www.pcgamer.com/
|
||||||
|
// - https://www.pcgamer.com/windows-95-theme-for-windows-10/
|
||||||
|
if (!attr.name.includes("lazy") && !(attr.name.includes("src") && attr.name !== "src") && !attr.name.includes("loading") && !attr.name.includes("original")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let url = new URL(sourceElement.srcset, location);
|
if (!isUrlLike(attr.value)) {
|
||||||
url.search = "";
|
continue;
|
||||||
|
|
||||||
let newImgElement = imgElement.cloneNode();
|
|
||||||
newImgElement.src = url.href;
|
|
||||||
newImgElement.style.filter = "none";
|
|
||||||
let imgWrapper = document.createElement("a");
|
|
||||||
imgWrapper.href = url.href;
|
|
||||||
imgWrapper.appendChild(newImgElement);
|
|
||||||
imgElement.replaceWith(imgWrapper);
|
|
||||||
|
|
||||||
for (sourceElement of element.querySelectorAll("source")) {
|
|
||||||
sourceElement.remove();
|
|
||||||
}
|
}
|
||||||
|
return attr.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function unhideElement(element) {
|
||||||
|
let style = getComputedStyle(element);
|
||||||
|
|
||||||
|
// Examples of opacity:
|
||||||
|
// - https://closeronline.co.uk
|
||||||
|
// - https://closeronline.co.uk/real-life/news/ever-used-excuses-documented-spreadsheet-man-used-expose-wife-s-lack-sex
|
||||||
|
// - https://www.vice.com/en/article/dy73n7/ehallpass-1000-thousand-schools-monitor-bathroom
|
||||||
|
// - https://daramiblog.com/
|
||||||
|
// - https://daramiblog.com/how-to-group-irregular-verbs-for-more-efficient-learning/
|
||||||
|
// - https://www.wired.com/
|
||||||
|
// - https://www.wired.com/story/researcher-fooled-a-google-ai-into-thinking-a-rifle-was-a-helicopter/
|
||||||
|
if (style.opacity === "0") {
|
||||||
element.style.opacity = 1;
|
element.style.opacity = 1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// https://daramiblog.com/
|
// Examples of display:
|
||||||
// https://daramiblog.com/how-to-group-irregular-verbs-for-more-efficient-learning/
|
// - https://closeronline.co.uk
|
||||||
function wordpress() {
|
// - https://closeronline.co.uk/real-life/news/ever-used-excuses-documented-spreadsheet-man-used-expose-wife-s-lack-sex
|
||||||
for (element of document.querySelectorAll("img.lazyload.wp-post-image")) {
|
if (style.display === "none") {
|
||||||
if (element.attributes["data-src"] === undefined || element.attributes["data-src"].value.length <= 0) {
|
element.style.display = "block";
|
||||||
continue;
|
|
||||||
}
|
|
||||||
element.src = element.attributes["data-src"].value;
|
|
||||||
element.style.opacity = 100;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://www.pcgamer.com/
|
function isElementLazyloader(element) {
|
||||||
// https://www.pcgamer.com/windows-95-theme-for-windows-10/
|
if (element.dataset.src) {
|
||||||
function pcgamer() {
|
return true;
|
||||||
// look into video carousels?
|
|
||||||
for (element of document.querySelectorAll("img.lazy-image-van")) {
|
|
||||||
let originalUrl = element.getAttribute("data-original-mos");
|
|
||||||
if (originalUrl === null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
element.src = originalUrl;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// https://www.wired.com/
|
for (let className of element.classList) {
|
||||||
// https://www.wired.com/story/researcher-fooled-a-google-ai-into-thinking-a-rifle-was-a-helicopter/
|
// Examples of loading:
|
||||||
function wired() {
|
// - https://closeronline.co.uk
|
||||||
let style = document.createElement("style");
|
// - https://closeronline.co.uk/real-life/news/ever-used-excuses-documented-spreadsheet-man-used-expose-wife-s-lack-sex
|
||||||
style.innerText = ".gbVKFf {opacity: 1}";
|
// Examples of lazy:
|
||||||
document.head.appendChild(style);
|
// - https://www.vice.com/en/article/dy73n7/ehallpass-1000-thousand-schools-monitor-bathroom
|
||||||
}
|
// - https://www.pcgamer.com/
|
||||||
|
// - https://www.pcgamer.com/windows-95-theme-for-windows-10/
|
||||||
// https://www.theautopian.com/
|
// - https://www.theautopian.com/
|
||||||
// https://www.theautopian.com/nobody-wants-touch-screen-glove-box-latches-and-it-needs-to-stop-now/
|
// - https://www.theautopian.com/nobody-wants-touch-screen-glove-box-latches-and-it-needs-to-stop-now/
|
||||||
function theautopian() {
|
// - https://vulcan.io/blog/
|
||||||
for (element of document.querySelectorAll("img[data-jzl-lazy-src]")) {
|
// - https://vulcan.io/blog/ai-hallucinations-package-risk
|
||||||
let originalUrl = element.getAttribute("data-jzl-lazy-src");
|
// Examples of responsive:
|
||||||
if (originalUrl === null) {
|
// - https://www.vice.com/en/article/dy73n7/ehallpass-1000-thousand-schools-monitor-bathroom
|
||||||
continue;
|
// - https://www.wired.com (it's a parent of lazyloaded <img>s)
|
||||||
}
|
// - https://www.wired.com/story/researcher-fooled-a-google-ai-into-thinking-a-rifle-was-a-helicopter/ (it's a parent of lazyloaded <img>s)
|
||||||
element.src = originalUrl;
|
if (className.includes("loading") || className.includes("lazy") || className.includes("responsive")) {
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://www.bleepingcomputer.com/
|
|
||||||
// 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 = !hasLinkParent(element);
|
|
||||||
const dataSrc = element.getAttribute("data-src");
|
|
||||||
if (dataSrc === null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const url = new URL(dataSrc, location);
|
|
||||||
if (addLink) {
|
|
||||||
const newElement = element.cloneNode();
|
|
||||||
newElement.src = url.href;
|
|
||||||
const wrapper = document.createElement("a");
|
|
||||||
wrapper.href = url.href;
|
|
||||||
wrapper.appendChild(newElement);
|
|
||||||
element.replaceWith(wrapper);
|
|
||||||
} else {
|
|
||||||
element.src = url.href;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://securelist.com/
|
|
||||||
// https://securelist.com/cosmicstrand-uefi-firmware-rootkit/106973/
|
|
||||||
function securelist() {
|
|
||||||
let style = document.createElement("style");
|
|
||||||
style.innerText = "img {opacity: 1 !important;}";
|
|
||||||
document.head.appendChild(style);
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://vulcan.io/blog/
|
|
||||||
// https://vulcan.io/blog/ai-hallucinations-package-risk
|
|
||||||
function vulcan() {
|
|
||||||
for (let element of document.querySelectorAll("img[nitro-lazy-src]")) {
|
|
||||||
const addLink = !hasLinkParent(element);
|
|
||||||
const url = new URL(element.getAttribute("nitro-lazy-src"), location);
|
|
||||||
|
|
||||||
if (addLink) {
|
|
||||||
const newElement = element.cloneNode();
|
|
||||||
newElement.src = url.href;
|
|
||||||
const wrapper = document.createElement("a");
|
|
||||||
wrapper.href = url.href;
|
|
||||||
wrapper.appendChild(newElement);
|
|
||||||
element.replaceWith(wrapper);
|
|
||||||
} else {
|
|
||||||
element.src = url.href;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://blog.joshumax.me/general/2021/08/11/running-doom-on-captioncall.html
|
|
||||||
// https://legendsoflocalization.com/common-problems-when-translating-games-into-japanese/
|
|
||||||
// https://knowyourmeme.com/
|
|
||||||
// https://knowyourmeme.com/memes/saddam-husseins-hiding-place
|
|
||||||
function datasrc() {
|
|
||||||
for (let element of document.querySelectorAll("img[data-src]")) {
|
|
||||||
const addLink = !hasLinkParent(element);
|
|
||||||
const url = new URL(element.getAttribute("data-src"), location);
|
|
||||||
|
|
||||||
if (addLink) {
|
|
||||||
const newElement = element.cloneNode();
|
|
||||||
newElement.src = url.href;
|
|
||||||
const wrapper = document.createElement("a");
|
|
||||||
wrapper.href = url.href;
|
|
||||||
wrapper.appendChild(newElement);
|
|
||||||
element.replaceWith(wrapper);
|
|
||||||
} else {
|
|
||||||
element.src = url.href;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function hasLinkParent(element) {
|
|
||||||
while (element) {
|
|
||||||
if (element.localName === "a") {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
element = element.parentElement;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (location.host) {
|
|
||||||
case "closeronline.co.uk": closeronline(); break;
|
|
||||||
case "www.indiatoday.in": indiatoday(); break;
|
|
||||||
case "www.vice.com": vice(); break;
|
|
||||||
case "www.pcgamer.com": pcgamer(); break;
|
|
||||||
case "www.wired.com": wired(); break;
|
|
||||||
case "www.theautopian.com": theautopian(); break;
|
|
||||||
case "www.bleepingcomputer.com": bleepingcomputer(); break;
|
|
||||||
case "securelist.com": securelist(); break;
|
|
||||||
case "vulcan.io": vulcan(); break;
|
|
||||||
|
|
||||||
case "blog.joshumax.me":
|
|
||||||
case "knowyourmeme.com":
|
|
||||||
case "legendsoflocalization.com":
|
|
||||||
datasrc();
|
|
||||||
break;
|
|
||||||
|
|
||||||
default: wordpress(); break;
|
function removePlaceholder(img) {
|
||||||
};
|
let hasLinkParent = false;
|
||||||
|
let parentElement = img.parentElement;
|
||||||
|
while (parentElement) {
|
||||||
|
hasLinkParent = hasLinkParent || parentElement.localName === "a";
|
||||||
|
// 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)) {
|
||||||
|
unhideElement(parentElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
parentElement = parentElement.parentElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
let url = findUrl(img);
|
||||||
|
if (!url) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let originalUrl = url;
|
||||||
|
|
||||||
|
|
||||||
|
if (window.location.host === "www.vice.com") {
|
||||||
|
let picture = img.parentElement;
|
||||||
|
|
||||||
|
img.style.filter = "none";
|
||||||
|
picture.style.opacity = 1;
|
||||||
|
|
||||||
|
let urlObject = new URL(url, window.location);
|
||||||
|
urlObject.search = "";
|
||||||
|
originalUrl = urlObject.href;
|
||||||
|
urlObject.search = "?resize=1024:*";
|
||||||
|
url = urlObject.href;
|
||||||
|
|
||||||
|
for (let source of picture.querySelectorAll("source")) {
|
||||||
|
source.remove();
|
||||||
|
}
|
||||||
|
} else if (window.location.host === "closeronline.co.uk") {
|
||||||
|
let urlObject = new URL(url, window.location);
|
||||||
|
urlObject.search = "";
|
||||||
|
originalUrl = urlObject.href;
|
||||||
|
img.closest(".image-container").querySelector(".image-loading").remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
img.src = url;
|
||||||
|
unhideElement(img);
|
||||||
|
|
||||||
|
if (!hasLinkParent) {
|
||||||
|
let wrapper = document.createElement("a");
|
||||||
|
img.replaceWith(wrapper);
|
||||||
|
wrapper.href = originalUrl;
|
||||||
|
wrapper.appendChild(img);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for (let img of document.querySelectorAll("img")) {
|
||||||
|
removePlaceholder(img);
|
||||||
|
}
|
||||||
|
// the reason we check for mutations for 1s after the page loads is because of <noscript> elements being faked by umatrix
|
||||||
|
let observer = new MutationObserver(function (mutations) {
|
||||||
|
for (let mutation of mutations) {
|
||||||
|
if (mutation.type !== "childList") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (let node of mutation.addedNodes) {
|
||||||
|
if (node.nodeType !== 1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (let img of node.querySelectorAll("img")) {
|
||||||
|
removePlaceholder(img);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
observer.observe(document.body, {childList: true, subtree: true});
|
||||||
|
setTimeout(function() {
|
||||||
|
observer.disconnect();
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// https://www.wikihow.com/Tie-Your-Shoes
|
||||||
|
if (window.location.host === "www.wikihow.com") {
|
||||||
|
let style = document.createElement("style");
|
||||||
|
style.textContent = ".image {display: block !important}";
|
||||||
|
document.head.appendChild(style);
|
||||||
|
|
||||||
|
for (let videoPlayer of document.querySelectorAll(".video-player")) {
|
||||||
|
videoPlayer.querySelector(".m-video-controls").remove();
|
||||||
|
|
||||||
|
let video = videoPlayer.querySelector("video");
|
||||||
|
video.controls = 1;
|
||||||
|
video.src = `/video${video.dataset.src}`;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue