75
|
1 // ==UserScript==
|
|
2 // @name Soranews image fix
|
|
3 // @namespace https://myconan.net
|
77
|
4 // @version 1.0.1
|
75
|
5 // @description Soranews lazy load image fix
|
|
6 // @author nanaya
|
|
7 // @match https://soranews24.com/*
|
|
8 // @grant none
|
77
|
9 // @downloadURL https://hg.sr.ht/~nanaya/ec-userscripts/raw/soranews-image.user.js?rev=tip
|
75
|
10 // ==/UserScript==
|
|
11
|
|
12 ;(function () {
|
|
13 'use strict'
|
|
14
|
|
15 // loop through passed nodes (or body if called without arguments)
|
|
16 var run = function (nodes) {
|
|
17 if (nodes == null) {
|
|
18 nodes = [document.body]
|
|
19 }
|
|
20
|
|
21 for (var i = 0; i < nodes.length; i++) {
|
|
22 // first try fixing itself
|
|
23 fix(nodes[i])
|
|
24
|
|
25 // and then find all the images inside
|
|
26 var images = nodes[i].querySelectorAll('.lazy')
|
|
27
|
|
28 for (var j = 0; j < images.length; j++) {
|
|
29 fix(images[j])
|
|
30 }
|
|
31 }
|
|
32 }
|
|
33
|
|
34 var fix = function (image) {
|
|
35 // basic sanity check
|
|
36 if (!image.classList.contains('lazy')) {
|
|
37 return
|
|
38 }
|
|
39
|
|
40 image.classList.remove('lazy')
|
|
41 image.removeAttribute('src')
|
|
42 image.setAttribute('srcset', image.dataset.scoSrc)
|
|
43 }
|
|
44
|
|
45 var onMutate = function (mutations) {
|
|
46 for (var mutation in mutations) {
|
|
47 run(mutation.addedNodes)
|
|
48 }
|
|
49 }
|
|
50
|
|
51 // the observer
|
|
52 var observer = new window.MutationObserver(onMutate)
|
|
53
|
|
54 // start the observer
|
|
55 observer.observe(document, { childList: true, subtree: true })
|
|
56 // initial run on existing document
|
|
57 run()
|
|
58 }).call()
|