78
|
1 // ==UserScript==
|
|
2 // @name pixiv fanbox no lazy loading image
|
|
3 // @namespace https://myconan.net
|
|
4 // @version 1.0.0
|
|
5 // @description Lazy loading is bad for environment. Disable it.
|
|
6 // @author nanaya
|
|
7 // @match https://tweetdeck.twitter.com/*
|
|
8 // @grant none
|
|
9 // @downloadURL https://hg.sr.ht/~nanaya/ec-userscripts/raw/pixiv-fanbox-unlazy.user.js?rev=tip
|
|
10 // ==/UserScript==
|
|
11
|
|
12 ;(function () {
|
|
13 'use strict'
|
|
14
|
|
15 var imageUrlPrefix = 'https://downloads.fanbox.cc/images/post/'
|
|
16
|
|
17 // loop through passed nodes (or body if called without arguments)
|
|
18 var run = function (nodes) {
|
|
19 if (nodes == null) {
|
|
20 nodes = [document.body]
|
|
21 }
|
|
22
|
|
23 for (var i = 0; i < nodes.length; i++) {
|
|
24 // first try fixing itself
|
|
25 fix(nodes[i])
|
|
26
|
|
27 // and then find all the links inside
|
|
28 var links = nodes[i].querySelectorAll(`[href^="${imageUrlPrefix}"]`)
|
|
29
|
|
30 for (var j = 0; j < links.length; j++) {
|
|
31 fix(links[j])
|
|
32 }
|
|
33 }
|
|
34 }
|
|
35
|
|
36 var fix = function (link) {
|
|
37 var href = link.href
|
|
38
|
|
39 // basic sanity check
|
|
40 if (typeof href !== 'string' || !href.startsWith(imageUrlPrefix)) {
|
|
41 return
|
|
42 }
|
|
43
|
|
44 // don't run again if already run on passed link
|
|
45 if (link._ecUserscript) {
|
|
46 return
|
|
47 }
|
|
48 link._ecUserscript = true
|
|
49
|
|
50 link.innerHTML = `<img style="width: 100%;" src="${href}" />`
|
|
51 }
|
|
52
|
|
53 var onMutate = function (mutations) {
|
|
54 for (var mutation in mutations) {
|
|
55 run(mutation.addedNodes)
|
|
56 }
|
|
57 }
|
|
58
|
|
59 // the observer
|
|
60 var observer = new window.MutationObserver(onMutate)
|
|
61
|
|
62 // start the observer
|
|
63 observer.observe(document, { childList: true, subtree: true })
|
|
64 // initial run on existing document
|
|
65 run()
|
|
66 }).call()
|