Filters Redesign (#658)

* Add XCheckboxFilter

* Fix madara typo

* Change the branch name in config

* Add typing for madara popoularnovels filters

* Add preview and refactor PluginWrapper

* Add preview HTML sanitize and other improv.

* Web improvements + sanitizeHTML

* Add dark mode

* Add git run less to compile less

* Add less.js to remove the need for compiling less
This commit is contained in:
Marcin Majewski
2023-12-27 15:49:46 +01:00
committed by GitHub
parent 9cdace3460
commit d7a76063bf
170 changed files with 94169 additions and 80752 deletions
+30 -21
View File
@@ -2,7 +2,6 @@ import { CheerioAPI, load as parseHTML } from "cheerio";
import { fetchApi, fetchFile } from "@libs/fetch";
import { Plugin } from "@typings/plugin";
import { isUrlAbsolute } from "@libs/isAbsoluteUrl";
import { Filter } from "@libs/filterInputs";
class HakoPlugin implements Plugin.PluginBase {
id: string;
name: string;
@@ -11,7 +10,7 @@ class HakoPlugin implements Plugin.PluginBase {
version: string;
userAgent: string;
cookieString: string;
constructor(){
constructor() {
this.id = "ln.hako";
this.name = "Hako";
this.icon = "src/vi/hakolightnovel/icon.png";
@@ -20,7 +19,7 @@ class HakoPlugin implements Plugin.PluginBase {
this.userAgent = "";
this.cookieString = "";
}
parseNovels(loadedCheerio: CheerioAPI){
parseNovels(loadedCheerio: CheerioAPI) {
const novels: Plugin.NovelItem[] = [];
loadedCheerio(".row > .thumb-item-flow").each((index, ele) => {
let url = loadedCheerio(ele)
@@ -44,15 +43,21 @@ class HakoPlugin implements Plugin.PluginBase {
cover = this.site + cover;
}
const novel = {name, url, cover};
const novel = { name, url, cover };
novels.push(novel);
}
});
return novels;
}
async popularNovels(pageNo: number, options: Plugin.PopularNovelsOptions): Promise<Plugin.NovelItem[]> {
const link = this.site + "/danh-sach?truyendich=1&sapxep=topthang&page=" + pageNo;
async popularNovels(
pageNo: number,
options: Plugin.PopularNovelsOptions
): Promise<Plugin.NovelItem[]> {
const link =
this.site +
"/danh-sach?truyendich=1&sapxep=topthang&page=" +
pageNo;
const result = await fetch(link);
const body = await result.text();
const loadedCheerio = parseHTML(body);
@@ -64,32 +69,33 @@ class HakoPlugin implements Plugin.PluginBase {
};
const result = await fetch(novelUrl);
const body = await result.text();
let loadedCheerio = parseHTML(body);
novel.name = loadedCheerio(".series-name").text();
const background =
loadedCheerio(".series-cover > .a6-ratio > div").attr("style") || "";
loadedCheerio(".series-cover > .a6-ratio > div").attr("style") ||
"";
const novelCover = background.substring(
background.indexOf("http"),
background.length - 2
);
novel.cover = novelCover
? isUrlAbsolute(novelCover)
? novelCover
: this.site + novelCover
: "";
novel.summary = loadedCheerio(".summary-content").text().trim();
novel.author = loadedCheerio(
"#mainpart > div:nth-child(2) > div > div:nth-child(1) > section > main > div.top-part > div > div.col-12.col-md-9 > div.series-information > div:nth-child(2) > span.info-value > a"
)
.text()
.trim();
novel.genres = loadedCheerio(".series-gernes")
.text()
.trim()
@@ -97,21 +103,21 @@ class HakoPlugin implements Plugin.PluginBase {
.split("\n")
.filter((e) => e.trim())
.join(", ");
novel.status = loadedCheerio(
"#mainpart > div:nth-child(2) > div > div:nth-child(1) > section > main > div.top-part > div > div.col-12.col-md-9 > div.series-information > div:nth-child(4) > span.info-value > a"
)
.text()
.trim();
const chapters: Plugin.ChapterItem[] = [];
loadedCheerio(".list-chapters li").each((index, ele) => {
let chapterUrl = loadedCheerio(ele).find("a").attr("href");
if (chapterUrl && !isUrlAbsolute(chapterUrl)) {
chapterUrl = this.site + chapterUrl;
}
if (chapterUrl) {
const chapterName = loadedCheerio(ele)
.find(".chapter-name")
@@ -120,13 +126,13 @@ class HakoPlugin implements Plugin.PluginBase {
const releaseTime = loadedCheerio(ele)
.find(".chapter-time")
.text();
const chapter = {
name: chapterName,
releaseTime: releaseTime,
url: chapterUrl,
};
chapters.push(chapter);
}
});
@@ -143,7 +149,10 @@ class HakoPlugin implements Plugin.PluginBase {
return chapterText;
}
async searchNovels(searchTerm: string, pageNo?: number | undefined): Promise<Plugin.NovelItem[]> {
async searchNovels(
searchTerm: string,
pageNo?: number | undefined
): Promise<Plugin.NovelItem[]> {
const url = this.site + "/tim-kiem?keywords=" + searchTerm;
const result = await fetch(url);
const body = await result.text();