Mercurial > ec-userscripts
annotate melonbooks-unlazy.user.js @ 116:0e108a9dc6d7
Split suruga-ya scripts
author | nanaya <me@nanaya.net> |
---|---|
date | Sun, 15 Jan 2023 23:46:56 +0900 |
parents | ef21ef445fc6 |
children | d9dc190bccaf |
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 |
104 | 7 // @version 1.0.5 |
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 | |
108 | 13 'use strict'; |
95 | 14 |
109 | 15 function unlazy () { |
16 function fix (image) { | |
17 if (!image.classList.contains('lazyload')) return; | |
18 | |
19 const src = image.dataset.src; | |
20 | |
21 if (src == null || src === '') return; | |
102 | 22 |
109 | 23 image.classList.remove('lazyload'); |
24 image.src = image.dataset.src; | |
25 delete image.dataset.src; | |
26 } | |
27 | |
28 function run (node) { | |
29 if (!(node instanceof window.HTMLElement)) return; | |
98
3e5f1fa9ed52
Skip redundant class check and add dataset check instead
nanaya <me@nanaya.net>
parents:
97
diff
changeset
|
30 |
109 | 31 fix(node); |
32 for (const image of node.querySelectorAll('.lazyload')) { | |
33 fix(image); | |
34 } | |
35 } | |
97 | 36 |
109 | 37 function onMutate (mutations) { |
38 for (const mutation of mutations) { | |
39 for (const node of mutation.addedNodes) { | |
40 run(node); | |
41 } | |
42 } | |
43 } | |
44 | |
45 const observer = new window.MutationObserver(onMutate); | |
46 observer.observe(document, { childList: true, subtree: true }); | |
47 run(document.body); | |
97 | 48 } |
95 | 49 |
109 | 50 unlazy(); |