refactor: Classes for Plugins (#631)

* set target to ES5

* refactor types

* use .gitkeep

* use dot to make dist/js dirs on top

* add hako

* add Hako

* add madara

* fix: url path js -> .js

* fix: branch

* freestyle for using UA, cookie

* add parseNovels for Hako

* update readme

* fix: conflict types

* add Kolnovel, remove node-fetch

* add bestlightnovel

* add plugins

* WQMangaStreamScraper
* PandaMTL
* NobleMTL
* LightNovelBrasil
* WPMangaStream

* add filters for popularNovels

* fix undefined json

* Linovelib (#26)

* linovelib CN

* icon for linovelib

* fix undefined chapter

* add check

* fix: add artist

* TuNovelaLigera ES + Madara Fix (#28)

* app repo test

* POST is now working

* update madara template + run generator

* template fix didnt get pushed commited idk why

* template update POST

* generated

* fix: useNewChapterEndpoint update (#29)

* useNewChapterEndpoint update

* Update Selectors

---------

Co-authored-by: K1ngfish3r <trulyihu@gmail.com>
This commit is contained in:
nyagami
2023-11-04 17:15:49 +07:00
committed by GitHub
parent 538841ddee
commit 20efcf404c
295 changed files with 67636 additions and 57286 deletions
+148
View File
@@ -0,0 +1,148 @@
import { load as parseHTML } from "cheerio";
import { fetchApi, fetchFile } from "@libs/fetch";
import { Chapter, Novel, Plugin } from "@typings/plugin";
export const id = "novelhold";
export const name = "Novel Hold";
export const version = "1.0.0";
export const icon = "src/en/novelhold/icon.png";
export const site = "https://novelhold.com/";
const baseUrl = site;
export const popularNovels: Plugin.popularNovels = async function (page) {
const url = `${baseUrl}all-${page}.html`;
const body = await fetchApi(url).then((r) => r.text());
const loadedCheerio = parseHTML(body);
let novels: Novel.Item[] = [];
loadedCheerio("#article_list_content > li").each(function () {
const novelName = loadedCheerio(this)
.find("h3")
.text()
.replace(/\t+/g, "")
.replace(/\n/g, " ");
const novelCover = loadedCheerio(this).find("img").attr("data-src");
const novelUrl =
baseUrl + loadedCheerio(this).find("a").attr("href")?.slice(1);
const novel = {
name: novelName,
cover: novelCover,
url: novelUrl,
};
novels.push(novel);
});
return novels;
};
export const parseNovelAndChapters: Plugin.parseNovelAndChapters =
async function (novelUrl) {
const url = novelUrl;
const body = await fetchApi(url).then((r) => r.text());
let loadedCheerio = parseHTML(body);
const novel: Novel.instance = {
url,
chapters: [],
};
novel.name = loadedCheerio(".booknav2 > h1").text();
novel.cover = loadedCheerio('meta[property="og:image"]').attr(
"content"
);
novel.summary = loadedCheerio(".navtxt").text().trim();
novel.author = loadedCheerio('p:contains("Author")')
.text()
.replace("Author:", "")
.trim();
novel.status = loadedCheerio('p:contains("Status")')
.text()
.replace("Status:", "")
.replace("Active", "Ongoing")
.trim();
novel.genres = loadedCheerio('p:contains("Genre")')
.text()
?.replace("Genre:", "")
.trim();
let chapter: Chapter.Item[] = [];
loadedCheerio("ul.chapterlist > li").each(function () {
const chapterName = loadedCheerio(this).find("a").text().trim();
const releaseDate = null;
const chapterUrl =
baseUrl + loadedCheerio(this).find("a").attr("href")?.slice(1);
chapter.push({
name: chapterName,
releaseTime: releaseDate,
url: chapterUrl,
});
});
novel.chapters = chapter;
console.log(novel);
return novel;
};
export const parseChapter: Plugin.parseChapter = async function (chapterUrl) {
const body = await fetchApi(chapterUrl).then((r) => r.text());
let loadedCheerio = parseHTML(body);
const chapterText = loadedCheerio(".content").html();
return chapterText;
};
export const searchNovels: Plugin.searchNovels = async function (searchTerm) {
const url = `${baseUrl}index.php?s=so&module=book&keyword=${searchTerm}`;
const body = await fetchApi(url).then((r) => r.text());
let loadedCheerio = parseHTML(body);
let novels: Novel.Item[] = [];
loadedCheerio("#article_list_content > li").each(function () {
const novelName = loadedCheerio(this)
.find("h3")
.text()
.replace(/\t+/g, "")
.replace(/\n/g, " ");
const novelCover = loadedCheerio(this).find("img").attr("data-src");
const novelUrl =
baseUrl + loadedCheerio(this).find("a").attr("href")?.slice(1);
const novel = {
name: novelName,
cover: novelCover,
url: novelUrl,
};
novels.push(novel);
});
return novels;
};
export const fetchImage: Plugin.fetchImage = async function (url) {
const headers = {
Referer: baseUrl,
};
return await fetchFile(url, { headers: headers });
};