选集屏蔽增加相反模式
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
import { getAuthInfoFromBrowserCookie, clearAuthCookie } from './auth';
|
||||
import { normalizeEpisodeFilterConfig } from './episode-filter';
|
||||
import { MangaReadRecord, MangaShelfItem } from './manga.types';
|
||||
import { DanmakuFilterConfig, EpisodeFilterConfig,SkipConfig } from './types';
|
||||
|
||||
@@ -2643,7 +2644,7 @@ export async function getEpisodeFilterConfig(): Promise<EpisodeFilterConfig | nu
|
||||
try {
|
||||
const raw = localStorage.getItem('moontv_episode_filter_config');
|
||||
if (!raw) return null;
|
||||
return JSON.parse(raw) as EpisodeFilterConfig;
|
||||
return normalizeEpisodeFilterConfig(JSON.parse(raw) as EpisodeFilterConfig);
|
||||
} catch (err) {
|
||||
console.error('读取集数过滤配置失败:', err);
|
||||
return null;
|
||||
@@ -2662,10 +2663,11 @@ export async function saveEpisodeFilterConfig(
|
||||
}
|
||||
|
||||
try {
|
||||
localStorage.setItem('moontv_episode_filter_config', JSON.stringify(config));
|
||||
const normalizedConfig = normalizeEpisodeFilterConfig(config);
|
||||
localStorage.setItem('moontv_episode_filter_config', JSON.stringify(normalizedConfig));
|
||||
window.dispatchEvent(
|
||||
new CustomEvent('episodeFilterConfigUpdated', {
|
||||
detail: config,
|
||||
detail: normalizedConfig,
|
||||
})
|
||||
);
|
||||
} catch (err) {
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import { EpisodeFilterConfig } from './types';
|
||||
|
||||
export function normalizeEpisodeFilterConfig(
|
||||
config?: EpisodeFilterConfig | null
|
||||
): EpisodeFilterConfig {
|
||||
return {
|
||||
rules: config?.rules ?? [],
|
||||
reverseMode: config?.reverseMode ?? false,
|
||||
};
|
||||
}
|
||||
|
||||
export function doesEpisodeTitleMatchFilterRules(
|
||||
title: string,
|
||||
config?: EpisodeFilterConfig | null
|
||||
): boolean {
|
||||
const normalizedConfig = normalizeEpisodeFilterConfig(config);
|
||||
|
||||
for (const rule of normalizedConfig.rules) {
|
||||
if (!rule.enabled) continue;
|
||||
|
||||
try {
|
||||
if (rule.type === 'normal' && title.includes(rule.keyword)) {
|
||||
return true;
|
||||
}
|
||||
if (rule.type === 'regex' && new RegExp(rule.keyword).test(title)) {
|
||||
return true;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('集数过滤规则错误:', e);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isEpisodeHiddenByFilter(
|
||||
title: string,
|
||||
config?: EpisodeFilterConfig | null
|
||||
): boolean {
|
||||
const normalizedConfig = normalizeEpisodeFilterConfig(config);
|
||||
if (normalizedConfig.rules.length === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const isMatched = doesEpisodeTitleMatchFilterRules(title, normalizedConfig);
|
||||
return normalizedConfig.reverseMode ? !isMatched : isMatched;
|
||||
}
|
||||
@@ -253,6 +253,7 @@ export interface EpisodeFilterRule {
|
||||
// 集数过滤配置数据结构
|
||||
export interface EpisodeFilterConfig {
|
||||
rules: EpisodeFilterRule[]; // 过滤规则列表
|
||||
reverseMode?: boolean; // 反向模式:开启后仅显示符合规则的集数
|
||||
}
|
||||
|
||||
// 通知类型枚举
|
||||
|
||||
Reference in New Issue
Block a user