Skip to content
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 @@ -107,7 +107,8 @@
{ "name": "mobedoor" },
{ "name": "nitramkh", "email": "nitramkh@gmail.com" },
{ "name": "s4daharu", "email": "s4daharu@gmail.com" },
{ "name": "crn0" }
{ "name": "crn0" },
{ "name": "meowmereo"}
],
"license": "GPL-3.0-only",
"bugs": {
Expand Down
97 changes: 97 additions & 0 deletions plugin/js/parsers/TruyenmoikkParser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
"use strict";

parserFactory.register("truyenmoikk.com", () => new TruyenMoiKKParser());

class TruyenMoiKKParser extends Parser {
constructor() {
super();
}

async getChapterUrls(dom, chapterUrlsUI) {
let chapters = await this.getChapterUrlsFromMultipleTocPages(
dom,
TruyenMoiKKParser.extractPartialChapterList,
TruyenMoiKKParser.getUrlsOfTocPages,
chapterUrlsUI
);

chapters.sort((a, b) => {
let numA = parseInt(a.sourceUrl.match(/chuong-(\d+)/)?.[1] || 0, 10);
let numB = parseInt(b.sourceUrl.match(/chuong-(\d+)/)?.[1] || 0, 10);
return numA - numB;
});

return chapters.filter((v, i, a) => a.findIndex(t => (t.sourceUrl === v.sourceUrl)) === i);
}

static getUrlsOfTocPages(dom) {
let urls = [];
let pageNodes = Array.from(dom.querySelectorAll("ul.pagination li a"));
let maxPage = 1;

pageNodes.forEach(a => {
let p = parseInt(a.textContent.trim(), 10);
if (!isNaN(p) && p > maxPage) {
maxPage = p;
}
});

let current = new URL(dom.baseURI);
let basePath = current.pathname.replace(/\/trang-\d+\/?$/, "");
if (!basePath.endsWith("/")) {
basePath += "/";
}

for (let i = 2; i <= maxPage; i++) {
let u = new URL(current);
u.hash = "";
u.search = "";
u.pathname = basePath + `trang-${i}`;
urls.push(u.toString());
}
return urls;
}

static extractPartialChapterList(dom) {
return [...dom.querySelectorAll("ul.list-chapter li a")]
.map(link => util.hyperLinkToChapter(link));
}

findContent(dom) {
return dom.querySelector("article.chapter-content");
}

extractTitleImpl(dom) {
return dom.querySelector("h1.story-title")?.textContent.trim();
}

extractAuthor(dom) {
return dom.querySelector("div[itemprop='author'] span[itemprop='name']")?.textContent.trim() || super.extractAuthor(dom);
}

findCoverImageUrl(dom) {
let metaThumb = dom.querySelector("meta[itemprop='thumbnailUrl']");
if (metaThumb && metaThumb.content) {
return metaThumb.content;
}
return util.getFirstImgSrc(dom, ".book img[itemprop='image']");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just needs to be

return util.getFirstImgSrc(dom, ".book");

Function locates the first image inside the element matching the CSS selector

}

findChapterTitle(dom) {
let titleNode = dom.querySelector("a.chapter-title") || dom.querySelector("h2");
return titleNode ? titleNode.textContent.trim() : super.findChapterTitle(dom);
}

extractSubject(dom) {
let genres = Array.from(dom.querySelectorAll("a[itemprop='genre']"));
return genres.map(a => a.textContent.trim()).join(", ");
}

extractDescription(dom) {
return dom.querySelector(".desc-text")?.textContent.trim() || super.extractDescription(dom);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI. If you implement getInformationEpubItemChildNodes(), you don't need to implement extractDescription()
Base implementation of extractDescription() calls getInformationEpubItemChildNodes()

}

getInformationEpubItemChildNodes(dom) {
return [...dom.querySelectorAll(".desc-text")];
}
}
1 change: 1 addition & 0 deletions plugin/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,7 @@ <h3>Instructions</h3>
<script src="js/parsers/TravistranslationsParser.js"></script>
<script src="js/parsers/TruyenfullParser.js"></script>
<script src="js/parsers/TruyenFullVisionParser.js"></script>
<script src="js/parsers/TruyenmoikkParser.js"></script>
<script src="js/parsers/TruyenyyParser.js"></script>
<script src="js/parsers/TruyenParser.js"></script>
<script src="js/parsers/TrxsParser.js"></script>
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ Don't forget to give the project a star! Thanks again!
<li>nitramkh</li>
<li>s4daharu</li>
<li>crn0</li>
<li>meowmereo</li>
</ul>
</details>

Expand Down
Loading