Mercurial > ec-userscripts
annotate 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 |
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 |
97 | 15 function fix (image) { |
108 | 16 if (!image.classList.contains('lazyload')) return; |
102 | 17 |
108 | 18 const src = image.dataset.src; |
98
3e5f1fa9ed52
Skip redundant class check and add dataset check instead
nanaya <me@nanaya.net>
parents:
97
diff
changeset
|
19 |
108 | 20 if (src == null || src === '') return; |
97 | 21 |
108 | 22 image.classList.remove('lazyload'); |
23 image.src = image.dataset.src; | |
24 delete image.dataset.src; | |
97 | 25 } |
95 | 26 |
104 | 27 function run (node) { |
108 | 28 if (!(node instanceof window.HTMLElement)) return; |
104 | 29 |
108 | 30 fix(node); |
104 | 31 for (const image of node.querySelectorAll('.lazyload')) { |
108 | 32 fix(image); |
104 | 33 } |
34 } | |
35 | |
97 | 36 function onMutate (mutations) { |
37 for (const mutation of mutations) { | |
38 for (const node of mutation.addedNodes) { | |
108 | 39 run(node); |
97 | 40 } |
95 | 41 } |
42 } | |
97 | 43 |
108 | 44 const observer = new window.MutationObserver(onMutate); |
45 observer.observe(document, { childList: true, subtree: true }); | |
46 run(document.body); |