annotate pixiv-fanbox-unlazy.user.js @ 81:e30cd7fbee42

Actually working
author nanaya <me@nanaya.pro>
date Sat, 03 Oct 2020 02:21:56 +0900
parents 86daedfccb43
children 86da34e62d29
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
81
e30cd7fbee42 Actually working
nanaya <me@nanaya.pro>
parents: 80
diff changeset
4 // @version 2.0.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
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
9 // @downloadURL https://hg.sr.ht/~nanaya/ec-userscripts/raw/pixiv-fanbox-unlazy.user.js?rev=tip
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
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
15 var imageUrlPrefix = 'https://downloads.fanbox.cc/images/post/'
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
16
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
17 // loop through passed nodes (or body if called without arguments)
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
18 var run = function (nodes) {
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
19 if (nodes == null) {
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
20 nodes = [document.body]
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
21 }
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
22
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
23 for (var i = 0; i < nodes.length; i++) {
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
24 // first try fixing itself
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
25 fix(nodes[i])
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
26
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
27 // and then find all the links inside
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
28 var links = nodes[i].querySelectorAll(`[href^="${imageUrlPrefix}"]`)
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
29
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
30 for (var j = 0; j < links.length; j++) {
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
31 fix(links[j])
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
32 }
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
33 }
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
34 }
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 var fix = function (link) {
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
37 var href = link.href
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
38
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
39 // basic sanity check
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
40 if (typeof href !== 'string' || !href.startsWith(imageUrlPrefix)) {
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
41 return
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
42 }
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
43
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
44 // 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
45 if (link._ecUserscript) {
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
46 return
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
47 }
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
48 link._ecUserscript = true
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
49
81
e30cd7fbee42 Actually working
nanaya <me@nanaya.pro>
parents: 80
diff changeset
50 link.addEventListener('click', (event) => {
e30cd7fbee42 Actually working
nanaya <me@nanaya.pro>
parents: 80
diff changeset
51 event.stopPropagation()
e30cd7fbee42 Actually working
nanaya <me@nanaya.pro>
parents: 80
diff changeset
52 })
78
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
53 link.innerHTML = `<img style="width: 100%;" src="${href}" />`
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
54 }
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
55
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
56 var onMutate = function (mutations) {
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
57 for (var mutation in mutations) {
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
58 run(mutation.addedNodes)
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
59 }
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
60 }
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
61
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
62 // the observer
9dc1be1a6c7a Bye image lazy loading on pixiv fanbox
nanaya <me@nanaya.pro>
parents:
diff changeset
63 var observer = new window.MutationObserver(onMutate)
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()