-
Notifications
You must be signed in to change notification settings - Fork 146
/
Copy pathmangakatana.com.js
137 lines (121 loc) · 3.65 KB
/
mangakatana.com.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
// ==MiruExtension==
// @name Mangakatana
// @version v0.0.1
// @author shashankx86
// @lang en
// @license MIT
// @icon https://mangakatana.com/static/img/fav.png
// @package mangakatana.com
// @type manga
// @webSite https://mangakatana.com/
// ==/MiruExtension==
export default class extends Extension {
async req(url) {
return this.request(url, {
headers: {
"Miru-Url": await this.getSetting("mangakatana"),
},
});
}
async load() {
this.registerSetting({
title: "Mangakatana URL",
key: "mangakatana",
type: "input",
description: "Homepage URL for Mangakatana",
defaultValue: "https://mangakatana.com/",
});
this.registerSetting({
title: "Reverse Order of Chapters",
key: "reverseChaptersOrderMangakatana",
type: "toggle",
description: "Reverse the order of chapters in ascending order",
defaultValue: "true",
});
}
async latest(page) {
const res = await this.req(`/page/${page}/`);
const latest = await this.querySelectorAll(res, "#book_list .item");
let manga = [];
for (const element of latest) {
const html = await element.content;
const url = await this.getAttributeText(html, "a", "href");
const title = await this.querySelector(html, "h3.title a").text;
const cover = await this.getAttributeText(html, ".wrap_img img", "src");
manga.push({
title: title.trim(),
url,
cover: cover,
});
}
return manga;
}
async search(kw, page) {
const res = await this.req(`/?search=${kw}`);
const searchList = await this.querySelectorAll(res, "#book_list .item");
const result = await Promise.all(
searchList.map(async (element) => {
const html = await element.content;
const url = await this.getAttributeText(html, "a", "href");
const title = await this.querySelector(html, "h3.title a").text;
const cover = await this.getAttributeText(html, ".wrap_img img", "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, "div.info > h1").text;
const cover = await this.getAttributeText(res, ".cover img", "src");
let descS = await this.querySelector(res, ".summary p").text;
let desc = descS.replace(/<br>/g, "");
const epiList = await this.querySelectorAll(res, "div.chapters > table > tbody > tr");
const chapters = await Promise.all(
epiList.map(async (element) => {
const html = await element.content;
const name = await this.querySelector(html, "div.chapter > a").text;
const url = await this.getAttributeText(html, "div.chapter > a", "href");
return {
name,
url: url,
};
})
);
if ((await this.getSetting("reverseChaptersOrderMangakatana")) === "true") {
chapters.reverse();
}
return {
title: title || "Unknown Title",
cover,
desc: desc || "N/A",
episodes: [
{
title: "Chapters",
urls: chapters,
},
],
};
}
async watch(url) {
const res = await fetch(url);
const html = await res.text();
const thzqMatch = html.match(/var thzq=\[(.*?)\];/);
let images = [];
if (thzqMatch) {
const thzqContent = thzqMatch[1];
images = thzqContent.match(/'(https:\/\/[^']+)'/g).map((match) => match.slice(1, -1));
}
return {
urls: images,
};
}
}