comparison melonbooks-unlazy.user.js @ 104:93e21738b588

Run fix on whole body on start There's no guarantee the script loads before document.
author nanaya <me@nanaya.net>
date Sun, 25 Dec 2022 11:52:30 +0900
parents 3fded109e23a
children 2c4470b73ad9
comparison
equal deleted inserted replaced
103:b2d0b37f945f 104:93e21738b588
2 // @name melonbooks unlazy 2 // @name melonbooks unlazy
3 // @namespace https://nanaya.net 3 // @namespace https://nanaya.net
4 // @match https://www.melonbooks.co.jp/* 4 // @match https://www.melonbooks.co.jp/*
5 // @grant none 5 // @grant none
6 // @run-at document-start 6 // @run-at document-start
7 // @version 1.0.4 7 // @version 1.0.5
8 // @author nanaya 8 // @author nanaya
9 // @description replace lazy loaded images with just images 9 // @description replace lazy loaded images with just images
10 // @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/melonbooks-unlazy.user.js 10 // @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/melonbooks-unlazy.user.js
11 // ==/UserScript== 11 // ==/UserScript==
12 12
22 image.classList.remove('lazyload') 22 image.classList.remove('lazyload')
23 image.src = image.dataset.src 23 image.src = image.dataset.src
24 delete image.dataset.src 24 delete image.dataset.src
25 } 25 }
26 26
27 function run (node) {
28 if (!(node instanceof window.HTMLElement)) return
29
30 fix(node)
31 for (const image of node.querySelectorAll('.lazyload')) {
32 fix(image)
33 }
34 }
35
27 function onMutate (mutations) { 36 function onMutate (mutations) {
28 for (const mutation of mutations) { 37 for (const mutation of mutations) {
29 for (const node of mutation.addedNodes) { 38 for (const node of mutation.addedNodes) {
30 if (node instanceof window.HTMLElement) { 39 run(node)
31 fix(node)
32 for (const image of node.querySelectorAll('.lazyload')) {
33 fix(image)
34 }
35 }
36 } 40 }
37 } 41 }
38 } 42 }
39 43
40 const observer = new window.MutationObserver(onMutate) 44 const observer = new window.MutationObserver(onMutate)
41 observer.observe(document, { childList: true, subtree: true }) 45 observer.observe(document, { childList: true, subtree: true })
46 run(document.body)