Skip to content

Commit 1be9f87

Browse files
首次发布.
0 parents  commit 1be9f87

File tree

4 files changed

+333
-0
lines changed

4 files changed

+333
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# ZaiManHua Plugin
2+
3+
用于阅读[再漫画](https://zaimanhua.com)的 Rulia 插件.
4+
5+
## 说明
6+
7+
- 能用就行.
8+
- 在使用**搜索**时,筛选功能不生效.
9+
10+
## 登录
11+
12+
- 在 Rulia 插件设置中手动添加`authorization`值,重启Rulia进入插件即可.
13+
14+
## 下载
15+
16+
- 你可以点击[这里](https://github.com/LittleStar-OuO/plugin.ZaiManHua/releases)下载插件.

icon.png

29 KB
Loading

index.js

Lines changed: 302 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,302 @@
1+
const userConfig = window.Rulia.getUserConfig()
2+
3+
let authorization = false;
4+
5+
if (userConfig.authorization) {
6+
authorization = userConfig.authorization;
7+
}
8+
9+
async function setMangaListFilterOptions() {
10+
try {
11+
let result = [{
12+
label: '主题',
13+
name: 'theme',
14+
options: []
15+
},
16+
{
17+
label: '受众',
18+
name: 'audience',
19+
options: []
20+
},
21+
{
22+
label: '状态',
23+
name: 'status',
24+
options: []
25+
},
26+
{
27+
label: '地域',
28+
name: 'area',
29+
options: []
30+
},
31+
{
32+
label: '排序',
33+
name: 'sortType',
34+
options: [{
35+
label: '更新',
36+
value: 1
37+
}, {
38+
label: '人气',
39+
value: 2
40+
}]
41+
}
42+
]
43+
if (authorization) {
44+
result[0].options.unshift({
45+
label: '书架',
46+
value: 'bookshelf'
47+
})
48+
}
49+
50+
const filterUrl = 'https://m.zaimanhua.com/api/app/v1/comic/filter/classify?_v=15';
51+
const filterRawResponse = await window.Rulia.httpRequest({
52+
url: filterUrl,
53+
method: 'GET'
54+
});
55+
const filterResponse = JSON.parse(filterRawResponse);
56+
for (let item of filterResponse.data.classifyList[0].list) {
57+
result[0].options.push({
58+
label: item.tagName,
59+
value: item.tagId
60+
})
61+
}
62+
for (let item of filterResponse.data.classifyList[1].list) {
63+
result[1].options.push({
64+
label: item.tagName,
65+
value: item.tagId
66+
})
67+
}
68+
for (let item of filterResponse.data.classifyList[2].list) {
69+
result[2].options.push({
70+
label: item.tagName,
71+
value: item.tagId
72+
})
73+
}
74+
for (let item of filterResponse.data.classifyList[3].list) {
75+
result[3].options.push({
76+
label: item.tagName,
77+
value: item.tagId
78+
})
79+
}
80+
window.Rulia.endWithResult(result);
81+
} catch (error) {
82+
window.Rulia.endWithResult([])
83+
}
84+
}
85+
86+
async function getMangaListByBookshelf(page, pageSize) {
87+
const url = 'https://m.zaimanhua.com/api/app/v1/comic/sub/list?status=0&firstLetter=&page=' + page.toString() +
88+
'&size=' + pageSize.toString() + '&_v=15';
89+
try {
90+
const rawResponse = await window.Rulia.httpRequest({
91+
url: url,
92+
method: 'GET',
93+
headers: {
94+
'Authorization': authorization
95+
}
96+
});
97+
const response = JSON.parse(rawResponse);
98+
let result = {
99+
list: []
100+
}
101+
102+
for (let manga of response.data.subList) {
103+
let comic = {
104+
title: manga.title,
105+
url: 'https://manhua.zaimanhua.com/details/' + manga.id,
106+
coverUrl: manga.cover
107+
}
108+
result.list.push(comic);
109+
}
110+
window.Rulia.endWithResult(result);
111+
} catch (error) {
112+
window.Rulia.endWithException(error.message);
113+
}
114+
}
115+
116+
async function getMangaListByCategory(page, pageSize, filterOptions) {
117+
if (filterOptions.theme == 'bookshelf') {
118+
return await getMangaListByBookshelf(page, pageSize);
119+
} else {
120+
const url = 'https://m.zaimanhua.com/api/app/v1/comic/filter/list';
121+
try {
122+
const payload = new URLSearchParams({});
123+
payload.append('page', page.toString());
124+
payload.append('size', pageSize.toString());
125+
if (filterOptions.theme) {
126+
payload.set('theme', filterOptions.theme);
127+
}
128+
129+
if (filterOptions.audience) {
130+
payload.set('cate', filterOptions.audience);
131+
}
132+
133+
if (filterOptions.status) {
134+
payload.set('status', filterOptions.status);
135+
}
136+
137+
if (filterOptions.area) {
138+
payload.set('zone', filterOptions.area);
139+
}
140+
141+
if (filterOptions.sortType) {
142+
payload.set('sortType', filterOptions.sortType);
143+
}
144+
145+
const rawResponse = await window.Rulia.httpRequest({
146+
url: url,
147+
method: 'GET',
148+
payload: payload.toString()
149+
});
150+
const response = JSON.parse(rawResponse);
151+
let result = {
152+
list: []
153+
}
154+
for (let manga of response.data.comicList) {
155+
let comic = {
156+
title: manga.name,
157+
url: 'https://manhua.zaimanhua.com/details/' + manga.id,
158+
coverUrl: manga.cover
159+
}
160+
result.list.push(comic);
161+
}
162+
window.Rulia.endWithResult(result);
163+
} catch (error) {
164+
window.Rulia.endWithException(error.message);
165+
}
166+
}
167+
168+
169+
}
170+
171+
async function getMangaListBySearching(page, pageSize, keyword) {
172+
const url = 'https://m.zaimanhua.com/api/app/v1/search/index';
173+
try {
174+
const payload = new URLSearchParams({
175+
source: 0,
176+
_v: 15
177+
});
178+
179+
payload.append('page', page.toString());
180+
payload.append('size', pageSize.toString());
181+
payload.set('keyword', keyword.toString());
182+
183+
const rawResponse = await window.Rulia.httpRequest({
184+
url: url,
185+
method: 'GET',
186+
payload: payload.toString()
187+
});
188+
189+
const response = JSON.parse(rawResponse);
190+
191+
let result = {
192+
list: []
193+
}
194+
195+
for (let manga of response.data.list) {
196+
let comic = {
197+
title: manga.title,
198+
url: 'https://manhua.zaimanhua.com/details/' + manga.id,
199+
coverUrl: manga.cover
200+
}
201+
result.list.push(comic);
202+
}
203+
204+
window.Rulia.endWithResult(result);
205+
} catch (error) {
206+
window.Rulia.endWithException(error.message);
207+
}
208+
}
209+
210+
async function getMangaList(page, pageSize, keyword, rawFilterOptions) {
211+
if (keyword) {
212+
return await getMangaListBySearching(page, pageSize, keyword);
213+
} else {
214+
return await getMangaListByCategory(page, pageSize, JSON.parse(rawFilterOptions));
215+
}
216+
window.Rulia.endWithResult(result);
217+
}
218+
async function getMangaData(dataPageUrl) {
219+
let id = dataPageUrl.match(/details\/(\d+)/)[1];
220+
const url = 'https://manhua.zaimanhua.com/api/v1/comic2/comic/detail';
221+
try {
222+
const payload = new URLSearchParams({
223+
channel: '%20pc',
224+
app_name: 'zmh',
225+
version: '1.0.0',
226+
timestamp: Date.now().toString(),
227+
uid: 0
228+
});
229+
payload.append('id', id.toString());
230+
const rawResponse = await window.Rulia.httpRequest({
231+
url: url,
232+
method: 'GET',
233+
payload: payload.toString()
234+
});
235+
const response = JSON.parse(rawResponse);
236+
let result = {
237+
title: response.data.comicInfo.title,
238+
description: response.data.comicInfo.authorsTagList[0].tagName + ' · ' + response.data.comicInfo
239+
.statusTagList[0].tagName + ' · ' + response.data.comicInfo.description,
240+
coverUrl: response.data.comicInfo.cover,
241+
chapterList: []
242+
}
243+
for (let chapters of response.data.comicInfo.chapterList[0].data) {
244+
let chapter = {
245+
title: chapters.chapter_title,
246+
url: 'https://m.zaimanhua.com/pages/comic/page?comic_id=' + id + '&chapter_id=' + chapters
247+
.chapter_id
248+
}
249+
result.chapterList.unshift(chapter);
250+
}
251+
window.Rulia.endWithResult(result);
252+
} catch (error) {
253+
window.Rulia.endWithException(error.message);
254+
}
255+
}
256+
257+
async function getChapterImageList(chapterUrl) {
258+
try {
259+
const params = new URL(chapterUrl).searchParams;
260+
const comic_id = params.get('comic_id');
261+
const chapter_id = params.get('chapter_id');
262+
const url = 'https://manhua.zaimanhua.com/api/v1/comic2/chapter/detail';
263+
const payload = new URLSearchParams({
264+
channel: 'pc',
265+
app_name: 'zmh',
266+
version: '1.0.0',
267+
timestamp: Date.now().toString(),
268+
uid: '0',
269+
comic_id,
270+
chapter_id
271+
});
272+
const rawResponse = await window.Rulia.httpRequest({
273+
url,
274+
method: 'GET',
275+
payload: payload.toString()
276+
});
277+
const response = JSON.parse(rawResponse);
278+
const pageUrls = response.data.chapterInfo.page_url || [];
279+
280+
const promises = pageUrls.map(url =>
281+
new Promise(resolve => {
282+
const img = new Image();
283+
img.onload = img.onerror = () => {
284+
resolve({
285+
url,
286+
width: img.width,
287+
height: img.height
288+
});
289+
};
290+
img.src = url;
291+
})
292+
);
293+
const result = await Promise.all(promises);
294+
window.Rulia.endWithResult(result);
295+
} catch (error) {
296+
window.Rulia.endWithException(error.message);
297+
}
298+
}
299+
300+
async function getImageUrl(path) {
301+
window.Rulia.endWithResult(path);
302+
}

package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "@rulia/ZaiManHua",
3+
"title": "再漫画",
4+
"description": "在Rulia里「再漫画」叭.(^∀^●)ノシ",
5+
"version": "0.0.1",
6+
"author": "LittleStar_OuO",
7+
"tags": ["ZaiManHua", "manga", "comic"],
8+
"homepage": "https://github.com/LittleStar-OuO/plugin.ZaiManHua",
9+
"userConfig": {
10+
"authorization": {
11+
"displayName": "authorization",
12+
"description": "请使用“网页开发者工具”从网页的header中提取authorization,例如:Bearer a5822c5xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx54f"
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)