comparison soranews-image.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 9c8cde985caf
children ef21ef445fc6
comparison
equal deleted inserted replaced
107:4bc5a633437c 108:2c4470b73ad9
7 // @match https://soranews24.com/* 7 // @match https://soranews24.com/*
8 // @grant none 8 // @grant none
9 // @downloadURL https://hg.myconan.net/ec-userscripts/raw-file/tip/soranews-image.user.js 9 // @downloadURL https://hg.myconan.net/ec-userscripts/raw-file/tip/soranews-image.user.js
10 // ==/UserScript== 10 // ==/UserScript==
11 11
12 ;(function () { 12 (function () {
13 'use strict' 13 'use strict';
14 14
15 const fix = function (image) { 15 const fix = function (image) {
16 // basic sanity check 16 // basic sanity check
17 if (!image.classList.contains('lazy')) { 17 if (!image.classList.contains('lazy')) {
18 return 18 return;
19 } 19 }
20 20
21 image.classList.remove('lazy') 21 image.classList.remove('lazy');
22 image.removeAttribute('src') 22 image.removeAttribute('src');
23 image.setAttribute('srcset', image.dataset.scoSrcset) 23 image.setAttribute('srcset', image.dataset.scoSrcset);
24 } 24 };
25 25
26 // loop through passed nodes (or body if called without arguments) 26 // loop through passed nodes (or body if called without arguments)
27 const run = function (nodes) { 27 const run = function (nodes) {
28 if (nodes == null) { 28 if (nodes == null) {
29 nodes = [document.body] 29 nodes = [document.body];
30 } 30 }
31 31
32 for (let i = 0; i < nodes.length; i++) { 32 for (let i = 0; i < nodes.length; i++) {
33 // find all the images inside (and self) 33 // find all the images inside (and self)
34 const images = [nodes[i], ...nodes[i].querySelectorAll('.lazy')] 34 const images = [nodes[i], ...nodes[i].querySelectorAll('.lazy')];
35 35
36 for (let j = 0; j < images.length; j++) { 36 for (let j = 0; j < images.length; j++) {
37 fix(images[j]) 37 fix(images[j]);
38 } 38 }
39 } 39 }
40 } 40 };
41 41
42 const onMutate = function (mutations) { 42 const onMutate = function (mutations) {
43 for (const mutation in mutations) { 43 for (const mutation in mutations) {
44 run(mutation.addedNodes) 44 run(mutation.addedNodes);
45 } 45 }
46 } 46 };
47 47
48 // the observer 48 // the observer
49 const observer = new window.MutationObserver(onMutate) 49 const observer = new window.MutationObserver(onMutate);
50 50
51 // start the observer 51 // start the observer
52 observer.observe(document, { childList: true, subtree: true }) 52 observer.observe(document, { childList: true, subtree: true });
53 // initial run on existing document 53 // initial run on existing document
54 run() 54 run();
55 }).call() 55 }).call();