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

Commit cd892a5

Browse files
committed
Add wnacg plugin
1 parent 187a76a commit cd892a5

File tree

3 files changed

+130
-0
lines changed

3 files changed

+130
-0
lines changed

plugins/wnacg/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# wnacg Plugin
2+
3+
This is the Mango plugin for [wnacg](http://www.wnacg.org/).
4+
5+
Note that
6+
7+
All downloaded galleries will be placed in the `wnacg` folder in your library.
8+
9+
Maintained by [@Ftbom](https://github.com/Ftbom).
10+
11+
Thanks to [@hkalexling](https://github.com/hkalexling)'s E-Hentai plgin.

plugins/wnacg/index.js

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
var pageURL;
2+
var pageCount = 0;
3+
var ended = false;
4+
var digits = 0;
5+
var firstpageURl;
6+
var baseURL = 'http://www.wnacg.org';
7+
8+
function listChapters(url) {
9+
var html = mango.get(url).body;
10+
11+
var urlMatch = /aid-([0-9]+)\.html/.exec(url);
12+
13+
var chapterID = urlMatch[1];
14+
15+
var chapterTitleNode = mango.css(html, 'h2')[0];
16+
17+
if (!chapterTitleNode)
18+
mango.raise("Failed to get the title");
19+
20+
var chapterTitle = mango.text(chapterTitleNode);
21+
22+
var chapters = [{
23+
id: chapterID,
24+
title: chapterTitle
25+
}];
26+
27+
return JSON.stringify({
28+
chapters: chapters,
29+
title: 'wnacg'
30+
});
31+
}
32+
33+
function selectChapter(id) {
34+
var url = baseURL+'/photos-index-aid-' + id + '.html';
35+
36+
var html = mango.get(url).body;
37+
38+
var chapterTitleNode = mango.css(html, 'h2')[0];
39+
40+
if (!chapterTitleNode)
41+
mango.raise("Failed to get the title");
42+
43+
var chapterTitle = mango.text(chapterTitleNode);
44+
45+
var pages = 0;
46+
try {
47+
var lengthRow = mango.css(html, '.asTB div.asTBcell.uwconn')[0];
48+
if (!lengthRow)
49+
throw new Error
50+
var lengthText = mango.text(lengthRow);
51+
pages = parseInt(/([0-9]+)/.exec(lengthText)[1]);
52+
} catch (e) {
53+
mango.raise("Failed to get the page count");
54+
}
55+
56+
var firstPageATag = mango.css(html, 'div.pic_box.tb a:first-child')[0];
57+
if (!firstPageATag)
58+
mango.raise("Failed to get the URL of the first page");
59+
60+
pageURL = baseURL + mango.attribute(firstPageATag, 'href');
61+
62+
firstpageURL=pageURL;
63+
64+
ended = false;
65+
pageCount = 0;
66+
digits = Math.floor(Math.log10(pages)) + 1;
67+
68+
return JSON.stringify({
69+
title: chapterTitle,
70+
pages: pages
71+
});
72+
}
73+
74+
function nextPage() {
75+
if (ended)
76+
return JSON.stringify({});
77+
78+
pageCount += 1;
79+
80+
var html = mango.get(pageURL).body;
81+
82+
var aTag = mango.css(html, '#photo_body a')[0];
83+
if (!aTag)
84+
mango.raise("Failed to get the URL of the next page");
85+
86+
var nextPageURL = baseURL + mango.attribute(aTag, 'href');
87+
88+
if (nextPageURL === firstpageURL)
89+
ended = true;
90+
91+
pageURL = nextPageURL;
92+
93+
var imgTag = mango.css(aTag, 'img')[0];
94+
if (!imgTag)
95+
mango.raise("Failed to get the image URL");
96+
97+
var url = 'http:' + mango.attribute(imgTag, 'src');
98+
var filename = pad(pageCount, digits) + '.jpg'
99+
100+
return JSON.stringify({
101+
url: url,
102+
filename: filename
103+
});
104+
}
105+
106+
// https://stackoverflow.com/a/10073788
107+
function pad(n, width, z) {
108+
z = z || '0';
109+
n = n + '';
110+
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
111+
}

plugins/wnacg/info.json

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

0 commit comments

Comments
 (0)