# HG changeset patch # User nanaya # Date 1671792979 -32400 # Node ID c8f9350c5307c48310f3b9e02c33c8b42a099cff # Parent 368035f2213b7ddd06c24713a8ba102aa7655061 More thorough lazyload monitor diff -r 368035f2213b -r c8f9350c5307 melonbooks-unlazy.user.js --- a/melonbooks-unlazy.user.js Fri Dec 23 19:14:04 2022 +0900 +++ b/melonbooks-unlazy.user.js Fri Dec 23 19:56:19 2022 +0900 @@ -3,8 +3,8 @@ // @namespace https://nanaya.net // @match https://www.melonbooks.co.jp/* // @grant none -// @run-at document-end -// @version 1.0.1 +// @run-at document-start +// @version 1.0.2 // @author nanaya // @description replace lazy loaded images with just images // @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/melonbooks-unlazy.user.js @@ -12,13 +12,25 @@ 'use strict' -for (const img of document.querySelectorAll('.lazyload')) { - const src = img.dataset.src +function fix (image) { + if (!image.classList.contains('lazyload')) return + + image.classList.remove('lazyload') + image.src = image.dataset.src + delete image.dataset.src +} - if (src != null) { - img.src = src - img.classList.remove('lazyload') - img.classList.add('unlazied') - delete img.dataset.src +function onMutate (mutations) { + for (const mutation of mutations) { + for (const node of mutation.addedNodes) { + if (node instanceof window.HTMLElement) { + for (const image of node.querySelectorAll('.lazyload')) { + fix(image) + } + } + } } } + +const observer = new window.MutationObserver(onMutate) +observer.observe(document, { childList: true, subtree: true })