# HG changeset patch # User nanaya # Date 1594054689 -32400 # Node ID 0aa28e02e257f7998de0bde43c422871f141762b # Parent 78598a92e6fc48f56350832d6976b331ca5df62d Add soranews unlazy image diff -r 78598a92e6fc -r 0aa28e02e257 soranews-image.user.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/soranews-image.user.js Tue Jul 07 01:58:09 2020 +0900 @@ -0,0 +1,58 @@ +// ==UserScript== +// @name Soranews image fix +// @namespace https://myconan.net +// @version 1.0.0 +// @description Soranews lazy load image fix +// @author nanaya +// @match https://soranews24.com/* +// @grant none +// @downloadURL https://hg.sr.ht/~nanaya/ec-userscripts/raw/default/soranews-image.user.js +// ==/UserScript== + +;(function () { + 'use strict' + + // 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 images inside + var images = nodes[i].querySelectorAll('.lazy') + + for (var j = 0; j < images.length; j++) { + fix(images[j]) + } + } + } + + var fix = function (image) { + // basic sanity check + if (!image.classList.contains('lazy')) { + return + } + + image.classList.remove('lazy') + image.removeAttribute('src') + image.setAttribute('srcset', image.dataset.scoSrc) + } + + 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()