-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
235 lines (224 loc) · 6.47 KB
/
index.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
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
let headers = {
'Platform': 1,
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6,ja;q=0.5',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0'
}
async function setMangaListFilterOptions() {
const url = 'https://api.mangacopy.com/api/v3/h5/filter/comic/tags';
try {
let result = [{
label: '主题',
name: 'theme',
options: [{
label: '推荐',
value: 'recommend'
}, {
label: '全部',
value: 0
}]
},
{
label: '地区/进度',
name: 'top',
options: [{
label: '全部',
value: 0
}]
}
]
const rawResponse = await window.Rulia.httpRequest({
url: url,
method: 'GET',
payload: 'format=json&type=1',
headers: headers
});
const response = JSON.parse(rawResponse);
for (var item of response.results.theme) {
result[0].options.push({
label: item.name,
value: item.path_word
})
}
for (var item of response.results.top) {
result[1].options.push({
label: item.name,
value: item.path_word
})
}
window.Rulia.endWithResult(result);
} catch (error) {
window.Rulia.endWithResult([])
}
}
async function getMangaListByRecommend(page, pageSize) {
const url =
'https://api.mangacopy.com/api/v3/recs';
try {
const rawResponse = await window.Rulia.httpRequest({
url: url,
method: 'GET',
payload: 'format=json&limit=' + pageSize + '&offset=' + ((page - 1) * pageSize) +
'&pos=3200102',
headers: headers
});
const response = JSON.parse(rawResponse);
var result = {
list: []
}
for (var manga of response.results.list) {
var comic = {
title: manga.comic.name,
url: 'https://www.mangacopy.com/comic/' + manga.comic.path_word,
coverUrl: manga.comic.cover
}
result.list.push(comic);
}
window.Rulia.endWithResult(result);
} catch (error) {
window.Rulia.endWithException(error.message);
}
}
async function getMangaListByCategory(page, pageSize, filterOptions) {
if (filterOptions.theme == 'recommend') {
return await getMangaListByRecommend(page, pageSize);
} else {
const url = 'https://api.mangacopy.com/api/v3/comics';
try {
var theme = '';
var top = '';
if (filterOptions.theme && filterOptions.theme != 0) {
theme = '&theme=' + filterOptions.theme;
}
if (filterOptions.top && filterOptions.top != 0) {
top = '&top=' + filterOptions.top;
}
var payload = '_update=true&format=json&free_type=1&limit=' + pageSize + '&offset=' + ((page - 1) *
pageSize) + '&ordering=popular' + theme + top;
const rawResponse = await window.Rulia.httpRequest({
url: url,
method: 'GET',
payload: payload,
headers: headers
})
const response = JSON.parse(rawResponse);
var result = {
list: []
}
for (var manga of response.results.list) {
var comic = {
title: manga.name,
url: 'https://www.mangacopy.com/comic/' + manga.path_word,
coverUrl: manga.cover
}
result.list.push(comic);
}
window.Rulia.endWithResult(result);
} catch (error) {
window.Rulia.endWithException(error.message);
}
}
}
async function getMangaListBySearching(page, pageSize, keyword) {
const url =
'https://api.mangacopy.com/api/v3/search/comic';
try {
const rawResponse = await window.Rulia.httpRequest({
url: url,
method: 'GET',
payload: '_update=true&format=json&limit=' + pageSize + '&offset=' + ((page - 1) * pageSize) +
'&platform=1&q=' + keyword + '&q_type=',
headers: headers
});
const response = JSON.parse(rawResponse);
var result = {
list: []
}
for (var manga of response.results.list) {
var comic = {
title: manga.name,
url: 'https://www.mangacopy.com/comic/' + manga.path_word,
coverUrl: manga.cover
}
result.list.push(comic);
}
window.Rulia.endWithResult(result);
} catch (error) {
window.Rulia.endWithException(error.message);
}
}
async function getMangaList(page, pageSize, keyword, rawFilterOptions) {
if (keyword) {
return await getMangaListBySearching(page, pageSize, keyword);
} else {
return await getMangaListByCategory(page, pageSize, JSON.parse(rawFilterOptions));
}
}
async function getMangaData(dataPageUrl) {
const seasonIdMatchExp = /\/comic\/(.*)/;
const seasonIdMatch = dataPageUrl.match(seasonIdMatchExp);
const detailUrl = 'https://api.mangacopy.com/api/v3/comic2/' + seasonIdMatch[1];
const chapterListUrl = 'https://api.mangacopy.com/api/v3/comic/' + seasonIdMatch[1] + '/group/default/chapters';
try {
const detailRawResponse = await window.Rulia.httpRequest({
url: detailUrl,
method: 'GET',
payload: 'format=json&platform=3',
headers: headers
})
const detailResponse = JSON.parse(detailRawResponse);
let result = {
title: detailResponse.results.comic.name,
description: detailResponse.results.comic.brief,
coverUrl: detailResponse.results.comic.cover,
chapterList: []
}
const chapterListRawResponse = await window.Rulia.httpRequest({
url: chapterListUrl,
method: 'GET',
payload: '_update=true&format=json&limit=500&offset=0',
headers: headers
});
const chapterListResponse = JSON.parse(chapterListRawResponse);
for (var manga of chapterListResponse.results.list) {
var comic = {
title: '[' + manga.name + '][' + manga.datetime_created + ']',
url: 'https://www.mangacopy.com/comic/' + seasonIdMatch[1] + '/chapter/' + manga.uuid
}
result.chapterList.push(comic);
}
window.Rulia.endWithResult(result);
} catch (error) {
window.Rulia.endWithException(error.message);
}
}
async function getChapterImageList(chapterUrl) {
const episodeIdMatchExp = /https?:\/\/www\.mangacopy\.com\/comic\/([a-zA-Z0-9_-]+)\/chapter\/([0-9a-f-]+)/;
const episodeIdMatch = chapterUrl.match(episodeIdMatchExp);
const url = 'https://api.mangacopy.com/api/v3/comic/' + episodeIdMatch[1] + '/chapter2/' + episodeIdMatch[2];
const rawResponse = await window.Rulia.httpRequest({
url: url,
method: 'GET',
payload: 'format=json',
headers: headers
});
const response = JSON.parse(rawResponse);
var result = [];
for (var i = 0; i < response.results.chapter.words.length; i++) {
result.push({
url: response.results.chapter.contents[i].url.replace(/c800x/, 'c1500x'),
index: response.results.chapter.words[i],
width: 1,
height: 1
});
}
result.sort(function(a, b) {
return a.index - b.index;
});
for (var i = 0; i < result.length; i++) {
delete result[i].index;
}
window.Rulia.endWithResult(result);
}
async function getImageUrl(path) {
window.Rulia.endWithResult(path);
}