Mercurial > ec-userscripts
annotate melonbooks-unlazy.user.js @ 101:e21710f5dd7b
Also run on its own node
author | nanaya <me@nanaya.net> |
---|---|
date | Sat, 24 Dec 2022 21:31:42 +0900 |
parents | b44d5cb661c5 |
children | 3fded109e23a |
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 |
99 | 7 // @version 1.0.3 |
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 |
99 | 18 if (src == null || src === '') 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 }) |