Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-Fixed broken Syosetu parser #1201

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
{ "name": "Oleksii Taranenko"},
{ "name": "Naheulf"},
{ "name": "perishableloc"},
{ "name": "praschke"}
{ "name": "praschke"},
{ "name": "ImmortalDreamer"}
],
"license": "GPL-3.0-only",
"bugs": {
Expand Down
40 changes: 32 additions & 8 deletions plugin/js/parsers/SyosetuParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,31 @@ class SyosetuParser extends Parser{
super();
}

getChapterUrls(dom) {
let menu = dom.querySelector("div.index_box")
|| dom.querySelector("div.novel_sublist")
return Promise.resolve(util.hyperlinksToChapterList(menu));
};
async getChapterUrls(dom, chapterUrlsUI) {
return this.getChapterUrlsFromMultipleTocPages(dom,
this.extractPartialChapterList,
this.getUrlsOfTocPages,
chapterUrlsUI
);
}

getUrlsOfTocPages(dom) {
let lastPage = dom.querySelector("a.novelview_pager-last");
let urls = [];
if (lastPage) {
const lastPageNumber = parseInt(lastPage.href.split('?p=')[1]);
const baseUrl = lastPage.href.substring(0, lastPage.href.lastIndexOf('?p='));
for (let i = 2; i <= lastPageNumber; i++) {
urls.push(`${baseUrl}?p=${i}`);
}
}
return urls;
}

extractPartialChapterList(dom) {
let chapterList = dom.querySelector("div.index_box") || dom.querySelector("div.novel_sublist");
return [...chapterList.querySelectorAll("a")].map(a => util.hyperLinkToChapter(a));
}

findContent(dom) {
return dom.querySelector("div#novel_honbun");
Expand All @@ -23,9 +43,13 @@ class SyosetuParser extends Parser{
};

extractAuthor(dom) {
let authorLabel = dom.querySelector("div.novel_writername a");
return (authorLabel === null) ? super.extractAuthor(dom) : authorLabel.textContent;
};
const authorDiv = dom.querySelector("div.novel_writername");
if (authorDiv) {
const authorText = authorDiv.textContent.trim().replace(/^作者:/, "");
return authorDiv.querySelector("a")?.textContent.trim() || authorText;
}
return super.extractAuthor(dom);
}

findChapterTitle(dom) {
let element = dom.querySelector(".novel_subtitle");
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Credits
* Naheulf
* perishableloc
* praschke
* ImmortalDreamer

## How to use with Baka-Tsuki:
* Browse to a Baka-Tsuki web page that has the full text of a story.
Expand Down