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
This commit is contained in:
Adam Kemish
2025-02-01 10:08:51 +08:00
committed by GitHub
parent 0e37fbc567
commit 73ee4ffe62
3 changed files with 38 additions and 9 deletions
+3 -1
View File
@@ -197,7 +197,9 @@
"id": "zetroTL", "id": "zetroTL",
"sourceSite": "https://zetrotranslation.com/", "sourceSite": "https://zetrotranslation.com/",
"sourceName": "Zetro Translation", "sourceName": "Zetro Translation",
"options": {} "options": {
"hasLocked": true
}
}, },
{ {
"id": "webnoveloku", "id": "webnoveloku",
+22 -3
View File
@@ -5,6 +5,7 @@ import { Cheerio, AnyNode, CheerioAPI, load as parseHTML } from 'cheerio';
import { defaultCover } from '@libs/defaultCover'; import { defaultCover } from '@libs/defaultCover';
import { NovelStatus } from '@libs/novelStatus'; import { NovelStatus } from '@libs/novelStatus';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import { storage } from '@libs/storage';
const includesAny = (str: string, keywords: string[]) => const includesAny = (str: string, keywords: string[]) =>
new RegExp(keywords.join('|')).test(str); new RegExp(keywords.join('|')).test(str);
@@ -15,6 +16,7 @@ type MadaraOptions = {
orderBy?: string; orderBy?: string;
versionIncrements?: number; versionIncrements?: number;
customJs?: string; customJs?: string;
hasLocked?: boolean;
}; };
export type MadaraMetadata = { export type MadaraMetadata = {
@@ -34,15 +36,28 @@ class MadaraPlugin implements Plugin.PluginBase {
options?: MadaraOptions; options?: MadaraOptions;
filters?: Filters | undefined; filters?: Filters | undefined;
hideLocked = storage.get('hideLocked');
pluginSettings?: Record<string, any>;
constructor(metadata: MadaraMetadata) { constructor(metadata: MadaraMetadata) {
this.id = metadata.id; this.id = metadata.id;
this.name = metadata.sourceName; this.name = metadata.sourceName;
this.icon = `multisrc/madara/${metadata.id.toLowerCase()}/icon.png`; this.icon = `multisrc/madara/${metadata.id.toLowerCase()}/icon.png`;
this.site = metadata.sourceSite; this.site = metadata.sourceSite;
const versionIncrements = metadata.options?.versionIncrements || 0; const versionIncrements = metadata.options?.versionIncrements || 0;
this.version = `1.0.${5 + versionIncrements}`; this.version = `1.0.${6 + versionIncrements}`;
this.options = metadata.options; this.options = metadata.options;
this.filters = metadata.filters; this.filters = metadata.filters;
if (this.options?.hasLocked) {
this.pluginSettings = {
hideLocked: {
value: '',
label: 'Hide locked chapters',
type: 'Switch',
},
};
}
} }
translateDragontea(text: Cheerio<AnyNode>): Cheerio<AnyNode> { translateDragontea(text: Cheerio<AnyNode>): Cheerio<AnyNode> {
@@ -270,7 +285,11 @@ class MadaraPlugin implements Plugin.PluginBase {
const totalChapters = loadedCheerio('.wp-manga-chapter').length; const totalChapters = loadedCheerio('.wp-manga-chapter').length;
loadedCheerio('.wp-manga-chapter').each((chapterIndex, element) => { 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) let releaseDate = loadedCheerio(element)
.find('span.chapter-release-date') .find('span.chapter-release-date')
@@ -285,7 +304,7 @@ class MadaraPlugin implements Plugin.PluginBase {
const chapterUrl = loadedCheerio(element).find('a').attr('href') || ''; const chapterUrl = loadedCheerio(element).find('a').attr('href') || '';
if (chapterUrl && chapterUrl != '#') { if (chapterUrl && chapterUrl != '#' && !(locked && this.hideLocked)) {
chapters.push({ chapters.push({
name: chapterName, name: chapterName,
path: chapterUrl.replace(/https?:\/\/.*?\//, '/'), path: chapterUrl.replace(/https?:\/\/.*?\//, '/'),
+13 -5
View File
@@ -2,11 +2,12 @@ import { CheerioAPI, load as parseHTML } from 'cheerio';
import { fetchApi } from '@libs/fetch'; import { fetchApi } from '@libs/fetch';
import { Filters, FilterTypes } from '@libs/filterInputs'; import { Filters, FilterTypes } from '@libs/filterInputs';
import { Plugin } from '@typings/plugin'; import { Plugin } from '@typings/plugin';
import { storage } from '@libs/storage';
class Webnovel implements Plugin.PluginBase { class Webnovel implements Plugin.PluginBase {
id = 'webnovel'; id = 'webnovel';
name = 'Webnovel'; name = 'Webnovel';
version = '1.0.1'; version = '1.0.2';
icon = 'src/en/webnovel/icon.png'; icon = 'src/en/webnovel/icon.png';
site = 'https://www.webnovel.com'; site = 'https://www.webnovel.com';
headers = { headers = {
@@ -18,6 +19,14 @@ class Webnovel implements Plugin.PluginBase {
'referrer': this.site, 'referrer': this.site,
}, },
}; };
hideLocked = storage.get('hideLocked');
pluginSettings = {
hideLocked: {
value: '',
label: 'Hide locked chapters',
type: 'Switch',
},
};
async parseNovels( async parseNovels(
loadedCheerio: CheerioAPI, loadedCheerio: CheerioAPI,
@@ -143,12 +152,11 @@ class Webnovel implements Plugin.PluginBase {
(loadedCheerio(ele_c).find('a').attr('title')?.trim() || (loadedCheerio(ele_c).find('a').attr('title')?.trim() ||
'No Title Found'); 'No Title Found');
const chapterPath = loadedCheerio(ele_c).find('a').attr('href'); 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({ chapters.push({
name: loadedCheerio(ele_c).find('svg').length name: locked ? `${chapterName} 🔒` : chapterName,
? `${chapterName} 🔒`
: chapterName,
path: chapterPath, path: chapterPath,
}); });
} }