78
|
1 // ==UserScript==
|
|
2 // @name pixiv fanbox no lazy loading image
|
|
3 // @namespace https://myconan.net
|
101
|
4 // @version 2.1.1
|
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
|
100
|
42 function onMutate (mutations) {
|
|
43 for (const mutation of mutations) {
|
|
44 for (const node of mutation.addedNodes) {
|
|
45 if (node instanceof window.HTMLElement) {
|
101
|
46 fix(node)
|
100
|
47 for (const link of node.querySelectorAll(`[href^="${imageUrlPrefix}"]`)) {
|
|
48 fix(link)
|
|
49 }
|
85
|
50 }
|
|
51 }
|
|
52 }
|
100
|
53 }
|
78
|
54
|
100
|
55 const observer = new window.MutationObserver(onMutate)
|
|
56 observer.observe(document, { childList: true, subtree: true })
|