Mercurial > ec-userscripts
annotate pixiv-fanbox-unlazy.user.js @ 80:86daedfccb43
Remove click event on the link itself
author | nanaya <me@nanaya.pro> |
---|---|
date | Sat, 03 Oct 2020 02:15:58 +0900 |
parents | e4b970501e8e |
children | e30cd7fbee42 |
rev | line source |
---|---|
78 | 1 // ==UserScript== |
2 // @name pixiv fanbox no lazy loading image | |
3 // @namespace https://myconan.net | |
80
86daedfccb43
Remove click event on the link itself
nanaya <me@nanaya.pro>
parents:
79
diff
changeset
|
4 // @version 2.0.0 |
78 | 5 // @description Lazy loading is bad for environment. Disable it. |
6 // @author nanaya | |
79 | 7 // @match https://*.fanbox.cc/* |
78 | 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 | |
80
86daedfccb43
Remove click event on the link itself
nanaya <me@nanaya.pro>
parents:
79
diff
changeset
|
50 link.onclick = null |
78 | 51 link.innerHTML = `<img style="width: 100%;" src="${href}" />` |
52 } | |
53 | |
54 var onMutate = function (mutations) { | |
55 for (var mutation in mutations) { | |
56 run(mutation.addedNodes) | |
57 } | |
58 } | |
59 | |
60 // the observer | |
61 var observer = new window.MutationObserver(onMutate) | |
62 | |
63 // start the observer | |
64 observer.observe(document, { childList: true, subtree: true }) | |
65 // initial run on existing document | |
66 run() | |
67 }).call() |