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",
"sourceSite": "https://zetrotranslation.com/",
"sourceName": "Zetro Translation",
"options": {}
"options": {
"hasLocked": true
}
},
{
"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 { 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<string, any>;
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<AnyNode>): Cheerio<AnyNode> {
@@ -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?:\/\/.*?\//, '/'),
+13 -5
View File
@@ -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,
});
}