Mercurial > ec-userscripts
annotate melonbooks-unlazy.user.js @ 98:3e5f1fa9ed52
Skip redundant class check and add dataset check instead
| author | nanaya <me@nanaya.net> |
|---|---|
| date | Fri, 23 Dec 2022 19:58:14 +0900 |
| parents | c8f9350c5307 |
| children | b44d5cb661c5 |
| rev | line source |
|---|---|
| 95 | 1 // ==UserScript== |
| 2 // @name melonbooks unlazy | |
| 3 // @namespace https://nanaya.net | |
| 4 // @match https://www.melonbooks.co.jp/* | |
| 5 // @grant none | |
| 97 | 6 // @run-at document-start |
| 7 // @version 1.0.2 | |
| 95 | 8 // @author nanaya |
| 9 // @description replace lazy loaded images with just images | |
| 10 // @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/melonbooks-unlazy.user.js | |
| 11 // ==/UserScript== | |
| 12 | |
| 13 'use strict' | |
| 14 | |
| 97 | 15 function fix (image) { |
|
98
3e5f1fa9ed52
Skip redundant class check and add dataset check instead
nanaya <me@nanaya.net>
parents:
97
diff
changeset
|
16 const src = image.dataset.src |
|
3e5f1fa9ed52
Skip redundant class check and add dataset check instead
nanaya <me@nanaya.net>
parents:
97
diff
changeset
|
17 |
|
3e5f1fa9ed52
Skip redundant class check and add dataset check instead
nanaya <me@nanaya.net>
parents:
97
diff
changeset
|
18 if (src == null) return |
| 97 | 19 |
| 20 image.classList.remove('lazyload') | |
| 21 image.src = image.dataset.src | |
| 22 delete image.dataset.src | |
| 23 } | |
| 95 | 24 |
| 97 | 25 function onMutate (mutations) { |
| 26 for (const mutation of mutations) { | |
| 27 for (const node of mutation.addedNodes) { | |
| 28 if (node instanceof window.HTMLElement) { | |
| 29 for (const image of node.querySelectorAll('.lazyload')) { | |
| 30 fix(image) | |
| 31 } | |
| 32 } | |
| 33 } | |
| 95 | 34 } |
| 35 } | |
| 97 | 36 |
| 37 const observer = new window.MutationObserver(onMutate) | |
| 38 observer.observe(document, { childList: true, subtree: true }) |
