-
Notifications
You must be signed in to change notification settings - Fork 102
/
manganato.js
142 lines (126 loc) · 3.41 KB
/
manganato.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
// ==MiruExtension==
// @name Manganato
// @version v0.0.1
// @author OshekharO
// @lang en
// @license MIT
// @icon https://manganato.com/themes/hm/images/logo.png
// @package manganato
// @type manga
// @webSite https://manganato.com
// ==/MiruExtension==
export default class extends Extension {
async req(url) {
return this.request(url, {
headers: {
"Miru-Url": await this.getSetting("manganato"),
},
});
}
async load() {
this.registerSetting({
title: "Base URL",
key: "manganato",
type: "input",
description: "Homepage URL for Manganato",
defaultValue: "https://manganato.com",
});
this.registerSetting({
title: "Reverse Order of Chapters",
key: "reverseChaptersOrder",
type: "toggle",
description: "Reverse the order of chapters in ascending order",
defaultValue: "true",
});
}
async latest() {
const res = await this.req(`/`);
const latest = await this.querySelectorAll(res, "div.content-homepage-item");
let comic = [];
for (const element of latest) {
const html = await element.content;
const url = await this.getAttributeText(html, "a.a-h", "href");
const title = await this.querySelector(html, "a.a-h").text;
const cover = await this.querySelector(html, "img.img-loading").getAttributeText("src");
comic.push({
title: title.trim(),
url,
cover,
});
}
return comic;
}
async search(kw) {
const kwstring = kw.replace(/ /g, "_");
const res = await this.req(`/search/story/${kwstring}`);
const searchList = await this.querySelectorAll(res, "div.search-story-item");
const result = await Promise.all(
searchList.map(async (element) => {
const html = await element.content;
const url = await this.getAttributeText(html, "a.a-h", "href");
const title = await this.querySelector(html, "a.a-h").text;
const cover = await this.querySelector(html, "img.img-loading").getAttributeText("src");
return {
title: title.trim(),
url,
cover,
};
})
);
return result;
}
async detail(url) {
const res = await this.request("", {
headers: {
"Miru-Url": url,
},
});
const title = await this.querySelector(res, "h1").text;
const cover = await this.querySelector(res, "img.img-loading").getAttributeText("src");
const desc = await this.querySelector(res, "div.panel-story-info-description").text;
const epiList = await this.querySelectorAll(res, "li.a-h");
const episodes = await Promise.all(
epiList.map(async (element) => {
const html = await element.content;
const name = await this.querySelector(html, "a").text;
const url = await this.getAttributeText(html, "a", "href");
return {
name,
url: url,
};
})
);
if ((await this.getSetting("reverseChaptersOrder")) === "true") {
episodes.reverse();
}
return {
title: title.trim(),
cover,
desc: desc.trim(),
episodes: [
{
title: "Chapters",
urls: episodes,
},
],
};
}
async watch(url) {
const res = await this.request("", {
headers: {
"Miru-Url": url,
},
});
const images = await Promise.all(
(await this.querySelectorAll(res, "div.container-chapter-reader > img")).map(async (element) => {
const html = await element.content;
let dataSrc = await this.getAttributeText(html, "img", "src");
dataSrc = dataSrc.trim();
return dataSrc;
})
);
return {
urls: images,
};
}
}