-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy pathmanwaba.js
More file actions
412 lines (391 loc) · 11 KB
/
Copy pathmanwaba.js
File metadata and controls
412 lines (391 loc) · 11 KB
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
/** @type {import('./_venera_.js')} */
class ManWaBa extends ComicSource {
// Note: The fields which are marked as [Optional] should be removed if not used
// name of the source
name = "漫蛙吧";
// unique id of the source
key = "manwaba";
version = "1.0.3";
minAppVersion = "1.4.0";
// update url
url = "https://cdn.jsdelivr.net/gh/venera-app/venera-configs@main/manwaba.js";
//修改域名不能用问题
api = "https://mwuu.cc/api";
init() {
/**
* Sends an HTTP request.
* @param {string} url - The URL to send the request to.
* @param {string} method - The HTTP method (e.g., GET, POST, PUT, PATCH, DELETE).
* @param {Object} params - The query parameters to include in the request.
* @param {Object} headers - The headers to include in the request.
* @param {string} payload - The payload to include in the request.
* @returns {Promise<Object>} The response from the request.
*/
this.fetchJson = async (
url,
{ method = "GET", params, headers, payload }
) => {
if (params) {
let params_str = Object.keys(params)
.map((key) => `${key}=${params[key]}`)
.join("&");
url += `?${params_str}`;
}
let res = await Network.sendRequest(method, url, headers, payload);
if (res.status !== 200) {
throw `Invalid status code: ${res.status}, body: ${res.body}`;
}
let json = JSON.parse(res.body);
return json;
};
this.logger = {
error: (msg) => {
log("error", this.name, msg);
},
info: (msg) => {
log("info", this.name, msg);
},
warn: (msg) => {
log("warning", this.name, msg);
},
};
}
// explore page list
explore = [
{
// title of the page.
// title is used to identify the page, it should be unique
title: this.name,
/// multiPartPage or multiPageComicList or mixed
type: "singlePageWithMultiPart",
/**
* load function
* @param page {number | null} - page number, null for `singlePageWithMultiPart` type
* @returns {{}}
* - for `multiPartPage` type, return [{title: string, comics: Comic[], viewMore: PageJumpTarget}]
* - for `multiPageComicList` type, for each page(1-based), return {comics: Comic[], maxPage: number}
* - for `mixed` type, use param `page` as index. for each index(0-based), return {data: [], maxPage: number?}, data is an array contains Comic[] or {title: string, comics: Comic[], viewMore: string?}
*/
load: async (page) => {
let params = {
page: 1,
pageSize: 6,
type: "",
flag: false,
};
const url = `${this.api}/home`;
const data = await this.fetchJson(url, { params }).then(
(res) => res.data
);
let magnaList = {
热门: data.comicList,
最新完整版: data.gufengList,
最新更新: data.xuanhuanList,
热门收藏: data.xiaoyuanList,
};
function parseComic(comic) {
return new Comic({
id: comic.id.toString(),
title: comic.title,
subTitle: comic.author,
cover: comic.pic,
tags: comic.tags.split(","),
});
}
let result = {};
for (let key in magnaList) {
result[key] = magnaList[key].map(parseComic);
}
return result;
},
},
];
// categories
category = {
/// title of the category page, used to identify the page, it should be unique
title: this.name,
parts: [
{
// title of the part
name: "类型",
// fixed or random or dynamic
// if random, need to provide `randomNumber` field, which indicates the number of comics to display at the same time
// if dynamic, need to provide `loader` field, which indicates the function to load comics
type: "fixed",
// Remove this if type is dynamic
categories: [
"全部",
"热血",
"玄幻",
"恋爱",
"冒险",
"古风",
"都市",
"穿越",
"奇幻",
"其他",
"搞笑",
"少男",
"战斗",
"重生",
"逆袭",
"爆笑",
"少年",
"后宫",
"系统",
"BL",
"韩漫",
"完整版",
"19r",
"台版",
],
itemType: "category",
categoryParams: [
"",
"热血",
"玄幻",
"恋爱",
"冒险",
"古风",
"都市",
"穿越",
"奇幻",
"其他",
"搞笑",
"少男",
"战斗",
"重生",
"逆袭",
"爆笑",
"少年",
"后宫",
"系统",
"BL",
"韩漫",
"完整版",
"19r",
"台版",
],
},
],
// enable ranking page
enableRankingPage: false,
};
/// category comic loading related
categoryComics = {
/**
* load comics of a category
* @param category {string} - category name
* @param param {string?} - category param
* @param options {string[]} - options from optionList
* @param page {number} - page number
* @returns {Promise<{comics: Comic[], maxPage: number}>}
*/
load: async (category, param, options, page) => {
let pathMap = {
"": "/cate",
"热血": "/cate/hotblooded",
"玄幻": "/cate/xuanhuan",
"恋爱": "/cate/romance",
"冒险": "/cate/adventure",
"古风": "/cate/historical",
"都市": "/cate/urban",
"穿越": "/cate/transmigration",
"奇幻": "/cate/fantasy",
"搞笑": "/cate/comedy",
"少男": "/cate/shounen",
"战斗": "/cate/action",
"重生": "/cate/rebirth",
"逆袭": "/cate/counterattack",
"爆笑": "/cate/hilarious",
"少年": "/cate/youth",
"系统": "/cate/system",
"BL": "/cate/bl",
"韩漫": "/cate/manhwa",
"完整版": "/cate/fullversion",
"19r": "/cate/19plus",
"台版": "/cate/taiwanver",
};
let url = this.api + pathMap[param] || "/cate";
let payload = JSON.stringify({
page: {
page: page,
pageSize: 10,
},
category: "comic",
sort: parseInt(options[2]),
comic: {
status: parseInt(options[0] == "2" ? -1 : options[0]),
day: parseInt(options[1]),
tag: param,
},
video: {
year: 0,
typeId: 0,
typeId1: 0,
area: "",
lang: "",
status: -1,
day: 0,
},
novel: {
status: -1,
day: 0,
sortId: 0,
},
});
let data = await this.fetchJson(url, {
method: "POST",
payload,
}).then((res) => res.data.list);
function parseComic(comic) {
return new Comic({
id: comic.url.split("/").pop(),
title: comic.title,
subTitle: comic.author,
cover: comic.pic,
tags: comic.tags.split(","),
description: comic.intro,
status: comic.status == 0 ? "连载中" : "已完结",
});
}
return {
comics: data.map(parseComic),
maxPage: 100,
};
},
// provide options for category comic loading
optionList: [
{
options: ["2-全部", "0-连载中", "1-已完结"],
},
{
options: [
"0-全部",
"1-周一",
"2-周二",
"3-周三",
"4-周四",
"5-周五",
"6-周六",
"7-周日",
],
},
{
options: ["0-更新", "1-新作", "2-畅销", "3-热门", "4-收藏"],
},
],
};
/// search related
search = {
/**
* load search result
* @param keyword {string}
* @param options {string[]} - options from optionList
* @param page {number}
* @returns {Promise<{comics: Comic[], maxPage: number}>}
*/
load: async (keyword, options, page) => {
const pageSize = 20;
let url = `${this.api}/search`;
let params = {
keyword,
type: "mh",
page,
pageSize,
};
let data = await this.fetchJson(url, { params }).then((res) => res.data);
let total = data.total;
let comics = data.list.map((item) => {
return new Comic({
id: item.id.toString(),
title: item.title,
subTitle: item.author,
cover: item.cover,
tags: item.tags.split(","),
description: item.description,
status: item.status == 0 ? "连载中" : "已完结",
});
});
let maxPage = Math.ceil(total / pageSize);
return {
comics,
maxPage,
};
},
};
/// single comic related
comic = {
/**
* load comic info
* @param id {string}
* @returns {Promise<ComicDetails>}s
*/
loadInfo: async (id) => {
let url = `${this.api}/comic/${id}`;
let data = await this.fetchJson(url, { payload: undefined }).then(
(res) => res.data
);
this.logger.warn(`loadInfo: ${data}`);
let chapterId = data.id;
let chapterApi = `${this.api}/comic/chapter`;
let params = {
comicId: chapterId,
page: 1,
pageSize: 1,
};
let pageRes = await this.fetchJson(chapterApi, { params });
let total = pageRes.pagination.total;
let chapterRes = await this.fetchJson(chapterApi, {
params: {
...params,
pageSize: total,
},
});
let chapterList = chapterRes.data;
let chapters = new Map();
chapterList.forEach((item) => {
chapters.set(item.id.toString(), item.title.toString());
});
return new ComicDetails({
title: data.title.toString(),
subTitle: data.author.toString(),
cover: data.cover,
tags: {
类型: data.tags.split(","),
状态: data.status == 0 ? "连载中" : "已完结",
},
chapters,
description: data.intro,
updateTime: new Date(data.editTime * 1000).toLocaleDateString(),
});
},
/**
* load images of a chapter
* @param comicId {string}
* @param epId {string?}
* @returns {Promise<{images: string[]}>}
*/
loadEp: async (comicId, epId) => {
let imgApi = `${this.api}/comic/image/${epId}`;
let params = {
page: 1,
pageSize: 1,
imageSource: "https://tu.mhttu.cc",
};
let pageNum = await this.fetchJson(imgApi, {
params,
}).then((res) => res.data.pagination.total);
let imageRes = await this.fetchJson(imgApi, {
params: {
...params,
page_size: pageNum,
},
}).then((res) => res.data.images);
let images = imageRes.map((item) => item.url);
return {
images,
};
},
};
}