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