diff melonbooks-unlazy.user.js @ 96:368035f2213b

Use builtin framework for document ready
author nanaya <me@nanaya.net>
date Fri, 23 Dec 2022 19:14:04 +0900
parents afad36fddb64
children c8f9350c5307
line wrap: on
line diff
--- a/melonbooks-unlazy.user.js	Fri Dec 23 19:10:50 2022 +0900
+++ b/melonbooks-unlazy.user.js	Fri Dec 23 19:14:04 2022 +0900
@@ -3,7 +3,8 @@
 // @namespace   https://nanaya.net
 // @match       https://www.melonbooks.co.jp/*
 // @grant       none
-// @version     1.0.0
+// @run-at      document-end
+// @version     1.0.1
 // @author      nanaya
 // @description replace lazy loaded images with just images
 // @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/melonbooks-unlazy.user.js
@@ -11,21 +12,13 @@
 
 'use strict'
 
-function unlazy () {
-  for (const img of document.querySelectorAll('.lazyload')) {
-    const src = img.dataset.src
+for (const img of document.querySelectorAll('.lazyload')) {
+  const src = img.dataset.src
 
-    if (src != null) {
-      img.src = src
-      img.classList.remove('lazyload')
-      img.classList.add('unlazied')
-      delete img.dataset.src
-    }
+  if (src != null) {
+    img.src = src
+    img.classList.remove('lazyload')
+    img.classList.add('unlazied')
+    delete img.dataset.src
   }
 }
-
-if (document.readyState === 'loading') {
-  document.addEventListener('DOMContentLoaded', unlazy)
-} else {
-  unlazy()
-}