Skip to content

Commit 7dafc96

Browse files
committed
feat: 更新中文和英文语言包,添加新的功能描述和设置选项
1 parent 91dc940 commit 7dafc96

File tree

8 files changed

+357
-19
lines changed

8 files changed

+357
-19
lines changed

_locales/en/messages.json

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
{
2+
"extensionName": {
3+
"message": "VideoAdGuard",
4+
"description": "Extension name"
5+
},
6+
"extensionDescription": {
7+
"message": "Based on large language models, automatically detects embedded/sponsored ads in Bilibili videos. When videos enter irrelevant sponsored content, it can automatically skip ads.",
8+
"description": "Extension description"
9+
},
10+
"settingsTitle": {
11+
"message": "Bilibili Ad Detection Settings",
12+
"description": "Settings page title"
13+
},
14+
"enableExtension": {
15+
"message": "Enable Extension",
16+
"description": "Enable extension checkbox label"
17+
},
18+
"autoSkipAd": {
19+
"message": "Auto Skip Ads",
20+
"description": "Auto skip ads checkbox label"
21+
},
22+
"restrictedMode": {
23+
"message": "Restricted Mode",
24+
"description": "Restricted mode checkbox label"
25+
},
26+
"localOllama": {
27+
"message": "Connect to Local Ollama",
28+
"description": "Local Ollama checkbox label"
29+
},
30+
"apiUrl": {
31+
"message": "API URL:",
32+
"description": "API URL input label"
33+
},
34+
"apiUrlPlaceholder": {
35+
"message": "Please enter API URL",
36+
"description": "API URL input placeholder"
37+
},
38+
"apiKey": {
39+
"message": "API Key:",
40+
"description": "API key input label"
41+
},
42+
"apiKeyPlaceholder": {
43+
"message": "Please enter API key",
44+
"description": "API key input placeholder"
45+
},
46+
"model": {
47+
"message": "Model Name:",
48+
"description": "Model name input label"
49+
},
50+
"modelPlaceholder": {
51+
"message": "Please enter model name",
52+
"description": "Model name input placeholder"
53+
},
54+
"enableAudioTranscription": {
55+
"message": "Enable Speech Recognition",
56+
"description": "Enable audio transcription checkbox label"
57+
},
58+
"groqApiKey": {
59+
"message": "Groq API Key:",
60+
"description": "Groq API key input label"
61+
},
62+
"groqApiKeyPlaceholder": {
63+
"message": "Please enter Groq API key",
64+
"description": "Groq API key input placeholder"
65+
},
66+
"enableWhitelist": {
67+
"message": "Enable UP Whitelist",
68+
"description": "Enable whitelist checkbox label"
69+
},
70+
"upUidPlaceholder": {
71+
"message": "Enter UP UID",
72+
"description": "UP UID input placeholder"
73+
},
74+
"addToWhitelist": {
75+
"message": "Add to Whitelist",
76+
"description": "Add to whitelist button text"
77+
},
78+
"removeFromWhitelist": {
79+
"message": "Remove",
80+
"description": "Remove from whitelist button text"
81+
},
82+
"register": {
83+
"message": "Register",
84+
"description": "Register link text"
85+
},
86+
"currentNotOnBilibili": {
87+
"message": "Not currently on Bilibili video page",
88+
"description": "Message when not on Bilibili page"
89+
},
90+
"extensionNotLoaded": {
91+
"message": "Extension not fully loaded, please wait or refresh",
92+
"description": "Message when extension is not loaded"
93+
},
94+
"noAdDetected": {
95+
"message": "No ad information detected",
96+
"description": "Message when no ads are detected"
97+
},
98+
"pleaseEnterUid": {
99+
"message": "Please enter UP UID",
100+
"description": "Error message for empty UID"
101+
},
102+
"addedToWhitelist": {
103+
"message": "Added to whitelist",
104+
"description": "Success message for adding to whitelist"
105+
},
106+
"alreadyInWhitelist": {
107+
"message": "This UP is already in the whitelist",
108+
"description": "Error message when UP is already whitelisted"
109+
},
110+
"addFailed": {
111+
"message": "Add failed: ",
112+
"description": "Error message prefix for add failure"
113+
},
114+
"removedFromWhitelist": {
115+
"message": "Removed from whitelist",
116+
"description": "Success message for removing from whitelist"
117+
}
118+
}

_locales/zh_CN/messages.json

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,115 @@
44
"description": "扩展名称"
55
},
66
"extensionDescription": {
7-
"message": "基于大语言模型检测B站视频中的植入广告",
7+
"message": "基于大语言模型,自动识别B站视频中的植入/口播广告,当视频进入与内容不相关口播广告时,可自动跳过广告。",
88
"description": "扩展描述"
9+
},
10+
"settingsTitle": {
11+
"message": "B站广告检测设置",
12+
"description": "设置页面标题"
13+
},
14+
"enableExtension": {
15+
"message": "启用插件",
16+
"description": "启用插件复选框标签"
17+
},
18+
"autoSkipAd": {
19+
"message": "自动跳过广告",
20+
"description": "自动跳过广告复选框标签"
21+
},
22+
"restrictedMode": {
23+
"message": "限制模式",
24+
"description": "限制模式复选框标签"
25+
},
26+
"localOllama": {
27+
"message": "连接本地 Ollama",
28+
"description": "本地Ollama复选框标签"
29+
},
30+
"apiUrl": {
31+
"message": "API 地址:",
32+
"description": "API地址输入框标签"
33+
},
34+
"apiUrlPlaceholder": {
35+
"message": "请输入API地址",
36+
"description": "API地址输入框占位符"
37+
},
38+
"apiKey": {
39+
"message": "API 密钥:",
40+
"description": "API密钥输入框标签"
41+
},
42+
"apiKeyPlaceholder": {
43+
"message": "请输入API密钥",
44+
"description": "API密钥输入框占位符"
45+
},
46+
"model": {
47+
"message": "模型名称:",
48+
"description": "模型名称输入框标签"
49+
},
50+
"modelPlaceholder": {
51+
"message": "请输入模型名称",
52+
"description": "模型名称输入框占位符"
53+
},
54+
"enableAudioTranscription": {
55+
"message": "启用语音识别",
56+
"description": "启用语音识别复选框标签"
57+
},
58+
"groqApiKey": {
59+
"message": "Groq 密钥:",
60+
"description": "Groq API密钥输入框标签"
61+
},
62+
"groqApiKeyPlaceholder": {
63+
"message": "请输入Groq API密钥",
64+
"description": "Groq API密钥输入框占位符"
65+
},
66+
"enableWhitelist": {
67+
"message": "启用UP主白名单",
68+
"description": "启用白名单复选框标签"
69+
},
70+
"upUidPlaceholder": {
71+
"message": "输入UP主UID",
72+
"description": "UP主UID输入框占位符"
73+
},
74+
"addToWhitelist": {
75+
"message": "添加到白名单",
76+
"description": "添加到白名单按钮文本"
77+
},
78+
"removeFromWhitelist": {
79+
"message": "移除",
80+
"description": "从白名单移除按钮文本"
81+
},
82+
"register": {
83+
"message": "注册",
84+
"description": "注册链接文本"
85+
},
86+
"currentNotOnBilibili": {
87+
"message": "当前不在哔哩哔哩视频页面",
88+
"description": "不在B站页面时的提示信息"
89+
},
90+
"extensionNotLoaded": {
91+
"message": "插件未完全加载,请等待或刷新",
92+
"description": "插件未加载时的提示信息"
93+
},
94+
"noAdDetected": {
95+
"message": "未检测到广告信息",
96+
"description": "未检测到广告时的提示信息"
97+
},
98+
"pleaseEnterUid": {
99+
"message": "请输入UP主UID",
100+
"description": "UID为空时的错误信息"
101+
},
102+
"addedToWhitelist": {
103+
"message": "已添加到白名单",
104+
"description": "添加到白名单成功信息"
105+
},
106+
"alreadyInWhitelist": {
107+
"message": "该UP主已在白名单中",
108+
"description": "UP主已在白名单中的错误信息"
109+
},
110+
"addFailed": {
111+
"message": "添加失败:",
112+
"description": "添加失败错误信息前缀"
113+
},
114+
"removedFromWhitelist": {
115+
"message": "已从白名单移除",
116+
"description": "从白名单移除成功信息"
9117
}
10118
}

manifests/manifest-chrome.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"extension_pages": "script-src 'self'; object-src 'self'"
1515
},
1616
"permissions": [
17-
"cookies",
1817
"storage",
1918
"tabs",
2019
"activeTab"

manifests/manifest-firefox.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,20 @@
1717
"128": "icons/icon128.png"
1818
},
1919
"content_security_policy": {
20-
"extension_pages": "script-src 'self'; object-src 'self'"
20+
"extension_pages": "script-src 'self'; object-src 'self'; connect-src https://*.bilibili.com https://api.bilibili.com https://*.bilivideo.com https://api.groq.com;"
2121
},
2222
"permissions": [
2323
"cookies",
2424
"storage",
2525
"tabs",
2626
"activeTab"
2727
],
28+
"host_permissions": [
29+
"*://*.bilibili.com/*",
30+
"*://api.bilibili.com/*",
31+
"*://*.bilivideo.com/*",
32+
"*://api.groq.com/*"
33+
],
2834
"background": {
2935
"scripts": [
3036
"background.js"
@@ -48,7 +54,8 @@
4854
],
4955
"js": [
5056
"content.js"
51-
]
57+
],
58+
"run_at": "document_start"
5259
}
5360
]
5461
}

src/background.ts

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,12 @@ class ApiRequestHandler {
6969

7070
const response = await fetch(url, {
7171
method: "POST",
72-
headers,
72+
headers: {
73+
...headers,
74+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
75+
},
7376
body: JSON.stringify(body),
77+
mode: 'cors'
7478
});
7579

7680
const data = await response.json();
@@ -126,7 +130,24 @@ class AudioTranscriptionHandler {
126130
*/
127131
private static async callGroqApiWithStream(audioUrl: string, fileInfo: any, options: any, apiKey: string): Promise<any> {
128132
// 获取音频流
129-
const audioResponse = await fetch(audioUrl);
133+
let audioResponse: Response;
134+
135+
// 判断是否是 bilivideo.com 域名的资源
136+
if (audioUrl.includes('bilivideo.com')) {
137+
audioResponse = await BilivideoResourceHandler.fetchBilivideoResource(audioUrl);
138+
} else {
139+
audioResponse = await fetch(audioUrl, {
140+
method: 'GET',
141+
headers: {
142+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
143+
'Referer': 'https://www.bilibili.com/',
144+
'Origin': 'https://www.bilibili.com'
145+
},
146+
credentials: 'include',
147+
mode: 'cors',
148+
referrerPolicy: 'strict-origin-when-cross-origin'
149+
});
150+
}
130151
if (!audioResponse.ok) {
131152
throw new Error('无法获取音频数据');
132153
}
@@ -172,8 +193,10 @@ class AudioTranscriptionHandler {
172193
method: 'POST',
173194
headers: {
174195
'Authorization': `Bearer ${apiKey}`,
196+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
175197
},
176-
body: formData
198+
body: formData,
199+
mode: 'cors'
177200
});
178201

179202
if (!response.ok) {
@@ -188,6 +211,33 @@ class AudioTranscriptionHandler {
188211

189212
}
190213

214+
// 专门处理 bilivideo.com 资源请求的处理器
215+
class BilivideoResourceHandler {
216+
/**
217+
* 处理 bilivideo.com 资源请求,使用正确的 referrer 策略
218+
*/
219+
static async fetchBilivideoResource(url: string, options: RequestInit = {}): Promise<Response> {
220+
return fetch(url, {
221+
...options,
222+
method: options.method || 'GET',
223+
headers: {
224+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
225+
'Referer': 'https://www.bilibili.com/',
226+
'Origin': 'https://www.bilibili.com',
227+
'Accept': '*/*',
228+
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
229+
'Sec-Fetch-Dest': 'video',
230+
'Sec-Fetch-Mode': 'cors',
231+
'Sec-Fetch-Site': 'cross-site',
232+
...options.headers
233+
},
234+
credentials: 'omit', // 对于 bilivideo.com 资源,不发送 cookies
235+
mode: 'cors',
236+
referrerPolicy: 'strict-origin-when-cross-origin'
237+
});
238+
}
239+
}
240+
191241
// 注册消息监听器
192242
chrome.runtime.onMessage.addListener(MessageHandler.handleMessage);
193243

0 commit comments

Comments
 (0)