diff 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
line wrap: on
line diff
--- a/melonbooks-unlazy.user.js	Sat Dec 24 22:10:30 2022 +0900
+++ b/melonbooks-unlazy.user.js	Sun Dec 25 11:52:30 2022 +0900
@@ -4,7 +4,7 @@
 // @match       https://www.melonbooks.co.jp/*
 // @grant       none
 // @run-at      document-start
-// @version     1.0.4
+// @version     1.0.5
 // @author      nanaya
 // @description replace lazy loaded images with just images
 // @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/melonbooks-unlazy.user.js
@@ -24,18 +24,23 @@
   delete image.dataset.src
 }
 
+function run (node) {
+  if (!(node instanceof window.HTMLElement)) return
+
+  fix(node)
+  for (const image of node.querySelectorAll('.lazyload')) {
+    fix(image)
+  }
+}
+
 function onMutate (mutations) {
   for (const mutation of mutations) {
     for (const node of mutation.addedNodes) {
-      if (node instanceof window.HTMLElement) {
-        fix(node)
-        for (const image of node.querySelectorAll('.lazyload')) {
-          fix(image)
-        }
-      }
+      run(node)
     }
   }
 }
 
 const observer = new window.MutationObserver(onMutate)
 observer.observe(document, { childList: true, subtree: true })
+run(document.body)