annotate pixiv-fanbox-unlazy.user.js @ 101:e21710f5dd7b

Also run on its own node
author nanaya <me@nanaya.net>
date Sat, 24 Dec 2022 21:31:42 +0900
parents 74c33632c353
children 93e21738b588
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
101
e21710f5dd7b Also run on its own node
nanaya <me@nanaya.net>
parents: 100
diff changeset
4 // @version 2.1.1
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
100
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
42 function onMutate (mutations) {
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
43 for (const mutation of mutations) {
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
44 for (const node of mutation.addedNodes) {
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
45 if (node instanceof window.HTMLElement) {
101
e21710f5dd7b Also run on its own node
nanaya <me@nanaya.net>
parents: 100
diff changeset
46 fix(node)
100
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
47 for (const link of node.querySelectorAll(`[href^="${imageUrlPrefix}"]`)) {
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
48 fix(link)
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
49 }
85
9c8cde985caf Update standard and fix
nanaya <me@nanaya.pro>
parents: 82
diff changeset
50 }
9c8cde985caf Update standard and fix
nanaya <me@nanaya.pro>
parents: 82
diff changeset
51 }
9c8cde985caf Update standard and fix
nanaya <me@nanaya.pro>
parents: 82
diff changeset
52 }
100
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
53 }
78
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
54
100
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
55 const observer = new window.MutationObserver(onMutate)
74c33632c353 Simplify script
nanaya <me@nanaya.net>
parents: 85
diff changeset
56 observer.observe(document, { childList: true, subtree: true })