comparison melonbooks-unlazy.user.js @ 108:2c4470b73ad9

Switch to semistandard No more `;` at the start of line.
author nanaya <me@nanaya.net>
date Sun, 15 Jan 2023 23:24:03 +0900
parents 93e21738b588
children ef21ef445fc6
comparison
equal deleted inserted replaced
107:4bc5a633437c 108:2c4470b73ad9
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 function fix (image) { 15 function fix (image) {
16 if (!image.classList.contains('lazyload')) return 16 if (!image.classList.contains('lazyload')) return;
17 17
18 const src = image.dataset.src 18 const src = image.dataset.src;
19 19
20 if (src == null || src === '') return 20 if (src == null || src === '') return;
21 21
22 image.classList.remove('lazyload') 22 image.classList.remove('lazyload');
23 image.src = image.dataset.src 23 image.src = image.dataset.src;
24 delete image.dataset.src 24 delete image.dataset.src;
25 } 25 }
26 26
27 function run (node) { 27 function run (node) {
28 if (!(node instanceof window.HTMLElement)) return 28 if (!(node instanceof window.HTMLElement)) return;
29 29
30 fix(node) 30 fix(node);
31 for (const image of node.querySelectorAll('.lazyload')) { 31 for (const image of node.querySelectorAll('.lazyload')) {
32 fix(image) 32 fix(image);
33 } 33 }
34 } 34 }
35 35
36 function onMutate (mutations) { 36 function onMutate (mutations) {
37 for (const mutation of mutations) { 37 for (const mutation of mutations) {
38 for (const node of mutation.addedNodes) { 38 for (const node of mutation.addedNodes) {
39 run(node) 39 run(node);
40 } 40 }
41 } 41 }
42 } 42 }
43 43
44 const observer = new window.MutationObserver(onMutate) 44 const observer = new window.MutationObserver(onMutate);
45 observer.observe(document, { childList: true, subtree: true }) 45 observer.observe(document, { childList: true, subtree: true });
46 run(document.body) 46 run(document.body);