Skip to content

Commit

Permalink
Some chapters on 38xs.com span multiple web pages
Browse files Browse the repository at this point in the history
See: #1081
  • Loading branch information
dteviot committed Sep 28, 2023
1 parent 2071f95 commit 4bef69e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
14 changes: 14 additions & 0 deletions plugin/js/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,20 @@ class Parser {
content.appendChild(header);
content.appendChild(list);
}
}

async walkPagesOfChapter(url, moreChapterTextUrl) {
let dom = (await HttpClient.wrapFetch(url)).responseXML;
let count = 2;
let nextUrl = moreChapterTextUrl(dom, url, count);
let oldContent = this.findContent(dom);
while(nextUrl != null) {
let nextDom = (await HttpClient.wrapFetch(nextUrl)).responseXML;
let newContent = this.findContent(nextDom);
util.moveChildElements(newContent, oldContent);
nextUrl = moreChapterTextUrl(nextDom, url, ++count);
}
return dom;
}
}

Expand Down
12 changes: 12 additions & 0 deletions plugin/js/parsers/230BookParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,16 @@ class _38xsParser extends _230BookBaseParser{
? list.slice(13)
: list;
}

async fetchChapter(url) {
return this.walkPagesOfChapter(url, this.moreChapterTextUrl);
}

moreChapterTextUrl(dom) {
let nextUrl = dom.querySelector("a#pager_next");
return (nextUrl != null && nextUrl.href.includes("_"))
? nextUrl.href
: null;
}

}
12 changes: 1 addition & 11 deletions plugin/js/parsers/GzbpParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,7 @@ class GzbpParser extends Parser{
}

async fetchChapter(url) {
let dom = (await HttpClient.wrapFetch(url)).responseXML;
let count = 2;
let nextUrl = this.moreChapterTextUrl(dom, url, count);
let oldContent = this.findContent(dom);
while(nextUrl != null) {
let nextDom = (await HttpClient.wrapFetch(nextUrl)).responseXML;
let newContent = this.findContent(nextDom);
util.moveChildElements(newContent, oldContent);
nextUrl = this.moreChapterTextUrl(nextDom, url, ++count);
}
return dom;
return this.walkPagesOfChapter(url, this.moreChapterTextUrl);
}

moreChapterTextUrl(dom, url, count) {
Expand Down

0 comments on commit 4bef69e

Please sign in to comment.