78
|
1 // ==UserScript==
|
|
2 // @name pixiv fanbox no lazy loading image
|
|
3 // @namespace https://myconan.net
|
104
|
4 // @version 2.1.2
|
78
|
5 // @description Lazy loading is bad for environment. Disable it.
|
|
6 // @author nanaya
|
79
|
7 // @match https://*.fanbox.cc/*
|
78
|
8 // @grant none
|
100
|
9 // @run-at document-start
|
|
10 // @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/pixiv-fanbox-unlazy.user.js
|
78
|
11 // ==/UserScript==
|
|
12
|
100
|
13 'use strict'
|
78
|
14
|
100
|
15 const imageUrlPrefix = 'https://downloads.fanbox.cc/images/post/'
|
78
|
16
|
100
|
17 function disableEventLink (event) {
|
|
18 event.stopPropagation()
|
|
19 }
|
78
|
20
|
100
|
21 function fix (link) {
|
|
22 const href = link.href
|
78
|
23
|
100
|
24 // basic sanity check
|
|
25 if (typeof href !== 'string' || !href.startsWith(imageUrlPrefix)) {
|
|
26 return
|
78
|
27 }
|
|
28
|
100
|
29 // don't run again if already run on passed link
|
|
30 if (link._ecUserscript) {
|
|
31 return
|
78
|
32 }
|
100
|
33 link._ecUserscript = true
|
78
|
34
|
100
|
35 link.addEventListener('click', disableEventLink)
|
|
36 const image = document.createElement('img')
|
|
37 image.style.width = '100%'
|
|
38 image.src = href
|
|
39 link.replaceChildren(image)
|
|
40 }
|
85
|
41
|
104
|
42 function run (node) {
|
|
43 if (!(node instanceof window.HTMLElement)) return
|
|
44
|
|
45 fix(node)
|
|
46 for (const link of node.querySelectorAll(`[href^="${imageUrlPrefix}"]`)) {
|
|
47 fix(link)
|
|
48 }
|
|
49 }
|
|
50
|
100
|
51 function onMutate (mutations) {
|
|
52 for (const mutation of mutations) {
|
|
53 for (const node of mutation.addedNodes) {
|
104
|
54 run(node)
|
85
|
55 }
|
|
56 }
|
100
|
57 }
|
78
|
58
|
100
|
59 const observer = new window.MutationObserver(onMutate)
|
|
60 observer.observe(document, { childList: true, subtree: true })
|
104
|
61 run(document.body)
|