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

Commit 07ab179

Browse files
author
TheBritishAccent
committed
Add manganelo plugin
1 parent 9fa43a1 commit 07ab179

File tree

3 files changed

+155
-0
lines changed

3 files changed

+155
-0
lines changed

plugins/manganelo/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Manganelo Plugin
2+
3+
This is the Mango plugin for [Manganelo](https://manganelo.com/).
4+
5+
Note that
6+
7+
- All downloaded chapters will be placed in their respective series folder in your library.
8+
- Cloudflare rate limits extensive downloads. Adjust `wait_seconds` in `info.json` if you plan to download many chapters in one go (or chapters with many pages).
9+
10+
Maintained by [@TheBritishAccent](https://github.com/TheBritishAccent).

plugins/manganelo/index.js

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
var currentPage = 0;
2+
var digits = 0;
3+
var imgURLs;
4+
5+
const SEARCH_URL = "https://manganelo.com/getstorysearchjson";
6+
const MANGA_URL = "https://manganelo.com/manga/";
7+
const CHAPTER_URL = "https://manganelo.com/chapter/";
8+
9+
function listChapters(query) {
10+
var search = mango.post(SEARCH_URL, "searchword=" + query, {
11+
"content-type" : "application/x-www-form-urlencoded"
12+
}).body;
13+
14+
if (!search) {
15+
mango.raise("An error occured when searching.");
16+
}
17+
18+
var mangaID = JSON.parse(search)[0].id_encode;
19+
var mangaURL = MANGA_URL + mangaID;
20+
21+
var html = mango.get(mangaURL).body;
22+
23+
if(!html) {
24+
mango.raise("Failed to find manga.");
25+
}
26+
27+
var mangaTitleNode = mango.css(html, "div.story-info-right h1")[0];
28+
29+
if (!mangaTitleNode) {
30+
mango.raise("Failed to get chapter title.");
31+
}
32+
33+
var mangaTitle = mango.text(mangaTitleNode);
34+
35+
var chapters = [];
36+
mango.css(html, "ul.row-content-chapter li").forEach(function (element) {
37+
var linkNode = mango.css(element, "a.chapter-name")[0];
38+
var uploadNode = mango.css(element, "span.chapter-time")[0];
39+
40+
var mangaChapterNumber;
41+
try {
42+
var url = mango.attribute(linkNode, "href");
43+
44+
// Extract yyy(.yy) from: https://manganelo.com/chapter/xxxxxxxx/chapter_yyy.yy
45+
mangaChapterNumber = /chapter_((\d+.?)*)/.exec(url)[1];
46+
47+
// Replace '.' with '_', since ids can't contain '.'
48+
mangaChapterNumber = mangaChapterNumber.replace(/\./, "_");
49+
} catch (e) {
50+
mango.raise("Failed to get chapter number.");
51+
}
52+
53+
var chapterID = mangaID + "ch" + mangaChapterNumber // Create ID as xxxxxxxxchyyy(_yy)
54+
var chapterTitle = mango.text(linkNode);
55+
var chapterUploadedTime = mango.attribute(uploadNode, "title");
56+
57+
var slimObj = {};
58+
slimObj['id'] = chapterID;
59+
slimObj['title'] = chapterTitle;
60+
slimObj['time-uploaded'] = chapterUploadedTime;
61+
chapters.push(slimObj);
62+
});
63+
64+
return JSON.stringify({
65+
chapters: chapters,
66+
title: mangaTitle
67+
});
68+
}
69+
70+
function selectChapter(id) {
71+
var mangaIDMatch = /(.*?)ch((\d_?)*)$/.exec(id); // Extract xxxxxxxx & yyy(_yy) from ID.
72+
var mangaID = mangaIDMatch[1];
73+
var mangaChapterNumber = mangaIDMatch[2].replace(/\_/, "."); // Convert '_' back to '.'
74+
75+
// Create URL formatted like https://manganelo.com/chapter/xxxxxxxx/chapter_yyy.yy
76+
var mangaURL = CHAPTER_URL + mangaID + "/chapter_" + mangaChapterNumber;
77+
78+
var html = mango.get(mangaURL).body;
79+
80+
if(!html) {
81+
mango.raise("Failed to load chapter.");
82+
}
83+
84+
var chapterTitleNode = mango.css(html, "div.panel-breadcrumb a:last-child")[0];
85+
86+
if (!chapterTitleNode) {
87+
mango.raise("Failed to get chapter title.")
88+
}
89+
90+
var chapterTitle = mango.text(chapterTitleNode);
91+
92+
var imageNodes = mango.css(html, "div.container-chapter-reader img");
93+
94+
if (!imageNodes) {
95+
mango.raise("Failed to get images.")
96+
}
97+
98+
imgURLs = [];
99+
imageNodes.forEach(function(element) {
100+
imgURLs.push(
101+
mango.attribute(element, "src")
102+
);
103+
})
104+
105+
currentPage = 0;
106+
digits = Math.floor(Math.log10(imgURLs.length)) + 1;
107+
108+
return JSON.stringify({
109+
title: chapterTitle,
110+
pages: imgURLs.length
111+
});
112+
}
113+
114+
function nextPage() {
115+
if (currentPage >= imgURLs.length) {
116+
return JSON.stringify({});
117+
}
118+
119+
var url = imgURLs[currentPage]
120+
var filename = pad(currentPage, digits) + '.' + /\.(\w+)$/.exec(url)[0];
121+
122+
currentPage += 1;
123+
return JSON.stringify({
124+
url: url,
125+
filename: filename,
126+
headers: {
127+
'referer': "https://manganelo.com/"
128+
}
129+
});
130+
}
131+
132+
// https://stackoverflow.com/a/10073788
133+
function pad(n, width, z) {
134+
z = z || '0';
135+
n = n + '';
136+
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
137+
}

plugins/manganelo/info.json

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

0 commit comments

Comments
 (0)