Skip to content

Commit

Permalink
Merge pull request #1167 from perishableloc/ExperimentalTabMode
Browse files Browse the repository at this point in the history
Fix KemonopartyParser
  • Loading branch information
dteviot authored Jan 17, 2024
2 parents 48b318b + af9eee5 commit 6cd5e0f
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions plugin/js/parsers/KemonopartyParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@ class KemonopartyParser extends Parser{
};

getUrlsOfTocPages(dom) {
let urls = [];
let paginator = dom.querySelector("div.paginator menu");
if (paginator === null) {
return [];
return urls;
}
return [...paginator.querySelectorAll("a:not(next)")]
.map(link => link.href);
let pages = [...paginator.querySelectorAll("a:not(.next)")];
let url = new URL(pages[pages.length - 1]);
let lastPageOffset = url.searchParams.get("o");
for(let i = 50; i <= lastPageOffset; i += 50) {
url.searchParams.set("o", i);
urls.push(url.href);
}
return urls;
}

extractPartialChapterList(dom) {
Expand All @@ -32,15 +39,21 @@ class KemonopartyParser extends Parser{
}));
}

removeUnwantedElementsFromContentElement(element) {
util.removeChildElementsMatchingCss(element, ".ad-container");
super.removeUnwantedElementsFromContentElement(element);
}

findContent(dom) {
return dom.querySelector(".post__body");
//the text of the chapter is always in .post__content, but if there is no chapter(e.g. only files), return .post__body instead of throwing an error
return dom.querySelector(".post__content") ?? dom.querySelector(".post__body");
}

extractTitleImpl(dom) {
return dom.querySelector("h1");
}

findChapterTitle(dom) {
return dom.querySelector("h1.post__title");
return dom.querySelector("h1.post__title > span");
}
}

0 comments on commit 6cd5e0f

Please sign in to comment.