Skip to content

Commit

Permalink
update SyosetuParser
Browse files Browse the repository at this point in the history
  • Loading branch information
gamebeaker committed Sep 24, 2024
1 parent 93a8aca commit c214ce6
Showing 1 changed file with 11 additions and 35 deletions.
46 changes: 11 additions & 35 deletions plugin/js/parsers/SyosetuParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,15 @@ class SyosetuParser extends Parser{
}

async getChapterUrls(dom, chapterUrlsUI) {
await this.fetchAndAttachInfoPage(dom);
return this.getChapterUrlsFromMultipleTocPages(dom,
this.extractPartialChapterList,
this.getUrlsOfTocPages,
chapterUrlsUI
);
}

async fetchAndAttachInfoPage(dom) {
const infoPageUrl = dom.querySelector("#head_nav > li:nth-child(2) > a").href;
this.infoPageDom = (await HttpClient.fetchHtml(infoPageUrl)).responseXML; // Parse and store the info page DOM
}

getUrlsOfTocPages(dom) {
let lastPage = dom.querySelector("a.novelview_pager-last");
let lastPage = dom.querySelector("a.c-pager__item--last");
let urls = [];
if (lastPage) {
const lastPageNumber = parseInt(lastPage.href.split("?p=")[1]);
Expand All @@ -37,20 +31,20 @@ class SyosetuParser extends Parser{
}

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

findContent(dom) {
return dom.querySelector("div#novel_honbun");
return dom.querySelector("div.p-novel__body");
};

extractTitleImpl(dom) {
return dom.querySelector(".novel_title");
return dom.querySelector(".p-novel__title");
};

extractAuthor(dom) {
const authorDiv = dom.querySelector("div.novel_writername");
const authorDiv = dom.querySelector("div.p-novel__author");
if (authorDiv) {
const authorText = authorDiv.textContent.trim().replace(/^作者:/, "");
return authorDiv.querySelector("a")?.textContent.trim() || authorText;
Expand All @@ -59,33 +53,15 @@ class SyosetuParser extends Parser{
}

findChapterTitle(dom) {
let element = dom.querySelector(".novel_subtitle");
let element = dom.querySelector(".p-novel__title");
return (element === null) ? null : element.textContent;
}

getInformationEpubItemChildNodes() {
const infoNodes = [];
const infoTable = this.infoPageDom.querySelector("#infodata");
const infoTableClone = infoTable.cloneNode(true);
infoNodes.push(infoTableClone);
return infoNodes;
getInformationEpubItemChildNodes(dom) {
return [...dom.querySelectorAll("h1.p-novel__title, #novel_ex")];
}

cleanInformationNode(node) {
util.removeChildElementsMatchingCss(node, "#qr, #pre_info > a");
const preInfoDiv = node.querySelector("#pre_info");
this.removePipeCharacter(preInfoDiv);
let sibling = preInfoDiv.querySelector("#noveltype_notend")?.nextSibling;
if (sibling) {
sibling.textContent = sibling.textContent.replace(/^全/, " 全");
}
}

removePipeCharacter(contentElement) {
let walker = contentElement.ownerDocument.createTreeWalker(contentElement, NodeFilter.SHOW_TEXT);
while (walker.nextNode()) {
let node = walker.currentNode;
node.textContent = node.textContent.replace(/\|/g, "");
};
}
extractDescription(dom) {
return dom.querySelector(".p-novel__summary").textContent.trim();
}
}

0 comments on commit c214ce6

Please sign in to comment.