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
-159
View File
@@ -1,159 +0,0 @@
import { load as parseHTML } from "cheerio";
import { fetchApi, fetchFile } from "@libs/fetch";
import { NovelStatus } from "@libs/novelStatus";
import { Chapter, Novel, Plugin } from "@typings/plugin";
export const id = "novelringan.com";
export const name = "NovelRingan";
export const site = "https://novelringan.com/";
export const icon = "src/id/novelringan/icon.png";
export const version = "1.0.0";
const baseUrl = site;
const coverUriPrefix = "https://i0.wp.com/novelringan.com/wp-content/uploads/";
export const popularNovels: Plugin.popularNovels = async function (page) {
const url = `${baseUrl}/top-novel/page/${page}`;
const result = await fetchApi(url);
const body = await result.text();
const loadedCheerio = parseHTML(body);
const novels: Novel.Item[] = [];
loadedCheerio("article.post").each(function () {
const novelName = loadedCheerio(this)
.find(".entry-title")
.text()
?.trim();
const novelCover =
coverUriPrefix + loadedCheerio(this).find("img").attr("data-sxrx");
const novelUrl = loadedCheerio(this).find("h2 > a").attr("href");
if (!novelUrl) return;
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 result = await fetchApi(url);
const body = await result.text();
const loadedCheerio = parseHTML(body);
let novel: Novel.instance = {
url,
name: "",
cover: "",
genres: "",
author: "",
status: NovelStatus.Unknown,
summary: "",
chapters: [],
};
novel.name = loadedCheerio(".entry-title").text()?.trim();
novel.cover =
coverUriPrefix +
loadedCheerio("img.ts-post-image").attr("data-sxrx");
novel.summary = loadedCheerio(
"body > div.site-container > div > main > article > div > div.maininfo > span > p"
).text();
let genreSelector = loadedCheerio(
"body > div.site-container > div > main > article > div > div.maininfo > span > ul > li:nth-child(4)"
).text();
novel.genres = genreSelector.includes("Genre")
? genreSelector.replace("Genre:", "").trim()
: "";
let statusSelector = loadedCheerio(
"body > div.site-container > div > main > article > div > div.maininfo > span > ul > li:nth-child(3)"
).text();
novel.status = statusSelector.includes("Status")
? statusSelector.replace("Status:", "").trim()
: NovelStatus.Unknown;
let chapters: Chapter.Item[] = [];
loadedCheerio(".bxcl > ul > li").each(function () {
const chapterName = loadedCheerio(this).find("a").text();
const releaseDate = null;
const chapterUrl = loadedCheerio(this).find("a").attr("href");
if (!chapterUrl) return;
const chapter = {
name: chapterName,
releaseTime: releaseDate,
url: chapterUrl,
};
chapters.push(chapter);
});
novel.chapters = chapters.reverse();
return novel;
};
export const parseChapter: Plugin.parseChapter = async function (chapterUrl) {
const url = chapterUrl;
const result = await fetchApi(url);
const body = await result.text();
const loadedCheerio = parseHTML(body);
loadedCheerio('.entry-content div[style="display:none"]').remove();
const chapterText = loadedCheerio(".entry-content").html();
return chapterText;
};
export const searchNovels: Plugin.searchNovels = async function (searchTerm) {
const url = baseUrl + "?s=" + searchTerm;
const result = await fetchApi(url);
const body = await result.text();
const loadedCheerio = parseHTML(body);
let novels: Novel.Item[] = [];
loadedCheerio("article.post").each(function () {
const novelName = loadedCheerio(this).find(".entry-title").text();
const novelCover =
coverUriPrefix + loadedCheerio(this).find("img").attr("data-sxrx");
const novelUrl = loadedCheerio(this).find("h2 > a").attr("href");
if (!novelUrl) return;
const novel = {
name: novelName,
cover: novelCover,
url: novelUrl,
};
novels.push(novel);
});
return novels;
};
export const fetchImage: Plugin.fetchImage = fetchFile;