annotate pixiv-fanbox-unlazy.user.js @ 105:6b354277f2d1

[surugaya-fixes] faster image load
author nanaya <me@nanaya.net>
date Sun, 08 Jan 2023 00:02:28 +0900
parents 93e21738b588
children 2c4470b73ad9
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
100
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
13 'use strict'
78
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
14
100
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
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) {
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
18 event.stopPropagation()
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) {
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
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)) {
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
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) {
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
31 return
78
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
32 }
100
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
33 link._ecUserscript = true
78
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
34
100
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
35 link.addEventListener('click', disableEventLink)
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
36 const image = document.createElement('img')
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
37 image.style.width = '100%'
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
38 image.src = href
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
39 link.replaceChildren(image)
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) {
93e21738b588 Run fix on whole body on start
nanaya <me@nanaya.net>
parents: 101
diff changeset
43 if (!(node instanceof window.HTMLElement)) return
93e21738b588 Run fix on whole body on start
nanaya <me@nanaya.net>
parents: 101
diff changeset
44
93e21738b588 Run fix on whole body on start
nanaya <me@nanaya.net>
parents: 101
diff changeset
45 fix(node)
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}"]`)) {
93e21738b588 Run fix on whole body on start
nanaya <me@nanaya.net>
parents: 101
diff changeset
47 fix(link)
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) {
104
93e21738b588 Run fix on whole body on start
nanaya <me@nanaya.net>
parents: 101
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
100
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
59 const observer = new window.MutationObserver(onMutate)
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
60 observer.observe(document, { childList: true, subtree: true })
104
93e21738b588 Run fix on whole body on start
nanaya <me@nanaya.net>
parents: 101
diff changeset
61 run(document.body)