Skip to content

Commit d5b70a4

Browse files
update.
0 parents  commit d5b70a4

File tree

4 files changed

+228
-0
lines changed

4 files changed

+228
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
MangaDex Plugin
2+
============
3+
4+
A Rulia plugin for reading [MangaDex](https://mangadex.org).
5+
6+
Description
7+
----------
8+
9+
* It works.
10+
* You need to customize the Http header in the plugin configuration, with the key being `User-Agent` and the value being `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0`.
11+
* There are a lot of bugs, I'll fix them when I have time.
12+
* There are also many shortcomings; I'll make changes when I have time.
13+
14+
Login
15+
----
16+
17+
You can log in in two ways (it works without logging in):
18+
19+
* Manually add a header named `Cookie` in the Rulia plugin settings and fill in the Cookie.
20+
* Use the web popup to log in, fill in `https://mangadex.org` as the URL, and log in successfully.

icon.png

25.8 KB
Loading

index.js

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
async function getMangaListByLatest(page, pageSize) {
2+
const comicsIdUrl = 'https://api.mangadex.org/chapter';
3+
const url = 'https://api.mangadex.org/manga';
4+
try {
5+
const comicsIdRawResponse = await window.Rulia.httpRequest({
6+
url: comicsIdUrl,
7+
method: 'GET',
8+
payload: 'limit=' + pageSize +
9+
'&offset=' + ((page - 1) * pageSize) +
10+
'&includes[]=user&includes[]=scanlation_group&includes[]=manga&contentRating[]=safe&contentRating[]=suggestive&contentRating[]=erotica&order[readableAt]=desc'
11+
});
12+
const comicsIdResponse = JSON.parse(comicsIdRawResponse);
13+
var comicsIdList = [];
14+
for (var x of comicsIdResponse.data) {
15+
comicsIdList.push(x.relationships[1].id);
16+
}
17+
var payload = '';
18+
19+
for (var i = 0; i < comicsIdList.length; i++) {
20+
payload += 'ids[]=' + comicsIdList[i];
21+
if (i < (comicsIdList.length - 1)) {
22+
payload += '&';
23+
} else {
24+
payload += '&includes[]=cover_art';
25+
}
26+
}
27+
const rawResponse = await window.Rulia.httpRequest({
28+
url: url,
29+
method: 'GET',
30+
payload: payload
31+
});
32+
const response = JSON.parse(rawResponse);
33+
var result = {
34+
list: []
35+
}
36+
for (manga of response.data) {
37+
var comicTitle = '';
38+
for (var comic in manga.attributes.title) {
39+
comicTitle = manga.attributes.title[comic];
40+
break;
41+
}
42+
const mangaDetailString = JSON.stringify(manga.relationships);
43+
const regex = /"fileName":\s*"(.*?)"/;
44+
const match = mangaDetailString.match(regex);
45+
let fileName = match[1];
46+
var comic = {
47+
title: comicTitle,
48+
url: 'https://www.mangadex.org/title/' + manga.id,
49+
coverUrl: 'https://mangadex.org/covers/' + manga.id + '/' + fileName + '.256.jpg'
50+
}
51+
result.list.push(comic)
52+
}
53+
window.Rulia.endWithResult(result);
54+
} catch (error) {
55+
window.Rulia.endWithException(error.message);
56+
}
57+
}
58+
59+
async function getMangaListBySearching(page, pageSize, keyword) {
60+
const comicsIdUrl = 'https://api.mangadex.org/manga';
61+
const url = 'https://api.mangadex.org/manga';
62+
try {
63+
const comicsIdRawResponse = await window.Rulia.httpRequest({
64+
url: comicsIdUrl,
65+
method: 'GET',
66+
payload: 'limit=' + pageSize + '&offset=' + ((page - 1) * pageSize) +
67+
'&includes[]=cover_art&includes[]=artist&includes[]=author&contentRating[]=safe&contentRating[]=suggestive&contentRating[]=erotica&title=' +
68+
keyword + '&includedTagsMode=AND&excludedTagsMode=OR'
69+
});
70+
const comicsIdResponse = JSON.parse(comicsIdRawResponse);
71+
var comicsIdList = [];
72+
for (var x of comicsIdResponse.data) {
73+
comicsIdList.push(x.id);
74+
}
75+
var payload = '';
76+
77+
for (var i = 0; i < comicsIdList.length; i++) {
78+
payload += 'ids[]=' + comicsIdList[i];
79+
if (i < (comicsIdList.length - 1)) {
80+
payload += '&';
81+
} else {
82+
payload += '&includes[]=cover_art';
83+
}
84+
}
85+
const rawResponse = await window.Rulia.httpRequest({
86+
url: url,
87+
method: 'GET',
88+
payload: payload
89+
});
90+
const response = JSON.parse(rawResponse);
91+
var result = {
92+
list: []
93+
}
94+
for (manga of response.data) {
95+
var comicTitle = '';
96+
for (var comic in manga.attributes.title) {
97+
comicTitle = manga.attributes.title[comic];
98+
break;
99+
}
100+
const mangaDetailString = JSON.stringify(manga.relationships);
101+
const regex = /"fileName":\s*"(.*?)"/;
102+
const match = mangaDetailString.match(regex);
103+
let fileName = match[1];
104+
var comic = {
105+
title: comicTitle,
106+
url: 'https://www.mangadex.org/title/' + manga.id,
107+
coverUrl: 'https://mangadex.org/covers/' + manga.id + '/' + fileName + '.256.jpg'
108+
}
109+
result.list.push(comic)
110+
}
111+
window.Rulia.endWithResult(result);
112+
} catch (error) {
113+
window.Rulia.endWithException(error.message);
114+
}
115+
}
116+
117+
async function getMangaList(page, pageSize, keyword) {
118+
if (keyword) {
119+
return await getMangaListBySearching(page, pageSize, keyword);
120+
} else {
121+
return await getMangaListByLatest(page, pageSize);
122+
}
123+
}
124+
125+
async function getMangaData(dataPageUrl) {
126+
const seasonIdMatchExp = /\/([0-9a-fA-F-]+)(\/|$|\?)/;
127+
const seasonIdMatch = dataPageUrl.match(seasonIdMatchExp);
128+
const detailUrl = 'https://api.mangadex.org/manga/' + seasonIdMatch[1];
129+
const chapterListUrl = 'https://api.mangadex.org/manga/' + seasonIdMatch[1] + '/feed';
130+
try {
131+
const detailRawResponse = await window.Rulia.httpRequest({
132+
url: detailUrl,
133+
method: 'GET',
134+
payload: 'includes[]=artist&includes[]=author&includes[]=cover_art'
135+
})
136+
const detailResponse = JSON.parse(detailRawResponse);
137+
let comicTitle = '';
138+
let comicDescription = '';
139+
for (var comic in detailResponse.data.attributes.title) {
140+
comicTitle = detailResponse.data.attributes.title[comic];
141+
break;
142+
}
143+
for (var comic in detailResponse.data.attributes.description) {
144+
comicDescription = detailResponse.data.attributes.description[comic];
145+
break;
146+
}
147+
const mangaDetailString = JSON.stringify(detailResponse.data.relationships);
148+
const regex = /"fileName":\s*"(.*?)"/;
149+
const match = mangaDetailString.match(regex);
150+
let comicCover = 'https://mangadex.org/covers/' + seasonIdMatch[1] + '/' + match[1] + '.256.jpg';
151+
var result = {
152+
title: comicTitle,
153+
description: comicDescription,
154+
coverUrl: comicCover,
155+
chapterList: []
156+
}
157+
const chapterListRawResponse = await window.Rulia.httpRequest({
158+
url: chapterListUrl,
159+
method: 'GET',
160+
payload: 'limit=500&includes[]=scanlation_group&includes[]=user&order[volume]=desc&order[chapter]=desc&offset=0&contentRating[]=safe&contentRating[]=suggestive&contentRating[]=erotica&contentRating[]=pornographic'
161+
});
162+
const chapterListResponse = JSON.parse(chapterListRawResponse);
163+
for (var manga of chapterListResponse.data) {
164+
var comic = {
165+
title: manga.attributes.translatedLanguage + '.' + manga.attributes.chapter,
166+
url: 'https://mangadex.org/chapter/' + manga.id
167+
}
168+
result.chapterList.push(comic);
169+
}
170+
window.Rulia.endWithResult(result);
171+
} catch (error) {
172+
window.Rulia.endWithException(error.message);
173+
}
174+
}
175+
176+
async function getChapterImageList(chapterUrl) {
177+
const episodeIdMatchExp = /\/chapter\/([0-9a-fA-F-]+)(\/|$|\?)/;
178+
const episodeIdMatch = chapterUrl.match(episodeIdMatchExp);
179+
const url = 'https://api.mangadex.org/at-home/server/' + episodeIdMatch[1];
180+
const rawResponse = await window.Rulia.httpRequest({
181+
url: url,
182+
method: 'GET',
183+
payload: 'forcePort443=false'
184+
});
185+
const response = JSON.parse(rawResponse);
186+
var result = [];
187+
188+
for (manga of response.chapter.data) {
189+
result.push({
190+
url: 'https://uploads.mangadex.org/data/' + response.chapter.hash + '/' + manga,
191+
width: 1,
192+
height: 1
193+
});
194+
}
195+
window.Rulia.endWithResult(result);
196+
}
197+
async function getImageUrl(path) {
198+
window.Rulia.endWithResult(path);
199+
}

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "@rulia/MangaDex",
3+
"title": "MangaDex",
4+
"description": "MangaDex Plugin.",
5+
"version": "0.0.1",
6+
"author": "LittleStar_OuO",
7+
"tags": ["MangaDex", "Manga","Comic"],
8+
"homepage": "https://github.com/LittleStar-OuO/plugin.MangaDex"
9+
}

0 commit comments

Comments
 (0)