优化调整

This commit is contained in:
zhongluofeng
2026-08-14 17:47:06 +08:00
parent 6c7897bf47
commit 7d49a7395f
50 changed files with 2805 additions and 259 deletions
@@ -16,7 +16,6 @@ const DEFAULT_CONFIG = {
interceptDownload: true,
minSize: 0,
excludeDomains: [],
showNotifications: true,
// 嗅探开关
sniffEnabled: true,
// 嗅探的资源类型:只保留视频/音频/图片/压缩包/种子/安装包
@@ -386,28 +385,13 @@ async function handleDownloadCreated(downloadItem) {
const filename = downloadItem.filename || ''
try {
const id = await addDownload(url, filename, downloadItem.referrer, '')
await notify('已添加到 Thing', `${filename || url}`)
await addDownload(url, filename, downloadItem.referrer, '')
} catch (e) {
await notify('Thing 添加失败', `${filename || url}\n${e.message}`)
// 添加失败:回退到浏览器自带下载,不弹通知
try { await chrome.downloads.download({ url }) } catch { /* ignore */ }
}
}
// ===== 通知 =====
async function notify(title, message) {
const config = await getConfig()
if (!config.showNotifications) return
try {
await chrome.notifications.create({
type: 'basic',
iconUrl: 'icons/icon-128.png',
title,
message
})
} catch { /* ignore */ }
}
// ===== 右键菜单 =====
chrome.runtime.onInstalled.addListener(() => {
chrome.contextMenus.create({
@@ -428,10 +412,7 @@ chrome.contextMenus.onClicked.addListener(async (info, tab) => {
const filename = url.split('/').pop()?.split('?')[0] || ''
try {
await addDownload(url, filename, info.pageUrl, '')
await notify('已添加到 Thing', `${filename || url}`)
} catch (e) {
await notify('Thing 添加失败', `${e.message}`)
}
} catch (e) { /* 忽略:添加失败时不打扰用户 */ }
}
})
@@ -11,9 +11,7 @@
"permissions": [
"downloads",
"storage",
"notifications",
"webRequest",
"webNavigation",
"contextMenus",
"tabs",
"scripting"
@@ -87,11 +87,6 @@
<span>启用资源嗅探</span>
</label>
<label class="checkbox">
<input type="checkbox" id="showNotifications" />
<span>显示桌面通知</span>
</label>
<label class="field">
<span>下载最小文件大小(字节,0=全部)</span>
<input type="number" id="minSize" min="0" placeholder="0" />
@@ -12,7 +12,6 @@ const DEFAULT_CONFIG = {
interceptDownload: true,
minSize: 0,
excludeDomains: [],
showNotifications: true,
sniffEnabled: true,
sniffTypes: ['video', 'audio', 'image', 'archive', 'torrent', 'installer'],
sniffMaxItems: 200,
@@ -57,7 +56,6 @@ function fillForm(config) {
$('secret').value = config.secret || ''
$('interceptDownload').checked = config.interceptDownload !== false
$('sniffEnabled').checked = config.sniffEnabled !== false
$('showNotifications').checked = config.showNotifications !== false
$('minSize').value = config.minSize || 0
$('sniffMinSize').value = config.sniffMinSize ?? DEFAULT_CONFIG.sniffMinSize
$('excludeDomains').value = (config.excludeDomains || []).join(',')
@@ -69,7 +67,6 @@ function readForm() {
secret: $('secret').value.trim(),
interceptDownload: $('interceptDownload').checked,
sniffEnabled: $('sniffEnabled').checked,
showNotifications: $('showNotifications').checked,
minSize: parseInt($('minSize').value, 10) || 0,
sniffMinSize: parseInt($('sniffMinSize').value, 10) || 0,
excludeDomains: $('excludeDomains').value