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
|
108
|
13 'use strict';
|
78
|
14
|
108
|
15 const imageUrlPrefix = 'https://downloads.fanbox.cc/images/post/';
|
78
|
16
|
100
|
17 function disableEventLink (event) {
|
108
|
18 event.stopPropagation();
|
100
|
19 }
|
78
|
20
|
100
|
21 function fix (link) {
|
108
|
22 const href = link.href;
|
78
|
23
|
100
|
24 // basic sanity check
|
|
25 if (typeof href !== 'string' || !href.startsWith(imageUrlPrefix)) {
|
108
|
26 return;
|
78
|
27 }
|
|
28
|
100
|
29 // don't run again if already run on passed link
|
|
30 if (link._ecUserscript) {
|
108
|
31 return;
|
78
|
32 }
|
108
|
33 link._ecUserscript = true;
|
78
|
34
|
108
|
35 link.addEventListener('click', disableEventLink);
|
|
36 const image = document.createElement('img');
|
|
37 image.style.width = '100%';
|
|
38 image.src = href;
|
|
39 link.replaceChildren(image);
|
100
|
40 }
|
85
|
41
|
104
|
42 function run (node) {
|
108
|
43 if (!(node instanceof window.HTMLElement)) return;
|
104
|
44
|
108
|
45 fix(node);
|
104
|
46 for (const link of node.querySelectorAll(`[href^="${imageUrlPrefix}"]`)) {
|
108
|
47 fix(link);
|
104
|
48 }
|
|
49 }
|
|
50
|
100
|
51 function onMutate (mutations) {
|
|
52 for (const mutation of mutations) {
|
|
53 for (const node of mutation.addedNodes) {
|
108
|
54 run(node);
|
85
|
55 }
|
|
56 }
|
100
|
57 }
|
78
|
58
|
108
|
59 const observer = new window.MutationObserver(onMutate);
|
|
60 observer.observe(document, { childList: true, subtree: true });
|
|
61 run(document.body);
|