comparison pixiv-fanbox-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 e21710f5dd7b
children 2c4470b73ad9
comparison
equal deleted inserted replaced
103:b2d0b37f945f 104:93e21738b588
1 // ==UserScript== 1 // ==UserScript==
2 // @name pixiv fanbox no lazy loading image 2 // @name pixiv fanbox no lazy loading image
3 // @namespace https://myconan.net 3 // @namespace https://myconan.net
4 // @version 2.1.1 4 // @version 2.1.2
5 // @description Lazy loading is bad for environment. Disable it. 5 // @description Lazy loading is bad for environment. Disable it.
6 // @author nanaya 6 // @author nanaya
7 // @match https://*.fanbox.cc/* 7 // @match https://*.fanbox.cc/*
8 // @grant none 8 // @grant none
9 // @run-at document-start 9 // @run-at document-start
37 image.style.width = '100%' 37 image.style.width = '100%'
38 image.src = href 38 image.src = href
39 link.replaceChildren(image) 39 link.replaceChildren(image)
40 } 40 }
41 41
42 function run (node) {
43 if (!(node instanceof window.HTMLElement)) return
44
45 fix(node)
46 for (const link of node.querySelectorAll(`[href^="${imageUrlPrefix}"]`)) {
47 fix(link)
48 }
49 }
50
42 function onMutate (mutations) { 51 function onMutate (mutations) {
43 for (const mutation of mutations) { 52 for (const mutation of mutations) {
44 for (const node of mutation.addedNodes) { 53 for (const node of mutation.addedNodes) {
45 if (node instanceof window.HTMLElement) { 54 run(node)
46 fix(node)
47 for (const link of node.querySelectorAll(`[href^="${imageUrlPrefix}"]`)) {
48 fix(link)
49 }
50 }
51 } 55 }
52 } 56 }
53 } 57 }
54 58
55 const observer = new window.MutationObserver(onMutate) 59 const observer = new window.MutationObserver(onMutate)
56 observer.observe(document, { childList: true, subtree: true }) 60 observer.observe(document, { childList: true, subtree: true })
61 run(document.body)