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