78
|
1 // ==UserScript==
|
|
2 // @name pixiv fanbox no lazy loading image
|
|
3 // @namespace https://myconan.net
|
82
|
4 // @version 2.0.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
|
82
|
9 // @downloadURL https://hg.myconan.net/ec-userscripts/raw-file/tip/pixiv-fanbox-unlazy.user.js
|
78
|
10 // ==/UserScript==
|
|
11
|
|
12 ;(function () {
|
|
13 'use strict'
|
|
14
|
85
|
15 const imageUrlPrefix = 'https://downloads.fanbox.cc/images/post/'
|
78
|
16
|
85
|
17 const fix = function (link) {
|
|
18 const href = link.href
|
78
|
19
|
|
20 // basic sanity check
|
|
21 if (typeof href !== 'string' || !href.startsWith(imageUrlPrefix)) {
|
|
22 return
|
|
23 }
|
|
24
|
|
25 // don't run again if already run on passed link
|
|
26 if (link._ecUserscript) {
|
|
27 return
|
|
28 }
|
|
29 link._ecUserscript = true
|
|
30
|
81
|
31 link.addEventListener('click', (event) => {
|
|
32 event.stopPropagation()
|
|
33 })
|
78
|
34 link.innerHTML = `<img style="width: 100%;" src="${href}" />`
|
|
35 }
|
|
36
|
85
|
37 const onMutate = function (mutations) {
|
|
38 for (const mutation in mutations) {
|
78
|
39 run(mutation.addedNodes)
|
|
40 }
|
|
41 }
|
|
42
|
85
|
43 // loop through passed nodes (or body if called without arguments)
|
|
44 const run = function (nodes) {
|
|
45 if (nodes == null) {
|
|
46 nodes = [document.body]
|
|
47 }
|
|
48
|
|
49 for (let i = 0; i < nodes.length; i++) {
|
|
50 // first try fixing itself
|
|
51 fix(nodes[i])
|
|
52
|
|
53 // and then find all the links inside
|
|
54 const links = nodes[i].querySelectorAll(`[href^="${imageUrlPrefix}"]`)
|
|
55
|
|
56 for (let j = 0; j < links.length; j++) {
|
|
57 fix(links[j])
|
|
58 }
|
|
59 }
|
|
60 }
|
|
61
|
78
|
62 // the observer
|
85
|
63 const observer = new window.MutationObserver(onMutate)
|
78
|
64
|
|
65 // start the observer
|
|
66 observer.observe(document, { childList: true, subtree: true })
|
|
67 // initial run on existing document
|
|
68 run()
|
|
69 }).call()
|