Skip to content
This repository was archived by the owner on Mar 23, 2025. It is now read-only.

Commit a7c6cc3

Browse files
authored
Merge pull request #31 from Ftbom/master
Add ManhuaDB plugin
2 parents 5f549b8 + f387dfc commit a7c6cc3

File tree

4 files changed

+122
-0
lines changed

4 files changed

+122
-0
lines changed

plugins/manhuadb/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
storage.json
2+
subscriptions.json

plugins/manhuadb/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# ManhuaDB Plugin
2+
3+
This is Mango plugin for [ManhuaDB](https://www.manhuadb.com/).
4+
5+
**Attention**
6+
7+
* Only show the results in the first page when search.
8+
9+
* It is not easy to get the number of chapter pages before starting the download, so in the chapter list the number of pages for all chapters is set to 1000. But in the download manager the number of chapter pages is correct.
10+
11+
Maintained by [@Ftbom](https://github.com/Ftbom).

plugins/manhuadb/index.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(e){var t="";var n,r,i,s,o,u,a;var f=0;e=Base64._utf8_encode(e);while(f<e.length){n=e.charCodeAt(f++);r=e.charCodeAt(f++);i=e.charCodeAt(f++);s=n>>2;o=(n&3)<<4|r>>4;u=(r&15)<<2|i>>6;a=i&63;if(isNaN(r)){u=a=64}else if(isNaN(i)){a=64}t=t+this._keyStr.charAt(s)+this._keyStr.charAt(o)+this._keyStr.charAt(u)+this._keyStr.charAt(a)}return t},decode:function(e){var t="";var n,r,i;var s,o,u,a;var f=0;e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");while(f<e.length){s=this._keyStr.indexOf(e.charAt(f++));o=this._keyStr.indexOf(e.charAt(f++));u=this._keyStr.indexOf(e.charAt(f++));a=this._keyStr.indexOf(e.charAt(f++));n=s<<2|o>>4;r=(o&15)<<4|u>>2;i=(u&3)<<6|a;t=t+String.fromCharCode(n);if(u!=64){t=t+String.fromCharCode(r)}if(a!=64){t=t+String.fromCharCode(i)}}t=Base64._utf8_decode(t);return t},_utf8_encode:function(e){e=e.replace(/\r\n/g,"\n");var t="";for(var n=0;n<e.length;n++){var r=e.charCodeAt(n);if(r<128){t+=String.fromCharCode(r)}else if(r>127&&r<2048){t+=String.fromCharCode(r>>6|192);t+=String.fromCharCode(r&63|128)}else{t+=String.fromCharCode(r>>12|224);t+=String.fromCharCode(r>>6&63|128);t+=String.fromCharCode(r&63|128)}}return t},_utf8_decode:function(e){var t="";var n=0;var r=c1=c2=0;while(n<e.length){r=e.charCodeAt(n);if(r<128){t+=String.fromCharCode(r);n++}else if(r>191&&r<224){c2=e.charCodeAt(n+1);t+=String.fromCharCode((r&31)<<6|c2&63);n+=2}else{c2=e.charCodeAt(n+1);c3=e.charCodeAt(n+2);t+=String.fromCharCode((r&15)<<12|(c2&63)<<6|c3&63);n+=3}}return t}}
2+
3+
function searchManga(query) {
4+
var mangas = [];
5+
const res = mango.get('https://www.manhuadb.com/search?q=' + encodeURIComponent(query));
6+
if (res.status_code !== 200)
7+
mango.raise('Failed to search for manga. Status ' + res.status_code);
8+
var html = res.body;
9+
items = mango.css(html, '.comicbook-index');
10+
for (i = 0; i < items.length; i++) {
11+
var href = mango.attribute(mango.css(items[i], 'a')[0], 'href');
12+
var img_link = mango.attribute(mango.css(items[i], 'img')[0], 'src');
13+
if (img_link.substring(0, 4) != 'http') {
14+
img_link = 'https://www.manhuadb.com' + img_link;
15+
}
16+
var authors = [];
17+
var authors_name = mango.css(items[i], '.one-line.comic-author>a')
18+
for (j = 0; j < authors_name.length; j++) {
19+
authors.push(mango.attribute(authors_name[j], 'title'))
20+
}
21+
mangas.push({
22+
id: href.substring(8, href.length),
23+
title: mango.attribute(mango.css(items[i], 'a')[0], 'title'),
24+
authors: authors,
25+
cover_url: img_link
26+
});
27+
}
28+
29+
return JSON.stringify(mangas);
30+
}
31+
32+
function listChapters(id) {
33+
var url = 'https://www.manhuadb.com/manhua/' + id;
34+
const res = mango.get(url);
35+
var chapters = []
36+
if (res.status_code !== 200)
37+
mango.raise('Failed to list chapters. Status ' + res.status_code);
38+
var html = res.body;
39+
var comic_lists = mango.css(html, '.links-of-books');
40+
for (i = 0; i < comic_lists.length; i++) {
41+
var comics = mango.css(comic_lists[i], 'a');
42+
for (j = 0; j < comics.length; j++) {
43+
var id_part = mango.attribute(comics[j], 'href');
44+
id_part2 = id_part.replace('/manhua/' + id + '/', '');
45+
chapters.push({
46+
id: id + '__' + id_part2.substring(0, id_part2.length - 5),
47+
title: mango.attribute(comics[j], 'title'),
48+
pages: 1000,
49+
manga_title: mango.text(mango.css(html, 'h1')[0])
50+
})
51+
}
52+
}
53+
return JSON.stringify(chapters);
54+
}
55+
56+
function selectChapter(id) {
57+
var ids = id.split('__');
58+
var url = 'https://www.manhuadb.com/manhua/' + ids[0] + '/' + ids[1] + '.html';
59+
const res = mango.get(url);
60+
if (res.status_code !== 200)
61+
mango.raise('Failed to get chapter. Status ' + res.status_code);
62+
var html = res.body;
63+
var script = mango.text(mango.css(html, 'script')[7]);
64+
script = script.substring(16, script.length - 2);
65+
var img_urls = JSON.parse(Base64.decode(script));
66+
var img_url_front = mango.attribute(mango.css(html, '.show-pic')[0], 'src');
67+
img_url_front = img_url_front.substring(0, img_url_front.search(img_urls[0]['img']));
68+
var image_urls = [];
69+
for(i = 0; i < img_urls.length; i++) {
70+
image_urls.push(img_url_front + img_urls[i]['img'])
71+
}
72+
var info = mango.css(html, '.breadcrumb-item');
73+
var title = mango.text(mango.css(info[info.length - 1], 'a')[0]);
74+
var page_num = img_urls.length;
75+
var manga_title = mango.text(mango.css(info[info.length - 2], 'a')[0]);
76+
mango.storage('images', image_urls.toString());
77+
mango.storage('page', '0');
78+
79+
return JSON.stringify({
80+
id: id,
81+
title: title,
82+
pages: page_num,
83+
manga_title: manga_title
84+
});
85+
}
86+
87+
function nextPage() {
88+
const page = parseInt(mango.storage('page'));
89+
const urls = mango.storage('images').split(',');
90+
const filename = page + '.jpg';
91+
if (page >= urls.length) return JSON.stringify({});
92+
var img_url = urls[page];
93+
mango.storage('page', (page + 1).toString());
94+
return JSON.stringify({
95+
url: img_url,
96+
filename: filename,
97+
});
98+
}

plugins/manhuadb/info.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"id": "manhuadb",
3+
"title": "ManhuaDB",
4+
"author": "Ftbom - [email protected]",
5+
"version": "v1.0",
6+
"placeholder": "Search ManhuaDB",
7+
"wait_seconds": 2,
8+
"api_version": 2,
9+
"settings": {
10+
}
11+
}

0 commit comments

Comments
 (0)