Skip to content

Commit c346702

Browse files
feat(bilibili-block): 支持通过 Tampermonkey 菜单配置屏蔽规则
- 使用 GM_getValue/GM_setValue 持久化 FILTER_BLOCK_UIDS 和 MIN_FOLLOWER - 注册 3 个菜单命令:设置屏蔽UID列表、设置最低粉丝数、查看当前配置 - meta.ts 添加 GM_getValue/GM_setValue/GM_registerMenuCommand 权限 - 版本号从 2.8 升级到 2.9
1 parent 0fbd379 commit c346702

2 files changed

Lines changed: 79 additions & 6 deletions

File tree

src/bilibili-block/index.ts

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,82 @@
11
export {};
22

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+
376
// 定义需要筛选屏蔽的视频卡片类名
477
const FILTER_CLASSES = ['.bili-feed-card'];
578
// 定义需要直接直接屏蔽的直播类名
679
const FILTER_BLOCK_CLASSES = ['.floor-single-card'];
7-
// 定义需要直接屏蔽的作者uid
8-
const FILTER_BLOCK_UIDS = [113560378];
9-
// 定义需要屏蔽的最小的follower数
10-
const MIN_FOLLOWER = 2000;
1180
// 定义接口前缀
1281
const API_USERDATA = 'https://api.bilibili.com/x/relation/stat?vmid=';
1382

src/bilibili-block/meta.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default defineConfig({
99
en: "Block Bilibili's marketing videos and promotional videos",
1010
},
1111
namespace: 'http://tampermonkey.net/',
12-
version: '2.8',
12+
version: '2.9',
1313
description: {
1414
'': '屏蔽部分B站(bilibili)主页推荐的视频卡片,屏蔽up主粉丝少于一定数量的,屏蔽直播与右侧推广,屏蔽带广告标签的',
1515
'zh-CN':
@@ -24,7 +24,11 @@ export default defineConfig({
2424
'https://www.bilibili.com/?spm_id_from=*',
2525
],
2626
icon: 'https://www.bilibili.com/favicon.ico',
27-
grant: 'none',
27+
grant: [
28+
'GM_getValue',
29+
'GM_setValue',
30+
'GM_registerMenuCommand',
31+
],
2832
license: 'GNU General Public License v3.0',
2933
downloadURL:
3034
'https://update.greasyfork.org/scripts/467384/%F0%9F%9B%A0%EF%B8%8F%E5%B1%8F%E8%94%BDB%E7%AB%99%E8%90%A5%E9%94%80%E8%A7%86%E9%A2%91.user.js',

0 commit comments

Comments
 (0)