annotate melonbooks-unlazy.user.js @ 116:0e108a9dc6d7

Split suruga-ya scripts
author nanaya <me@nanaya.net>
date Sun, 15 Jan 2023 23:46:56 +0900
parents ef21ef445fc6
children d9dc190bccaf
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
104
93e21738b588 Run fix on whole body on start
nanaya <me@nanaya.net>
parents: 102
diff changeset
7 // @version 1.0.5
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
108
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 104
diff changeset
13 'use strict';
95
afad36fddb64 Add melonbooks unlazy
nanaya <me@nanaya.net>
parents:
diff changeset
14
109
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
15 function unlazy () {
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
16 function fix (image) {
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
17 if (!image.classList.contains('lazyload')) return;
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
18
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
19 const src = image.dataset.src;
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
20
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
21 if (src == null || src === '') return;
102
3fded109e23a Also run on own node
nanaya <me@nanaya.net>
parents: 99
diff changeset
22
109
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
23 image.classList.remove('lazyload');
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
24 image.src = image.dataset.src;
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
25 delete image.dataset.src;
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
26 }
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
27
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
28 function run (node) {
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
29 if (!(node instanceof window.HTMLElement)) return;
98
3e5f1fa9ed52 Skip redundant class check and add dataset check instead
nanaya <me@nanaya.net>
parents: 97
diff changeset
30
109
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
31 fix(node);
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
32 for (const image of node.querySelectorAll('.lazyload')) {
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
33 fix(image);
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
34 }
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
35 }
97
c8f9350c5307 More thorough lazyload monitor
nanaya <me@nanaya.net>
parents: 96
diff changeset
36
109
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
37 function onMutate (mutations) {
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
38 for (const mutation of mutations) {
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
39 for (const node of mutation.addedNodes) {
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
40 run(node);
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
41 }
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
42 }
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
43 }
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
44
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
45 const observer = new window.MutationObserver(onMutate);
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
46 observer.observe(document, { childList: true, subtree: true });
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
47 run(document.body);
97
c8f9350c5307 More thorough lazyload monitor
nanaya <me@nanaya.net>
parents: 96
diff changeset
48 }
95
afad36fddb64 Add melonbooks unlazy
nanaya <me@nanaya.net>
parents:
diff changeset
49
109
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
50 unlazy();