annotate pixiv-fanbox-unlazy.user.js @ 108:2c4470b73ad9

Switch to semistandard No more `;` at the start of line.
author nanaya <me@nanaya.net>
date Sun, 15 Jan 2023 23:24:03 +0900
parents 93e21738b588
children ef21ef445fc6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
78
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
1 // ==UserScript==
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
2 // @name pixiv fanbox no lazy loading image
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
3 // @namespace https://myconan.net
104
93e21738b588 Run fix on whole body on start
nanaya <me@nanaya.net>
parents: 101
diff changeset
4 // @version 2.1.2
78
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
5 // @description Lazy loading is bad for environment. Disable it.
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
6 // @author nanaya
79
e4b970501e8e Missed the url fix
nanaya <me@nanaya.pro>
parents: 78
diff changeset
7 // @match https://*.fanbox.cc/*
78
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
8 // @grant none
100
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
9 // @run-at document-start
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
10 // @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/pixiv-fanbox-unlazy.user.js
78
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
11 // ==/UserScript==
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
12
108
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 104
diff changeset
13 'use strict';
78
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
14
108
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 104
diff changeset
15 const imageUrlPrefix = 'https://downloads.fanbox.cc/images/post/';
78
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
16
100
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
17 function disableEventLink (event) {
108
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 104
diff changeset
18 event.stopPropagation();
100
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
19 }
78
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
20
100
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
21 function fix (link) {
108
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 104
diff changeset
22 const href = link.href;
78
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
23
100
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
24 // basic sanity check
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
25 if (typeof href !== 'string' || !href.startsWith(imageUrlPrefix)) {
108
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 104
diff changeset
26 return;
78
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
27 }
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
28
100
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
29 // don't run again if already run on passed link
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
30 if (link._ecUserscript) {
108
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 104
diff changeset
31 return;
78
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
32 }
108
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 104
diff changeset
33 link._ecUserscript = true;
78
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
34
108
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 104
diff changeset
35 link.addEventListener('click', disableEventLink);
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 104
diff changeset
36 const image = document.createElement('img');
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 104
diff changeset
37 image.style.width = '100%';
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 104
diff changeset
38 image.src = href;
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 104
diff changeset
39 link.replaceChildren(image);
100
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
40 }
85
9c8cde985caf Update standard and fix
nanaya <me@nanaya.pro>
parents: 82
diff changeset
41
104
93e21738b588 Run fix on whole body on start
nanaya <me@nanaya.net>
parents: 101
diff changeset
42 function run (node) {
108
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 104
diff changeset
43 if (!(node instanceof window.HTMLElement)) return;
104
93e21738b588 Run fix on whole body on start
nanaya <me@nanaya.net>
parents: 101
diff changeset
44
108
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 104
diff changeset
45 fix(node);
104
93e21738b588 Run fix on whole body on start
nanaya <me@nanaya.net>
parents: 101
diff changeset
46 for (const link of node.querySelectorAll(`[href^="${imageUrlPrefix}"]`)) {
108
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 104
diff changeset
47 fix(link);
104
93e21738b588 Run fix on whole body on start
nanaya <me@nanaya.net>
parents: 101
diff changeset
48 }
93e21738b588 Run fix on whole body on start
nanaya <me@nanaya.net>
parents: 101
diff changeset
49 }
93e21738b588 Run fix on whole body on start
nanaya <me@nanaya.net>
parents: 101
diff changeset
50
100
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
51 function onMutate (mutations) {
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
52 for (const mutation of mutations) {
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
53 for (const node of mutation.addedNodes) {
108
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 104
diff changeset
54 run(node);
85
9c8cde985caf Update standard and fix
nanaya <me@nanaya.pro>
parents: 82
diff changeset
55 }
9c8cde985caf Update standard and fix
nanaya <me@nanaya.pro>
parents: 82
diff changeset
56 }
100
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
57 }
78
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
58
108
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 104
diff changeset
59 const observer = new window.MutationObserver(onMutate);
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 104
diff changeset
60 observer.observe(document, { childList: true, subtree: true });
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 104
diff changeset
61 run(document.body);