Mercurial > ec-userscripts
annotate melonbooks-unlazy.user.js @ 102:3fded109e23a
Also run on own node
author | nanaya <me@nanaya.net> |
---|---|
date | Sat, 24 Dec 2022 21:33:30 +0900 |
parents | b44d5cb661c5 |
children | 93e21738b588 |
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 |
102 | 7 // @version 1.0.4 |
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) { |
102 | 16 if (!image.classList.contains('lazyload')) return |
17 | |
98
3e5f1fa9ed52
Skip redundant class check and add dataset check instead
nanaya <me@nanaya.net>
parents:
97
diff
changeset
|
18 const src = image.dataset.src |
3e5f1fa9ed52
Skip redundant class check and add dataset check instead
nanaya <me@nanaya.net>
parents:
97
diff
changeset
|
19 |
99 | 20 if (src == null || src === '') return |
97 | 21 |
22 image.classList.remove('lazyload') | |
23 image.src = image.dataset.src | |
24 delete image.dataset.src | |
25 } | |
95 | 26 |
97 | 27 function onMutate (mutations) { |
28 for (const mutation of mutations) { | |
29 for (const node of mutation.addedNodes) { | |
30 if (node instanceof window.HTMLElement) { | |
102 | 31 fix(node) |
97 | 32 for (const image of node.querySelectorAll('.lazyload')) { |
33 fix(image) | |
34 } | |
35 } | |
36 } | |
95 | 37 } |
38 } | |
97 | 39 |
40 const observer = new window.MutationObserver(onMutate) | |
41 observer.observe(document, { childList: true, subtree: true }) |