generated from manga-raiku/raiku-plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplugin.ts
200 lines (179 loc) · 4.7 KB
/
plugin.ts
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
import { defineApi } from "raiku-pgs/plugin"
import type {
API,
Comic,
ID,
Ranking,
Server
} from "raiku-pgs/plugin"
import { CURL } from "src/const"
import { withProxyImage } from "./src/logic/with-proxy-image"
import General from "./src/runs/[general]"
import getListChapters from "./src/runs/get-list-chapters"
import Index from "./src/runs/index"
import searchQuickly from "./src/runs/pre-search"
import search from "./src/runs/tim-kiem"
import getComic from "./src/runs/truyen-tranh/[slug]"
import getComicChapter from "./src/runs/truyen-tranh/[slug]-chap-[chap]"
import getComicComment from "./src/runs/truyen-tranh/comment/get"
const Rankings: Ranking[] = [
{
value: "ngay",
match: "/tim-truyen?status=-1&sort=13",
name: {
"vi-VN": "Ngày",
"en-US": "Date"
}
},
{
value: "tuan",
match: "/tim-truyen?status=-1&sort=12",
name: {
"vi-VN": "Tuần",
"en-US": "Week"
}
},
{
value: "thang",
match: "/tim-truyen?status=-1&sort=11",
name: {
"vi-VN": "Tháng",
"en-US": "Month"
}
}
]
export const headersNettruyen = {
referer: "https://www.nettruyenmax.com"
}
const Servers: Server[] = [
{
name: "Server 1",
has: () => true,
parse: ({ pages }) =>
pages.map((page) => withProxyImage(page.src, headersNettruyen))
},
{
name: "Server 2",
has: ({ pages }) =>
pages[0].original !== null && pages[0].original !== pages[0].src,
parse({ pages }) {
return pages.map((page) => {
if (
page.original?.indexOf("focus-opensocial.googleusercontent") !== -1
) {
return withProxyImage(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
decodeURIComponent(page.original!.split("&url", 2)[1]),
headersNettruyen
)
}
return withProxyImage(
`https://images2-focus-opensocial.googleusercontent.com/gadgets/proxy?container=focus&gadget=a&no_expand=1&resize_h=0&rewriteMime=image%2F*&url=${encodeURIComponent(
page.original
)}`,
headersNettruyen
)
})
}
},
{
name: "Server 3",
has: (item) => item.cdn !== null,
parse: ({ pages }) =>
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
pages.map((item) => withProxyImage(item.cdn!, headersNettruyen))
},
{
name: "Server 4",
has: ({ pages, cdn, cdn2 }) => pages[0].cdn !== null && !!cdn && !!cdn2,
parse: ({ pages, cdn, cdn2 }) => {
return pages.map((item) =>
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
withProxyImage(item.cdn!.replace(cdn!, cdn2!), headersNettruyen)
)
}
}
]
const TAGS_IS_MANGA = ["manga", "anime", "japan"]
class Nettruyen implements API<true> {
public readonly Rankings = Rankings
public readonly Servers = Servers
public readonly autoFetchComicIsManga = true
async setup() {
if (AppInfo.extension) {
console.log("Plugin run mode extension.")
await setReferrers({
"#nettruyen": CURL
})
}
}
async index() {
return Index()
}
async getComic(zlug: string) {
return getComic(zlug)
}
async getModeReader(_: string, __: string, comicData: Comic) {
if (comicData.genres.some(item => TAGS_IS_MANGA.includes(item.name.toLowerCase()))) {
return {
scrollingMode: false,
rightToLeft: true
}
}
return {}
}
async getComicChapter<Fast extends boolean>(
mangaId: ID,
epId: ID,
fast: Fast
) {
const lastI = epId.lastIndexOf("-i") >>> 0
return getComicChapter(
mangaId.replace(/-\d+$/, "") +
"/chapter-" +
epId.slice(0, lastI) +
"/" +
epId.slice(lastI + 2),
fast
)
}
async getComicComments(
comicId: number,
orderByNews: boolean,
chapterId = -1,
parentId = 0,
page: number,
comicKey: string
) {
return getComicComment(
comicId,
orderByNews,
chapterId,
parentId,
page,
comicKey
)
}
async getListChapters(mangaId: ID) {
return getListChapters(mangaId)
}
async searchQuickly(keyword: string, page: number) {
return searchQuickly(keyword, page)
}
async search(keyword: string, page: number) {
return search(keyword, page)
}
async getRanking(type: string, page: number, filter: Record<string, string>) {
const match = Rankings.find((item) => item.value === type)?.match
if (!match) throw new Error("not_found")
return General(match, page, filter)
}
async getCategory(
type: string,
page: number,
filter: Record<string, string | string[]>
) {
return General(`/tim-truyen/${type}`, page, filter)
}
}
defineApi(Nettruyen)