Mercurial > ec-userscripts
comparison melonbooks-unlazy.user.js @ 97:c8f9350c5307
More thorough lazyload monitor
| author | nanaya <me@nanaya.net> | 
|---|---|
| date | Fri, 23 Dec 2022 19:56:19 +0900 | 
| parents | 368035f2213b | 
| children | 3e5f1fa9ed52 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 96:368035f2213b | 97:c8f9350c5307 | 
|---|---|
| 1 // ==UserScript== | 1 // ==UserScript== | 
| 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-end | 6 // @run-at document-start | 
| 7 // @version 1.0.1 | 7 // @version 1.0.2 | 
| 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 | 
| 13 'use strict' | 13 'use strict' | 
| 14 | 14 | 
| 15 for (const img of document.querySelectorAll('.lazyload')) { | 15 function fix (image) { | 
| 16 const src = img.dataset.src | 16 if (!image.classList.contains('lazyload')) return | 
| 17 | 17 | 
| 18 if (src != null) { | 18 image.classList.remove('lazyload') | 
| 19 img.src = src | 19 image.src = image.dataset.src | 
| 20 img.classList.remove('lazyload') | 20 delete image.dataset.src | 
| 21 img.classList.add('unlazied') | 21 } | 
| 22 delete img.dataset.src | 22 | 
| 23 function onMutate (mutations) { | |
| 24 for (const mutation of mutations) { | |
| 25 for (const node of mutation.addedNodes) { | |
| 26 if (node instanceof window.HTMLElement) { | |
| 27 for (const image of node.querySelectorAll('.lazyload')) { | |
| 28 fix(image) | |
| 29 } | |
| 30 } | |
| 31 } | |
| 23 } | 32 } | 
| 24 } | 33 } | 
| 34 | |
| 35 const observer = new window.MutationObserver(onMutate) | |
| 36 observer.observe(document, { childList: true, subtree: true }) | 
