-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
29 lines (28 loc) · 1.03 KB
/
background.js
File metadata and controls
29 lines (28 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// 插件安装时的初始化
chrome.runtime.onInstalled.addListener(() => {
console.log('网页图片幻灯片插件已安装');
// 设置默认配置(interval单位为秒)
chrome.storage.sync.set({
interval: 3,
order: 'sequential'
});
});
// 监听来自content script的消息
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === 'DOWNLOAD_IMAGE') {
chrome.downloads.download({
url: request.url,
filename: request.filename,
conflictAction: 'uniquify',
saveAs: false
}, (downloadId) => {
if (chrome.runtime.lastError) {
console.error('Download failed:', chrome.runtime.lastError);
sendResponse({ success: false, error: chrome.runtime.lastError.message });
} else {
sendResponse({ success: true, downloadId: downloadId });
}
});
return true; // 保持消息通道开启,以便异步发送响应
}
});