Mercurial > ec-userscripts
comparison soranews-image.user.js @ 84:af4f8b25495e
Merge elements first and use actual srcset
author | nanaya <me@nanaya.pro> |
---|---|
date | Thu, 15 Apr 2021 14:56:23 +0900 |
parents | 86da34e62d29 |
children | 9c8cde985caf |
comparison
equal
deleted
inserted
replaced
83:a1e007bea4f1 | 84:af4f8b25495e |
---|---|
1 // ==UserScript== | 1 // ==UserScript== |
2 // @name Soranews image fix | 2 // @name Soranews image fix |
3 // @namespace https://myconan.net | 3 // @namespace https://myconan.net |
4 // @version 1.0.2 | 4 // @version 1.0.3 |
5 // @description Soranews lazy load image fix | 5 // @description Soranews lazy load image fix |
6 // @author nanaya | 6 // @author nanaya |
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 |
17 if (nodes == null) { | 17 if (nodes == null) { |
18 nodes = [document.body] | 18 nodes = [document.body] |
19 } | 19 } |
20 | 20 |
21 for (var i = 0; i < nodes.length; i++) { | 21 for (var i = 0; i < nodes.length; i++) { |
22 // first try fixing itself | 22 // find all the images inside (and self) |
23 fix(nodes[i]) | 23 var images = [nodes[i], ...nodes[i].querySelectorAll('.lazy')] |
24 | |
25 // and then find all the images inside | |
26 var images = nodes[i].querySelectorAll('.lazy') | |
27 | 24 |
28 for (var j = 0; j < images.length; j++) { | 25 for (var j = 0; j < images.length; j++) { |
29 fix(images[j]) | 26 fix(images[j]) |
30 } | 27 } |
31 } | 28 } |
37 return | 34 return |
38 } | 35 } |
39 | 36 |
40 image.classList.remove('lazy') | 37 image.classList.remove('lazy') |
41 image.removeAttribute('src') | 38 image.removeAttribute('src') |
42 image.setAttribute('srcset', image.dataset.scoSrc) | 39 image.setAttribute('srcset', image.dataset.scoSrcset) |
43 } | 40 } |
44 | 41 |
45 var onMutate = function (mutations) { | 42 var onMutate = function (mutations) { |
46 for (var mutation in mutations) { | 43 for (var mutation in mutations) { |
47 run(mutation.addedNodes) | 44 run(mutation.addedNodes) |