Mercurial > ec-userscripts
diff 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 |
line wrap: on
line diff
--- a/pixiv-fanbox-unlazy.user.js Sat Dec 24 22:10:30 2022 +0900 +++ b/pixiv-fanbox-unlazy.user.js Sun Dec 25 11:52:30 2022 +0900 @@ -1,7 +1,7 @@ // ==UserScript== // @name pixiv fanbox no lazy loading image // @namespace https://myconan.net -// @version 2.1.1 +// @version 2.1.2 // @description Lazy loading is bad for environment. Disable it. // @author nanaya // @match https://*.fanbox.cc/* @@ -39,18 +39,23 @@ link.replaceChildren(image) } +function run (node) { + if (!(node instanceof window.HTMLElement)) return + + fix(node) + for (const link of node.querySelectorAll(`[href^="${imageUrlPrefix}"]`)) { + fix(link) + } +} + function onMutate (mutations) { for (const mutation of mutations) { for (const node of mutation.addedNodes) { - if (node instanceof window.HTMLElement) { - fix(node) - for (const link of node.querySelectorAll(`[href^="${imageUrlPrefix}"]`)) { - fix(link) - } - } + run(node) } } } const observer = new window.MutationObserver(onMutate) observer.observe(document, { childList: true, subtree: true }) +run(document.body)