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

Commit f69aa5a

Browse files
committed
Correctly handle gif pages (resolves #25)
1 parent 0f6b0b6 commit f69aa5a

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

plugins/nhentai/index.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function selectChapter(id) {
6363

6464
uglyPageURL = mango.attribute(firstPageATag, 'data-src');
6565
var pageURLMatch = /\/galleries\/([0-9]+)\/.*?\.(\w*)/.exec(uglyPageURL);
66-
66+
6767
pageURL = NHENTAI_IMAGE_URL + pageURLMatch[1] + "/";
6868
imageType = pageURLMatch[2];
6969

@@ -82,22 +82,28 @@ function nextPage() {
8282
if (ended) {
8383
return JSON.stringify({});
8484
}
85-
85+
8686
pageCount += 1;
8787

8888
if (pageCount === totalPages) {
8989
ended = true;
9090
}
9191

92-
var url = pageURL + pageCount + "." + imageType;
92+
var url, extension;
93+
var extensions = [imageType, 'png', 'jpg', 'gif', 'jpeg'];
9394

9495
// Not all galleries have uniform file types
9596
// Post should return 405 if path exists, 404 otherwise.
96-
if (mango.post(url, "").status_code == 404) {
97-
url = pageURL + pageCount + "." + (imageType == "png" ? "jpg" : "png");
97+
for (var i = 0; i < extensions.length; i++) {
98+
extension = extensions[i];
99+
url = pageURL + pageCount + "." + extension;
100+
if (mango.post(url, "").status_code == 405) {
101+
// We got the right extension
102+
break;
103+
}
98104
}
99105

100-
var filename = pad(pageCount, digits) + '.' + imageType;
106+
var filename = pad(pageCount, digits) + '.' + extension;
101107

102108
return JSON.stringify({
103109
url: url,

0 commit comments

Comments
 (0)