# HG changeset patch # User nanaya # Date 1596710389 -32400 # Node ID 9dc1be1a6c7a2511463882601b2c38c808c2f5ea # Parent 5a3a269c5e6fd828acc62362af40811b58f27acd Bye image lazy loading on pixiv fanbox diff -r 5a3a269c5e6f -r 9dc1be1a6c7a pixiv-fanbox-unlazy.user.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pixiv-fanbox-unlazy.user.js Thu Aug 06 19:39:49 2020 +0900 @@ -0,0 +1,66 @@ +// ==UserScript== +// @name pixiv fanbox no lazy loading image +// @namespace https://myconan.net +// @version 1.0.0 +// @description Lazy loading is bad for environment. Disable it. +// @author nanaya +// @match https://tweetdeck.twitter.com/* +// @grant none +// @downloadURL https://hg.sr.ht/~nanaya/ec-userscripts/raw/pixiv-fanbox-unlazy.user.js?rev=tip +// ==/UserScript== + +;(function () { + 'use strict' + + var imageUrlPrefix = 'https://downloads.fanbox.cc/images/post/' + + // loop through passed nodes (or body if called without arguments) + var run = function (nodes) { + if (nodes == null) { + nodes = [document.body] + } + + for (var i = 0; i < nodes.length; i++) { + // first try fixing itself + fix(nodes[i]) + + // and then find all the links inside + var links = nodes[i].querySelectorAll(`[href^="${imageUrlPrefix}"]`) + + for (var j = 0; j < links.length; j++) { + fix(links[j]) + } + } + } + + var fix = function (link) { + var href = link.href + + // basic sanity check + if (typeof href !== 'string' || !href.startsWith(imageUrlPrefix)) { + return + } + + // don't run again if already run on passed link + if (link._ecUserscript) { + return + } + link._ecUserscript = true + + link.innerHTML = `` + } + + var onMutate = function (mutations) { + for (var mutation in mutations) { + run(mutation.addedNodes) + } + } + + // the observer + var observer = new window.MutationObserver(onMutate) + + // start the observer + observer.observe(document, { childList: true, subtree: true }) + // initial run on existing document + run() +}).call()