From 73ee4ffe62d4c1d0aa75b9095298a8c6caeb37ea Mon Sep 17 00:00:00 2001 From: Adam Kemish <49228220+Soopyboo32@users.noreply.github.com> Date: Sat, 1 Feb 2025 10:08:51 +0800 Subject: [PATCH] Add lock icon to madara theme locked chapters & setting to zetro translation to hide locked chapters (#1406) * Add lock icon to madara theme locked chapters & setting to zetro translation to hide locked chapters * Increment version number * Fix storage * Add hide locked chapters toggle to webnovel plugin * Fix version number from rebase --- scripts/multisrc/madara/sources.json | 4 +++- scripts/multisrc/madara/template.ts | 25 ++++++++++++++++++++++--- src/plugins/english/webnovel.ts | 18 +++++++++++++----- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/scripts/multisrc/madara/sources.json b/scripts/multisrc/madara/sources.json index e49a086..32cf806 100644 --- a/scripts/multisrc/madara/sources.json +++ b/scripts/multisrc/madara/sources.json @@ -197,7 +197,9 @@ "id": "zetroTL", "sourceSite": "https://zetrotranslation.com/", "sourceName": "Zetro Translation", - "options": {} + "options": { + "hasLocked": true + } }, { "id": "webnoveloku", diff --git a/scripts/multisrc/madara/template.ts b/scripts/multisrc/madara/template.ts index 74a4b09..316db5f 100644 --- a/scripts/multisrc/madara/template.ts +++ b/scripts/multisrc/madara/template.ts @@ -5,6 +5,7 @@ import { Cheerio, AnyNode, CheerioAPI, load as parseHTML } from 'cheerio'; import { defaultCover } from '@libs/defaultCover'; import { NovelStatus } from '@libs/novelStatus'; import dayjs from 'dayjs'; +import { storage } from '@libs/storage'; const includesAny = (str: string, keywords: string[]) => new RegExp(keywords.join('|')).test(str); @@ -15,6 +16,7 @@ type MadaraOptions = { orderBy?: string; versionIncrements?: number; customJs?: string; + hasLocked?: boolean; }; export type MadaraMetadata = { @@ -34,15 +36,28 @@ class MadaraPlugin implements Plugin.PluginBase { options?: MadaraOptions; filters?: Filters | undefined; + hideLocked = storage.get('hideLocked'); + pluginSettings?: Record; + constructor(metadata: MadaraMetadata) { this.id = metadata.id; this.name = metadata.sourceName; this.icon = `multisrc/madara/${metadata.id.toLowerCase()}/icon.png`; this.site = metadata.sourceSite; const versionIncrements = metadata.options?.versionIncrements || 0; - this.version = `1.0.${5 + versionIncrements}`; + this.version = `1.0.${6 + versionIncrements}`; this.options = metadata.options; this.filters = metadata.filters; + + if (this.options?.hasLocked) { + this.pluginSettings = { + hideLocked: { + value: '', + label: 'Hide locked chapters', + type: 'Switch', + }, + }; + } } translateDragontea(text: Cheerio): Cheerio { @@ -270,7 +285,11 @@ class MadaraPlugin implements Plugin.PluginBase { const totalChapters = loadedCheerio('.wp-manga-chapter').length; loadedCheerio('.wp-manga-chapter').each((chapterIndex, element) => { - const chapterName = loadedCheerio(element).find('a').text().trim(); + let chapterName = loadedCheerio(element).find('a').text().trim(); + const locked = element.attribs['class'].includes('premium-block'); + if (locked) { + chapterName = '🔒 ' + chapterName; + } let releaseDate = loadedCheerio(element) .find('span.chapter-release-date') @@ -285,7 +304,7 @@ class MadaraPlugin implements Plugin.PluginBase { const chapterUrl = loadedCheerio(element).find('a').attr('href') || ''; - if (chapterUrl && chapterUrl != '#') { + if (chapterUrl && chapterUrl != '#' && !(locked && this.hideLocked)) { chapters.push({ name: chapterName, path: chapterUrl.replace(/https?:\/\/.*?\//, '/'), diff --git a/src/plugins/english/webnovel.ts b/src/plugins/english/webnovel.ts index dad209e..e849013 100644 --- a/src/plugins/english/webnovel.ts +++ b/src/plugins/english/webnovel.ts @@ -2,11 +2,12 @@ import { CheerioAPI, load as parseHTML } from 'cheerio'; import { fetchApi } from '@libs/fetch'; import { Filters, FilterTypes } from '@libs/filterInputs'; import { Plugin } from '@typings/plugin'; +import { storage } from '@libs/storage'; class Webnovel implements Plugin.PluginBase { id = 'webnovel'; name = 'Webnovel'; - version = '1.0.1'; + version = '1.0.2'; icon = 'src/en/webnovel/icon.png'; site = 'https://www.webnovel.com'; headers = { @@ -18,6 +19,14 @@ class Webnovel implements Plugin.PluginBase { 'referrer': this.site, }, }; + hideLocked = storage.get('hideLocked'); + pluginSettings = { + hideLocked: { + value: '', + label: 'Hide locked chapters', + type: 'Switch', + }, + }; async parseNovels( loadedCheerio: CheerioAPI, @@ -143,12 +152,11 @@ class Webnovel implements Plugin.PluginBase { (loadedCheerio(ele_c).find('a').attr('title')?.trim() || 'No Title Found'); const chapterPath = loadedCheerio(ele_c).find('a').attr('href'); + const locked = loadedCheerio(ele_c).find('svg').length; - if (chapterPath) { + if (chapterPath && !(locked && this.hideLocked)) { chapters.push({ - name: loadedCheerio(ele_c).find('svg').length - ? `${chapterName} 🔒` - : chapterName, + name: locked ? `${chapterName} 🔒` : chapterName, path: chapterPath, }); }