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
+119 -107
View File
@@ -1,6 +1,6 @@
import { CheerioAPI, load as parseHTML } from "cheerio";
import { fetchApi, fetchFile } from "@libs/fetch";
import { Filter, FilterInputs } from "@libs/filterInputs";
import { FilterTypes, Filters } from "@libs/filterInputs";
import { Plugin } from "@typings/plugin";
import { showToast } from "@libs/showToast";
import { defaultCover } from "@libs/defaultCover";
@@ -15,27 +15,30 @@ class TuNovelaLigera implements Plugin.PluginBase {
userAgent = "";
cookieString = "";
async popularNovels(pageNo: number, {filters}: Plugin.PopularNovelsOptions): Promise<Plugin.NovelItem[]> {
async popularNovels(
pageNo: number,
{ filters }: Plugin.PopularNovelsOptions<typeof this.filters>
): Promise<Plugin.NovelItem[]> {
let link = `${this.site}`;
link += (filters?.genres ? `genero/` + filters.genres : "novelas");
link += filters.genres ? `genero/` + filters.genres : "novelas";
link += `/page/${pageNo}`;
link += (filters?.order ? filters.order : "?m_orderby=rating")
link += filters.order;
const headers = new Headers();
if(this.cookieString){
if (this.cookieString) {
headers.append("cookie", this.cookieString);
}
const result = await fetchApi(link, {headers})
const result = await fetchApi(link, { headers });
const body = await result.text();
const loadedCheerio = parseHTML(body);
const novels: Plugin.NovelItem[] = [];
loadedCheerio(".page-item-detail").each((i,el) => {
loadedCheerio(".page-item-detail").each((i, el) => {
const novelName = loadedCheerio(el).find(".h5 > a").text();
const novelCover = loadedCheerio(el).find("img").attr("src");
const novelUrl = loadedCheerio(el).find(".h5 > a").attr("href");
@@ -51,15 +54,15 @@ class TuNovelaLigera implements Plugin.PluginBase {
});
return novels;
};
}
async parseNovelAndChapters(novelUrl: string): Promise<Plugin.SourceNovel> {
const url = novelUrl;
const headers = new Headers();
if(this.cookieString){
if (this.cookieString) {
headers.append("cookie", this.cookieString);
}
const result = await fetchApi(url, {headers});
const result = await fetchApi(url, { headers });
const body = await result.text();
let loadedCheerio = parseHTML(body);
@@ -78,7 +81,7 @@ class TuNovelaLigera implements Plugin.PluginBase {
novel.cover =
novelCover.attr("data-src") ||
novelCover.attr("src") ||
novelCover.attr('data-cfsrc') ||
novelCover.attr("data-cfsrc") ||
defaultCover;
loadedCheerio(".post-content_item").each(function () {
@@ -114,14 +117,14 @@ class TuNovelaLigera implements Plugin.PluginBase {
const delay = (ms: number) => new Promise((res) => setTimeout(res, ms));
let lastPage = 1;
lastPage = +loadedCheerio('.lcp_paginator li:last').prev().text();
lastPage = +loadedCheerio(".lcp_paginator li:last").prev().text();
const getChapters = async () => {
const n = url.split('/');
const n = url.split("/");
const novelName = n[4];
showToast('Cargando desde Archivo...');
showToast("Cargando desde Archivo...");
const formData = new FormData()
const formData = new FormData();
formData.append("action", "madara_load_more");
formData.append("page", "0");
formData.append("template", "html/loop/content");
@@ -131,24 +134,25 @@ class TuNovelaLigera implements Plugin.PluginBase {
const result = await fetchApi(
`${this.site}wp-admin/admin-ajax.php`,
{
method: "POST",
body: formData,
headers
},
method: "POST",
body: formData,
headers,
}
);
const text = await result.text();
loadedCheerio = parseHTML(text);
loadedCheerio('.heading').each((i, el) => {
loadedCheerio(".heading").each((i, el) => {
const chapterName = loadedCheerio(el)
.text()
.replace(/[\t\n]/g, '')
.trim();
.text()
.replace(/[\t\n]/g, "")
.trim();
const releaseDate = null;
const chapterUrl = loadedCheerio(el).find('a').attr('href') || "";
chapter.push({
const chapterUrl =
loadedCheerio(el).find("a").attr("href") || "";
chapter.push({
name: chapterName,
url: chapterUrl,
releaseTime: releaseDate,
@@ -156,56 +160,56 @@ class TuNovelaLigera implements Plugin.PluginBase {
});
return chapter.reverse();
};
const getPageChapters = async () => {
for (let i = 1; i <= lastPage; i++) {
const chaptersUrl = `${novelUrl}?lcp_page0=${i}`;
showToast(`Cargando desde la página ${i}/${lastPage}...`);
const result = await fetchApi(chaptersUrl, {headers});
const result = await fetchApi(chaptersUrl, { headers });
const chaptersHTML = await result.text();
let chapterCheerio = parseHTML(chaptersHTML);
chapterCheerio('.lcp_catlist li').each((i, el) => {
chapterCheerio(".lcp_catlist li").each((i, el) => {
const chapterName = chapterCheerio(el)
.find('a')
.find("a")
.text()
.replace(/[\t\n]/g, '')
.replace(/[\t\n]/g, "")
.trim();
const releaseDate = chapterCheerio(el)
.find('span')
.find("span")
.text()
.trim();
const chapterUrl =
chapterCheerio(el).find('a').attr('href') || "";
chapterCheerio(el).find("a").attr("href") || "";
chapter.push({
name: chapterName,
releaseTime: releaseDate,
url: chapterUrl,
chapter.push({
name: chapterName,
releaseTime: releaseDate,
url: chapterUrl,
});
});
await delay(1000);
}
return chapter.reverse();
}
};
novel.chapters = await getChapters();
if (!novel.chapters.length) {
showToast('¡Archivo no encontrado!');
showToast("¡Archivo no encontrado!");
await delay(1000);
novel.chapters = await getPageChapters();
}
return novel;
}
async parseChapter(chapterUrl: string): Promise<string> {
const headers = new Headers();
if(this.cookieString){
if (this.cookieString) {
headers.append("cookie", this.cookieString);
}
const result = await fetchApi(chapterUrl);
@@ -213,13 +217,17 @@ class TuNovelaLigera implements Plugin.PluginBase {
const loadedCheerio = parseHTML(body);
loadedCheerio("#hola_siguiente").next().find('div').remove();
const chapterText = loadedCheerio("#hola_siguiente").next().html() || "";
loadedCheerio("#hola_siguiente").next().find("div").remove();
const chapterText =
loadedCheerio("#hola_siguiente").next().html() || "";
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}?s=${searchTerm}&post_type=wp-manga`;
const result = await fetchApi(url);
@@ -238,136 +246,140 @@ class TuNovelaLigera implements Plugin.PluginBase {
name: novelName,
url: novelUrl,
cover: novelCover,
});
});
});
return novels;
};
}
async fetchImage(url: string): Promise<string | undefined> {
return await fetchFile(url);
}
filters = [
{
key: "order",
filters = {
order: {
value: "?m_orderby=rating",
label: "Ordenado por",
values: [
options: [
{ label: "Lo mas reciente", value: "?m_orderby=latest" },
{ label: "A-Z", value: "?m_orderby=alphabet" },
{ label: "Clasificación", value: "?m_orderby=rating" },
{ label: "Trending", value: "?m_orderby=trending" },
{ label: "Mas visto", value: "?m_orderby=views" },
{ label: "Nuevo", value: "?m_orderby=new-manga" },
],
inputType: FilterInputs.Picker,
type: FilterTypes.Picker,
},
{
key: "genres",
genres: {
value: "",
label: "Generos",
values: [
options: [
{ label: "None", value: "" },
{ label: "Acción", value: "accion" },
{ label: "Adulto", value: "adulto" },
{ label: "Artes Marciales", value: "artes-marciales" },
{ label: "Aventura", value: "aventura" },
{ label: "Ciencia Ficción", value: "ciencia-ficcion" },
{ label: "Comedia", value: "comedia" },
{ label: "Deportes", value: "deportes" },
{ label: "Drama", value: "drama" },
{ label: "Eastern Fantasy", value: "eastern-fantasy" },
{ label: "Ecchi", value: "ecchi" },
{ label: "FanFiction", value: "fan-fiction" },
{ label: "Fantasía", value: "fantasia" },
{ label: "Fantasía oriental", value: "fantasia-oriental" },
{ label: "Ficción Romántica", value: "ficcion-romantica" },
{ label: "Gender Bender", value: "gender-bender" },
{ label: "Harem", value: "harem" },
{ label: "Histórico", value: "historico" },
{ label: "Horror", value: "horror" },
{ label: "Josei", value: "josei" },
{ label: "Maduro", value: "maduro" },
{ label: "Mecha", value: "mecha" },
{ label: "Misterio", value: "misterio" },
{ label: "Novela China", value: "novela-china" },
{ label: "Novela FanFiction", value: "novela-fanfiction" },
{ label: "Novela Japonesa", value: "novela-japonesa" },
{ label: "Novela Koreana", value: "novela-koreana" },
{ label: "Novela ligera", value: "novela-ligera" },
{ label: "Novela original", value: "novela-original" },
{ label: "Novela Web", value: "web-novel" },
{ label: "Psicológico", value: "psicologico" },
{ label: "Realismo Mágico", value: "realismo-magico" },
{ label: "Recuento de vida", value: "recuento-de-vida" },
{ label: "Romance", value: "romance" },
{ label: "Romance contemporáneo", value: "romance-contemporaneo" },
{
label: "Romance contemporáneo",
value: "romance-contemporaneo",
},
{ label: "Romance Moderno", value: "romance-moderno" },
{ label: "Seinen", value: "seinen" },
{ label: "Shoujo", value: "shoujo" },
{ label: "Shounen", value: "shounen" },
{ label: "Sobrenatural", value: "sobrenatural" },
{ label: "Tragedia", value: "tragedia" },
{ label: "Vampiros", value: "vampiros" },
{ label: "Vida Escolar", value: "vida-escolar" },
{ label: "Western Fantasy", value: "western-fantasy" },
{ label: "Wuxia", value: "wuxia" },
{ label: "Xianxia", value: "xianxia" },
{ label: "Xuanhuan", value: "xuanhuan" },
{ label: "Yaoi", value: "yaoi" },
],
inputType: FilterInputs.Picker,
type: FilterTypes.Picker,
},
];
} satisfies Filters;
}
export default new TuNovelaLigera();