annotate pixiv-fanbox-unlazy.user.js @ 113:647ade033475

Backed out changeset 684704b5adbf
author nanaya <me@nanaya.net>
date Sun, 15 Jan 2023 23:43:37 +0900
parents ef21ef445fc6
children d9dc190bccaf
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
109
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
3 // @namespace https://nanaya.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
109
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
15 function unlazy () {
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
16 const imageUrlPrefix = 'https://downloads.fanbox.cc/images/post/';
78
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
17
109
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
18 function disableEventLink (event) {
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
19 event.stopPropagation();
78
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
20 }
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
21
109
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
22 function fix (link) {
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
23 const href = link.href;
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
24
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
25 // basic sanity check
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
26 if (typeof href !== 'string' || !href.startsWith(imageUrlPrefix)) {
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
27 return;
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
28 }
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
29
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
30 // don't run again if already run on passed link
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
31 if (link._ecUserscript) {
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
32 return;
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
33 }
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
34 link._ecUserscript = true;
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
35
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
36 link.addEventListener('click', disableEventLink);
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
37 const image = document.createElement('img');
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
38 image.style.width = '100%';
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
39 image.src = href;
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
40 link.replaceChildren(image);
78
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
41 }
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
42
109
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
43 function run (node) {
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
44 if (!(node instanceof window.HTMLElement)) return;
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
45
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
46 fix(node);
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
47 for (const link of node.querySelectorAll(`[href^="${imageUrlPrefix}"]`)) {
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
48 fix(link);
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
49 }
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
50 }
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
51
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
52 function onMutate (mutations) {
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
53 for (const mutation of mutations) {
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
54 for (const node of mutation.addedNodes) {
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
55 run(node);
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
56 }
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
57 }
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
58 }
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
59
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
60 const observer = new window.MutationObserver(onMutate);
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
61 observer.observe(document, { childList: true, subtree: true });
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
62 run(document.body);
100
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
63 }
85
9c8cde985caf Update standard and fix
nanaya <me@nanaya.pro>
parents: 82
diff changeset
64
109
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
65 unlazy();