Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
See: #1117
  • Loading branch information
dteviot committed Nov 26, 2023
1 parent bf164e0 commit fd3479a
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions plugin/js/parsers/ShanghaifantasyParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,29 @@ class ShanghaifantasyParser extends Parser{
}

async getChapterUrls(dom) {
let menu = dom.querySelector("div.elementor-posts-container");
return util.hyperlinksToChapterList(menu);
let tocUrl = this.buildTocUrl(dom);
let json = (await HttpClient.fetchJson(tocUrl)).json;
return this.buildChapterUrls(json);
}

buildTocUrl(dom) {
let category = dom.querySelector("ul#chapterList")?.getAttribute("data-cat");
return `https://shanghaifantasy.com/wp-json/fiction/v1/chapters?category=${category}&order=asc&page=1&per_page=10000`;
}

buildChapterUrls(json) {
return json.map(a => ({
title: a.title,
sourceUrl: a.permalink
}));
}

findContent(dom) {
return dom.querySelector("div[data-widget_type='theme-post-content.default']");
return dom.querySelector("div.contenta");
}

extractTitleImpl(dom) {
return dom.querySelector("h1");
return dom.querySelector("title")?.textContent ?? null;;
}

removeUnwantedElementsFromContentElement(element) {
Expand All @@ -26,14 +39,14 @@ class ShanghaifantasyParser extends Parser{
}

findChapterTitle(dom) {
return dom.querySelector("h1");
return dom.querySelector("title")?.textContent ?? null;
}

findCoverImageUrl(dom) {
return util.getFirstImgSrc(dom, "div[data-widget_type='image.default']");
return util.getFirstImgSrc(dom, ".flex-col");
}

getInformationEpubItemChildNodes(dom) {
return [...dom.querySelectorAll("div[role='tablist'] p")];
return [...dom.querySelectorAll("div#editdescription")];
}
}

0 comments on commit fd3479a

Please sign in to comment.