annotate pixiv-fanbox-unlazy.user.js @ 88:14eafa2920c8

Update dependencies
author nanaya <me@nanaya.pro>
date Sat, 04 Dec 2021 04:06:31 +0900
parents 9c8cde985caf
children 74c33632c353
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
82
86da34e62d29 Update url
nanaya <me@nanaya.pro>
parents: 81
diff changeset
4 // @version 2.0.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
82
86da34e62d29 Update url
nanaya <me@nanaya.pro>
parents: 81
diff changeset
9 // @downloadURL https://hg.myconan.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
10 // ==/UserScript==
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
11
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
12 ;(function () {
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
13 'use strict'
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
14
85
9c8cde985caf Update standard and fix
nanaya <me@nanaya.pro>
parents: 82
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
85
9c8cde985caf Update standard and fix
nanaya <me@nanaya.pro>
parents: 82
diff changeset
17 const fix = function (link) {
9c8cde985caf Update standard and fix
nanaya <me@nanaya.pro>
parents: 82
diff changeset
18 const href = link.href
78
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
19
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
20 // basic sanity check
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
21 if (typeof href !== 'string' || !href.startsWith(imageUrlPrefix)) {
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
22 return
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
23 }
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
24
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
25 // don't run again if already run on passed link
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
26 if (link._ecUserscript) {
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
27 return
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
28 }
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
29 link._ecUserscript = true
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
30
81
e30cd7fbee42 Actually working
nanaya <me@nanaya.pro>
parents: 80
diff changeset
31 link.addEventListener('click', (event) => {
e30cd7fbee42 Actually working
nanaya <me@nanaya.pro>
parents: 80
diff changeset
32 event.stopPropagation()
e30cd7fbee42 Actually working
nanaya <me@nanaya.pro>
parents: 80
diff changeset
33 })
78
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
34 link.innerHTML = `<img style="width: 100%;" src="${href}" />`
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
35 }
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
36
85
9c8cde985caf Update standard and fix
nanaya <me@nanaya.pro>
parents: 82
diff changeset
37 const onMutate = function (mutations) {
9c8cde985caf Update standard and fix
nanaya <me@nanaya.pro>
parents: 82
diff changeset
38 for (const mutation in mutations) {
78
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
39 run(mutation.addedNodes)
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
40 }
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
85
9c8cde985caf Update standard and fix
nanaya <me@nanaya.pro>
parents: 82
diff changeset
43 // loop through passed nodes (or body if called without arguments)
9c8cde985caf Update standard and fix
nanaya <me@nanaya.pro>
parents: 82
diff changeset
44 const run = function (nodes) {
9c8cde985caf Update standard and fix
nanaya <me@nanaya.pro>
parents: 82
diff changeset
45 if (nodes == null) {
9c8cde985caf Update standard and fix
nanaya <me@nanaya.pro>
parents: 82
diff changeset
46 nodes = [document.body]
9c8cde985caf Update standard and fix
nanaya <me@nanaya.pro>
parents: 82
diff changeset
47 }
9c8cde985caf Update standard and fix
nanaya <me@nanaya.pro>
parents: 82
diff changeset
48
9c8cde985caf Update standard and fix
nanaya <me@nanaya.pro>
parents: 82
diff changeset
49 for (let i = 0; i < nodes.length; i++) {
9c8cde985caf Update standard and fix
nanaya <me@nanaya.pro>
parents: 82
diff changeset
50 // first try fixing itself
9c8cde985caf Update standard and fix
nanaya <me@nanaya.pro>
parents: 82
diff changeset
51 fix(nodes[i])
9c8cde985caf Update standard and fix
nanaya <me@nanaya.pro>
parents: 82
diff changeset
52
9c8cde985caf Update standard and fix
nanaya <me@nanaya.pro>
parents: 82
diff changeset
53 // and then find all the links inside
9c8cde985caf Update standard and fix
nanaya <me@nanaya.pro>
parents: 82
diff changeset
54 const links = nodes[i].querySelectorAll(`[href^="${imageUrlPrefix}"]`)
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 for (let j = 0; j < links.length; j++) {
9c8cde985caf Update standard and fix
nanaya <me@nanaya.pro>
parents: 82
diff changeset
57 fix(links[j])
9c8cde985caf Update standard and fix
nanaya <me@nanaya.pro>
parents: 82
diff changeset
58 }
9c8cde985caf Update standard and fix
nanaya <me@nanaya.pro>
parents: 82
diff changeset
59 }
9c8cde985caf Update standard and fix
nanaya <me@nanaya.pro>
parents: 82
diff changeset
60 }
9c8cde985caf Update standard and fix
nanaya <me@nanaya.pro>
parents: 82
diff changeset
61
78
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
62 // the observer
85
9c8cde985caf Update standard and fix
nanaya <me@nanaya.pro>
parents: 82
diff changeset
63 const observer = new window.MutationObserver(onMutate)
78
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
64
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
65 // start the observer
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
66 observer.observe(document, { childList: true, subtree: true })
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
67 // initial run on existing document
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
68 run()
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
69 }).call()