-
Notifications
You must be signed in to change notification settings - Fork 105
/
wnmtl.org.js
102 lines (90 loc) · 2.56 KB
/
wnmtl.org.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
// ==MiruExtension==
// @name Wnmtl
// @version v0.0.1
// @author OshekharO
// @lang en
// @license MIT
// @icon https://wnmtl.com/logo.png
// @package wnmtl.org
// @type fikushon
// @webSite https://api.mystorywave.com/story-wave-backend/api/v1/content
// @nsfw false
// ==/MiruExtension==
export default class extends Extension {
async req(url) {
return this.request(url, {
headers: {
"Miru-Url": await this.getSetting("mystorywave"),
},
});
}
async load() {
this.registerSetting({
title: "MYSTORYWAVE API",
key: "mystorywave",
type: "input",
description: "MYSTORYWAVE API URL",
defaultValue: "https://api.mystorywave.com/story-wave-backend/api/v1/content",
});
}
async latest(page) {
const res = await this.req(`/books?pageNumber=${page}&pageSize=30`);
return res.data.list.map((item) => ({
url: item.id.toString(),
title: item.title,
cover: item.coverImgUrl,
}));
}
async detail(url) {
const res = await this.req(`/books/${url}`);
const id = res.data.id;
let page = 1;
let allEpisodes = [];
while (true) {
const epres = await this.req(`/chapters/page?sortDirection=ASC&bookId=${id}&pageNumber=${page}&pageSize=1000`);
const episodesOnPage = epres.data.list.map((item) => ({
name: item.title,
url: item.id.toString(),
}));
if (episodesOnPage.length === 0) {
break;
}
allEpisodes = allEpisodes.concat(episodesOnPage);
page++;
}
return {
title: res.data.title,
cover: res.data.coverImgUrl,
desc: res.data.synopsis,
episodes: [
{
title: "Chapters",
urls: allEpisodes,
},
],
};
}
async search(kw, page) {
const res = await this.req(`/books/search?keyWord=${kw}&pageNumber=${page}&pageSize=50`);
if (res.data && Array.isArray(res.data.list)) {
return res.data.list.map((item) => ({
title: item.title || "",
url: item.id ? item.id.toString() : "",
cover: item.coverImgUrl || "",
}));
} else {
return [];
}
}
async watch(url) {
const res = await this.req(`/chapters/${url}`);
let chapterContentDiv = res.data.content;
chapterContentDiv = chapterContentDiv.replace(/<\/?p>|<br\s*\/?>/gi, "\n");
chapterContentDiv = chapterContentDiv.replace(/\n{2,}/g, "\n");
const content = chapterContentDiv.split("\n");
return {
title: res.data.title,
content: content,
};
}
}