优化调整

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) { /* 忽略:添加失败时不打扰用户 */ }
}
})