-
Notifications
You must be signed in to change notification settings - Fork 0
/
mangaInfiniteScrollBundle.user.js
325 lines (325 loc) · 13.3 KB
/
mangaInfiniteScrollBundle.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
// ==UserScript==
// @name mangaInfiniteScrollBundle
// @namespace https://github.com/plong-wasin
// @version 0.9.2
// @description Read manga with infinite scroll
// @author Plong-Wasin
// @updateURL https://github.com/Plong-Wasin/manga-infinite-scroll/raw/main/mangaInfiniteScrollBundle.user.js
// @downloadURL https://github.com/Plong-Wasin/manga-infinite-scroll/raw/main/mangaInfiniteScrollBundle.user.js
// @match https://*/*
// @grant none
// ==/UserScript==
"use strict";
(() => {
function ready(fn) {
if (document.readyState != "loading") {
fn();
}
else {
document.addEventListener("DOMContentLoaded", fn);
}
}
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
function changeUrl(url) {
history.replaceState(null, "", url);
}
function loadPage() {
const images = document.querySelectorAll("image[loading='lazy']");
for (let i = 0; i < images.length && i < 3; i++) {
images[i].loading = "eager";
}
}
function addEventToImg() {
const els = document.querySelectorAll('img[loading="lazy"]');
if (els.length > 0) {
const el = els[els.length - 1];
el.loading = "eager";
}
els.forEach((el, index) => {
el.addEventListener("load", () => {
for (let j = 1; j + index < els.length && j <= 3; j++) {
const el = els[j + index];
el.loading = "eager";
}
});
el.addEventListener("error", function () {
const countError = this.dataset.countError || 1;
if (+countError < 3) {
this.dataset.countError = `${+countError + 1}`;
}
else {
return;
}
for (let j = 1; j + index < els.length && j <= 3; j++) {
const el = els[j + index];
el.loading = "eager";
}
setTimeout(() => {
const imgSrc = el.src;
this.src = imgSrc;
}, 1000);
});
});
}
function manga({ nextChapterSelector, containerSelector, imageBlockSelector = "", callback = () => void 0, }) {
const containerEl = document.querySelector(containerSelector);
let loading = false;
let nextChapterEl = document.querySelector(nextChapterSelector);
let nextChapterLink = nextChapterEl?.href;
window.addEventListener("scroll", () => {
void (async () => {
if (containerEl) {
if (!loading &&
nextChapterLink &&
window.scrollY + window.innerHeight * 2 >
containerEl.offsetTop + containerEl.offsetHeight) {
loading = true;
const tempImg = document.createElement("img");
tempImg.style.height = `${window.innerHeight}px`;
containerEl.appendChild(tempImg);
const res = await fetch(nextChapterLink);
const text = await res.text();
const parser = new DOMParser();
const doc = parser.parseFromString(text, "text/html");
const divEls = doc.querySelectorAll(`${containerSelector} ${imageBlockSelector}`);
for (const divEl of divEls) {
const img = divEl.querySelector(`img`) ||
divEl;
callback(divEl, img);
if (img) {
img.loading = "lazy";
containerEl.appendChild(divEl);
}
}
containerEl.appendChild(tempImg);
addEventToImg();
loadPage();
const docTitleEl = doc.querySelector("title");
const titleEl = document.querySelector("title");
if (docTitleEl && titleEl) {
titleEl.innerText = docTitleEl.innerText;
}
changeUrl(nextChapterLink);
nextChapterEl = doc.querySelector(nextChapterSelector);
nextChapterLink = nextChapterEl?.href;
await sleep(1000);
tempImg.remove();
loading = false;
}
}
})();
});
}
function init() {
return {
mangakakalot: () => {
const params = {
nextChapterSelector: ".btn-navigation-chap .back",
containerSelector: ".container-chapter-reader",
imageBlockSelector: "img",
callback(blockElement, imageElement) {
const selectElement = document.querySelector(".pn-op-sv-cbb-content-margin");
const selectValue = selectElement?.value;
if (selectValue) {
imageElement.style.marginTop = `${selectValue}px`;
}
},
};
manga(params);
},
readmanganato: () => {
const params = {
nextChapterSelector: ".navi-change-chapter-btn-next",
containerSelector: ".container-chapter-reader",
imageBlockSelector: "img",
callback(blockElement, imageElement) {
const selectElement = document.querySelector(".server-cbb-content-margin");
const selectValue = selectElement?.value;
if (selectValue) {
imageElement.style.marginTop = `${selectValue}px`;
}
},
};
manga(params);
},
_365manga: () => {
const params = {
nextChapterSelector: ".nav-next a",
containerSelector: ".reading-content",
imageBlockSelector: ".page-break.no-gaps",
};
manga(params);
},
mangauptocats: () => {
const params = {
nextChapterSelector: ".nav-next a",
containerSelector: ".reading-content",
imageBlockSelector: ".page-break",
};
manga(params);
},
rh2plusmanga: () => {
const params = {
nextChapterSelector: ".btn.next_page",
containerSelector: ".text-left p code",
imageBlockSelector: "img",
};
manga(params);
},
manga00: () => {
const params = {
nextChapterSelector: ".nvs.rght a",
containerSelector: "#image_manga",
imageBlockSelector: "img",
callback(blockElement, imageElement) {
imageElement.src = imageElement.dataset.cfsrc ?? imageElement.src;
},
};
manga(params);
},
niceoppai: () => {
const params = {
nextChapterSelector: ".nav_pag .nxt",
containerSelector: "#image-container",
imageBlockSelector: "center",
};
manga(params);
},
mangaisekaithai: () => {
const params = {
nextChapterSelector: "a.btn.next_page",
containerSelector: ".text-left p",
imageBlockSelector: "img",
};
manga(params);
},
mangatitan: () => {
const params = {
nextChapterSelector: ".next_page",
containerSelector: ".reading-content",
imageBlockSelector: ".page-break.no-gaps",
callback(blockElement, imageElement) {
imageElement.src = imageElement.dataset.src ?? imageElement.src;
},
};
manga(params);
},
oremanga: () => {
const params = {
nextChapterSelector: ".nav-chapter a[rel='next']",
containerSelector: ".reader-area-main",
imageBlockSelector: "img",
};
manga(params);
},
mangadex: () => {
const params = {
nextChapterSelector: "a.rounded.relative.md-btn.flex.items-center.px-3.justify-center.text-white.bg-primary.hover:bg-primary-darken.active:bg-primary-darken2.px-4.px-6",
containerSelector: ".md--pages.flex-grow.flex-col>div",
imageBlockSelector: "img",
};
manga(params);
},
mangadeemak: () => {
const params = {
nextChapterSelector: ".nav-next a",
containerSelector: ".reading-content",
imageBlockSelector: ".page-break.no-gaps",
callback(blockElement, imageElement) {
imageElement.src = imageElement.dataset.src ?? imageElement.src;
},
};
manga(params);
},
kingsmanga: () => {
const params = {
nextChapterSelector: "[rel='next']:not(.nextpostslink)",
containerSelector: ".post-content",
imageBlockSelector: "img",
};
manga(params);
},
mangaclash: () => {
const params = {
nextChapterSelector: ".btn.next_page",
containerSelector: ".reading-content",
imageBlockSelector: ".page-break.no-gaps",
callback(blockElement, imageElement) {
imageElement.src = imageElement.dataset.src ?? imageElement.src;
},
};
manga(params);
},
catsTranslator: () => {
const params = {
nextChapterSelector: ".btn.next_page",
containerSelector: ".reading-content",
imageBlockSelector: ".page-break",
callback(blockElement, imageElement) {
imageElement.src = imageElement.dataset.src ?? imageElement.src;
},
};
manga(params);
},
german66: () => {
const params = {
nextChapterSelector: ".rightnav>a",
containerSelector: "div.reader-area > p",
imageBlockSelector: "img",
};
manga(params);
},
mangapost: () => {
const params = {
nextChapterSelector: ".nav-next > a",
containerSelector: ".reading-content",
imageBlockSelector: ".page-break.no-gaps",
};
manga(params);
},
kaichan: () => {
const params = {
nextChapterSelector: "a.btn.btn-xs.rounded-md:last-child",
containerSelector: ".px-4.py-4.relative",
imageBlockSelector: ".w-full.h-full.flex.justify-center",
callback(blockElement, imageElement) {
imageElement.src = imageElement.dataset.src ?? imageElement.src;
imageElement.loading = "eager";
},
};
manga(params);
},
};
}
ready(() => {
const url = new URL(location.href);
const host = url.host;
const hosts = {
"mangakakalot.com": init().mangakakalot,
"readmanganato.com": init().readmanganato,
"365manga.com": init()._365manga,
"mangauptocats.net": init().mangauptocats,
"www.rh2plusmanga.com": init().rh2plusmanga,
"manga00.com": init().manga00,
"www.niceoppai.net": init().niceoppai,
"www.mangaisekaithai.com": init().mangaisekaithai,
"manga-titan.com": init().mangatitan,
"www.oremanga.net": init().oremanga,
"mangadex.org": init().mangadex,
"mangadeemak.com": init().mangadeemak,
"www.kingsmanga.net": init().kingsmanga,
"mangaclash.com": init().mangaclash,
"cats-translator.com": init().catsTranslator,
"chapmanganato.com": init().readmanganato,
"chapmanganato.to": init().readmanganato,
"germa-66.com": init().german66,
"manga-post.com": init().mangapost,
"kaichan.co": init().kaichan,
};
if (hosts[host]) {
hosts[host]();
}
});
})();