annotate melonbooks-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 b44d5cb661c5
children 3fded109e23a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
95
afad36fddb64 Add melonbooks unlazy
nanaya <me@nanaya.net>
parents:
diff changeset
1 // ==UserScript==
afad36fddb64 Add melonbooks unlazy
nanaya <me@nanaya.net>
parents:
diff changeset
2 // @name melonbooks unlazy
afad36fddb64 Add melonbooks unlazy
nanaya <me@nanaya.net>
parents:
diff changeset
3 // @namespace https://nanaya.net
afad36fddb64 Add melonbooks unlazy
nanaya <me@nanaya.net>
parents:
diff changeset
4 // @match https://www.melonbooks.co.jp/*
afad36fddb64 Add melonbooks unlazy
nanaya <me@nanaya.net>
parents:
diff changeset
5 // @grant none
97
c8f9350c5307 More thorough lazyload monitor
nanaya <me@nanaya.net>
parents: 96
diff changeset
6 // @run-at document-start
99
b44d5cb661c5 Also check for empty string
nanaya <me@nanaya.net>
parents: 98
diff changeset
7 // @version 1.0.3
95
afad36fddb64 Add melonbooks unlazy
nanaya <me@nanaya.net>
parents:
diff changeset
8 // @author nanaya
afad36fddb64 Add melonbooks unlazy
nanaya <me@nanaya.net>
parents:
diff changeset
9 // @description replace lazy loaded images with just images
afad36fddb64 Add melonbooks unlazy
nanaya <me@nanaya.net>
parents:
diff changeset
10 // @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/melonbooks-unlazy.user.js
afad36fddb64 Add melonbooks unlazy
nanaya <me@nanaya.net>
parents:
diff changeset
11 // ==/UserScript==
afad36fddb64 Add melonbooks unlazy
nanaya <me@nanaya.net>
parents:
diff changeset
12
afad36fddb64 Add melonbooks unlazy
nanaya <me@nanaya.net>
parents:
diff changeset
13 'use strict'
afad36fddb64 Add melonbooks unlazy
nanaya <me@nanaya.net>
parents:
diff changeset
14
97
c8f9350c5307 More thorough lazyload monitor
nanaya <me@nanaya.net>
parents: 96
diff changeset
15 function fix (image) {
98
3e5f1fa9ed52 Skip redundant class check and add dataset check instead
nanaya <me@nanaya.net>
parents: 97
diff changeset
16 const src = image.dataset.src
3e5f1fa9ed52 Skip redundant class check and add dataset check instead
nanaya <me@nanaya.net>
parents: 97
diff changeset
17
99
b44d5cb661c5 Also check for empty string
nanaya <me@nanaya.net>
parents: 98
diff changeset
18 if (src == null || src === '') return
97
c8f9350c5307 More thorough lazyload monitor
nanaya <me@nanaya.net>
parents: 96
diff changeset
19
c8f9350c5307 More thorough lazyload monitor
nanaya <me@nanaya.net>
parents: 96
diff changeset
20 image.classList.remove('lazyload')
c8f9350c5307 More thorough lazyload monitor
nanaya <me@nanaya.net>
parents: 96
diff changeset
21 image.src = image.dataset.src
c8f9350c5307 More thorough lazyload monitor
nanaya <me@nanaya.net>
parents: 96
diff changeset
22 delete image.dataset.src
c8f9350c5307 More thorough lazyload monitor
nanaya <me@nanaya.net>
parents: 96
diff changeset
23 }
95
afad36fddb64 Add melonbooks unlazy
nanaya <me@nanaya.net>
parents:
diff changeset
24
97
c8f9350c5307 More thorough lazyload monitor
nanaya <me@nanaya.net>
parents: 96
diff changeset
25 function onMutate (mutations) {
c8f9350c5307 More thorough lazyload monitor
nanaya <me@nanaya.net>
parents: 96
diff changeset
26 for (const mutation of mutations) {
c8f9350c5307 More thorough lazyload monitor
nanaya <me@nanaya.net>
parents: 96
diff changeset
27 for (const node of mutation.addedNodes) {
c8f9350c5307 More thorough lazyload monitor
nanaya <me@nanaya.net>
parents: 96
diff changeset
28 if (node instanceof window.HTMLElement) {
c8f9350c5307 More thorough lazyload monitor
nanaya <me@nanaya.net>
parents: 96
diff changeset
29 for (const image of node.querySelectorAll('.lazyload')) {
c8f9350c5307 More thorough lazyload monitor
nanaya <me@nanaya.net>
parents: 96
diff changeset
30 fix(image)
c8f9350c5307 More thorough lazyload monitor
nanaya <me@nanaya.net>
parents: 96
diff changeset
31 }
c8f9350c5307 More thorough lazyload monitor
nanaya <me@nanaya.net>
parents: 96
diff changeset
32 }
c8f9350c5307 More thorough lazyload monitor
nanaya <me@nanaya.net>
parents: 96
diff changeset
33 }
95
afad36fddb64 Add melonbooks unlazy
nanaya <me@nanaya.net>
parents:
diff changeset
34 }
afad36fddb64 Add melonbooks unlazy
nanaya <me@nanaya.net>
parents:
diff changeset
35 }
97
c8f9350c5307 More thorough lazyload monitor
nanaya <me@nanaya.net>
parents: 96
diff changeset
36
c8f9350c5307 More thorough lazyload monitor
nanaya <me@nanaya.net>
parents: 96
diff changeset
37 const observer = new window.MutationObserver(onMutate)
c8f9350c5307 More thorough lazyload monitor
nanaya <me@nanaya.net>
parents: 96
diff changeset
38 observer.observe(document, { childList: true, subtree: true })