-
Notifications
You must be signed in to change notification settings - Fork 105
/
isekaiscan.to.js
172 lines (143 loc) · 5.03 KB
/
isekaiscan.to.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
// ==MiruExtension==
// @name IsekaiScan
// @version v0.0.3
// @author bethro
// @lang en
// @license MIT
// @icon https://sp-ao.shortpixel.ai/client/to_webp,q_glossy,ret_img,w_192,h_192/https://m.isekaiscan.to/wp-content/uploads/2023/03/0_20230304_101820_0000-300x300.png
// @package isekaiscan.to
// @type manga
// @webSite https://m.isekaiscan.to
// ==/MiruExtension==
export default class extends Extension {
async req(url) {
return this.request(url, {
headers: {
"Miru-Url": await this.getSetting("isekaiscan"),
},
});
}
async load() {
this.registerSetting({
title: "Isekaiscan URL",
key: "isekaiscan",
type: "input",
description: "Homepage URL for Isekaiscan",
defaultValue: "https://m.isekaiscan.to",
});
this.registerSetting({
title: "Reverse Order of Chapters",
key: "reverseChaptersOrder",
type: "toggle",
description: "Reverse the order of chapters in ascending order",
defaultValue: "true",
});
// for latest & search page
this.registerSetting({
title: "resize cover images",
key: "imageResize",
type: "input",
description: "Image dimensions in pixels. Example: '372,496' (width,height)",
defaultValue: "386,556",
});
}
async latest(page) {
const res = await this.req(`/page/${page}/`);
const resizeValue = await this.getSetting("imageResize");
const latest = res.match(/<div class="page-item-detail manga">(.*?)<\/div>/gs);
const mangas = latest.map((element) => {
const urlMatch = element.match(/href="https:\/\/m.isekaiscan.to(.+?)"/);
const titleMatch = element.match(/<a href=".+?" title="(.+?)">/);
let coverMatch = element.match(/data-src="(.+?)"/);
if (urlMatch && titleMatch && coverMatch) {
const url = urlMatch[1];
const title = titleMatch[1];
coverMatch = coverMatch[1].replace(/\?resize=\d+,\d+/, `?resize=${resizeValue}`);
return {
title,
url,
cover: coverMatch,
};
}
}).filter(Boolean);
return mangas;
}
async search(kw, page) {
const res = await this.request(`/page/${page}/?s=${kw}&post_type=wp-manga`);
const resizeValue = await this.getSetting("imageResize");
const regex = /<div class="row c-tabs-item__content">(.*?)<\/div>/gs;
const Slist = Array.from(res.matchAll(regex));
const mangas = Slist.map((match) => {
const urlMatch = match[0].match(/href="https:\/\/m.isekaiscan.to(.+?)"/);
const titleMatch = match[0].match(/title="(.+?)"/);
const coverMatch = match[0].match(/data-src="(.+?)"/);
if (urlMatch && titleMatch && coverMatch) {
const url = urlMatch[1];
const title = titleMatch[1];
const cover = coverMatch[1].replace(/\?resize=\d+,\d+/, `?resize=${resizeValue}`);
return {
title,
url,
cover,
};
}
}).filter(Boolean);
return mangas;
}
async detail(url) {
const res = await this.req(url);
const html = res;
const extractContent = (regex, content) => {
const match = content.match(regex);
return match ? match[1] : null;
};
const title = extractContent(/div class="post-title"><h1>(.+?)<\/h1>/, html);
const cover = extractContent(/property="og:image" content="(.+?)"/, html);
const desc = extractContent(/<div class="summary__content"><p>(.+?)<\/p>/, html);
const chapters_res = await this.request(url + "ajax/chapters/", {
headers: {
"Miru-Url": await this.getSetting("isekaiscan"),
},
method: "POST"
});
const chaptersRegex = /<li\s+class\s*=\s*["']\s*wp-manga-chapter\s*["']\s*>(.*?)<\/li>/gs;
const chaptersMatch = chapters_res.match(chaptersRegex);
const chapters = [];
if (chaptersMatch) {
for (const element of chaptersMatch) {
const chapterUrl = extractContent(/href="https:\/\/m.isekaiscan.to(.+?)"/, element);
const chapterNum = extractContent(/Chapter (\d+)/, element);
if (chapterUrl && chapterNum) {
chapters.push({
name: `Chapter ${chapterNum}`,
url: chapterUrl,
});
}
}
}
if (await this.getSetting("reverseChaptersOrder") === "true") {
chapters.reverse();
}
return {
title: title || "Unknown Title",
cover,
desc: desc || "N/A",
episodes: [
{
title: "Chapters",
urls: chapters,
},
],
};
}
async watch(url) {
const res = await this.request(url);
const images = res.match(/<div\s+class\s*=\s*["']\s*page-break\s+no-gaps\s*["']\s*>(.*?)<\/div>/gs)
.map(element => element.match(/data-src="(.+?)"/))
.filter(imgMatch => imgMatch)
.map(imgMatch => imgMatch[1].trim());
return {
urls: images || [],
};
}
}