|
1 | 1 | export {}; |
2 | 2 |
|
| 3 | +// ─── GM API 类型声明 ────────────────────────────────────────── |
| 4 | +declare function GM_getValue<T>(key: string, defaultValue: T): T; |
| 5 | +declare function GM_setValue(key: string, value: unknown): void; |
| 6 | +declare function GM_registerMenuCommand( |
| 7 | + name: string, |
| 8 | + callback: () => void |
| 9 | +): void; |
| 10 | + |
| 11 | +// ─── 配置管理 ───────────────────────────────────────────────── |
| 12 | + |
| 13 | +// 默认值 |
| 14 | +const DEFAULT_FILTER_BLOCK_UIDS = [113560378]; |
| 15 | +const DEFAULT_MIN_FOLLOWER = 2000; |
| 16 | + |
| 17 | +// 从 GM 存储读取配置(首次使用时自动写入默认值) |
| 18 | +let FILTER_BLOCK_UIDS: number[] = GM_getValue( |
| 19 | + 'FILTER_BLOCK_UIDS', |
| 20 | + DEFAULT_FILTER_BLOCK_UIDS |
| 21 | +); |
| 22 | +let MIN_FOLLOWER: number = GM_getValue( |
| 23 | + 'MIN_FOLLOWER', |
| 24 | + DEFAULT_MIN_FOLLOWER |
| 25 | +); |
| 26 | + |
| 27 | +// ─── 配置菜单 ───────────────────────────────────────────────── |
| 28 | + |
| 29 | +GM_registerMenuCommand('⚙️ 设置屏蔽UID列表', () => { |
| 30 | + const current = FILTER_BLOCK_UIDS.join(', '); |
| 31 | + const input = prompt( |
| 32 | + '请输入需要屏蔽的UID列表(多个UID用英文逗号分隔):\n\n例如:113560378, 123456789', |
| 33 | + current |
| 34 | + ); |
| 35 | + if (input === null) return; // 用户取消 |
| 36 | + |
| 37 | + const parsed = input |
| 38 | + .split(',') |
| 39 | + .map((s) => s.trim()) |
| 40 | + .filter((s) => /^\d+$/.test(s)) |
| 41 | + .map(Number); |
| 42 | + |
| 43 | + FILTER_BLOCK_UIDS = parsed; |
| 44 | + GM_setValue('FILTER_BLOCK_UIDS', parsed); |
| 45 | + alert(`✅ 已保存屏蔽UID列表(${parsed.length} 个UID)\n刷新页面后生效`); |
| 46 | +}); |
| 47 | + |
| 48 | +GM_registerMenuCommand('⚙️ 设置最低粉丝数', () => { |
| 49 | + const input = prompt( |
| 50 | + '请输入最低粉丝数(低于此数量的UP主视频将被屏蔽):', |
| 51 | + String(MIN_FOLLOWER) |
| 52 | + ); |
| 53 | + if (input === null) return; // 用户取消 |
| 54 | + |
| 55 | + const parsed = parseInt(input, 10); |
| 56 | + if (isNaN(parsed) || parsed < 0) { |
| 57 | + alert('❌ 请输入有效的非负整数'); |
| 58 | + return; |
| 59 | + } |
| 60 | + |
| 61 | + MIN_FOLLOWER = parsed; |
| 62 | + GM_setValue('MIN_FOLLOWER', parsed); |
| 63 | + alert(`✅ 已保存最低粉丝数:${parsed}\n刷新页面后生效`); |
| 64 | +}); |
| 65 | + |
| 66 | +GM_registerMenuCommand('📋 查看当前配置', () => { |
| 67 | + alert( |
| 68 | + `当前配置:\n\n` + |
| 69 | + `屏蔽UID列表:${FILTER_BLOCK_UIDS.length > 0 ? FILTER_BLOCK_UIDS.join(', ') : '(空)'}\n` + |
| 70 | + `最低粉丝数:${MIN_FOLLOWER}` |
| 71 | + ); |
| 72 | +}); |
| 73 | + |
| 74 | +// ─── 脚本逻辑 ───────────────────────────────────────────────── |
| 75 | + |
3 | 76 | // 定义需要筛选屏蔽的视频卡片类名 |
4 | 77 | const FILTER_CLASSES = ['.bili-feed-card']; |
5 | 78 | // 定义需要直接直接屏蔽的直播类名 |
6 | 79 | const FILTER_BLOCK_CLASSES = ['.floor-single-card']; |
7 | | -// 定义需要直接屏蔽的作者uid |
8 | | -const FILTER_BLOCK_UIDS = [113560378]; |
9 | | -// 定义需要屏蔽的最小的follower数 |
10 | | -const MIN_FOLLOWER = 2000; |
11 | 80 | // 定义接口前缀 |
12 | 81 | const API_USERDATA = 'https://api.bilibili.com/x/relation/stat?vmid='; |
13 | 82 |
|
|
0 commit comments