-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbackground.js
More file actions
28 lines (25 loc) · 865 Bytes
/
Copy pathbackground.js
File metadata and controls
28 lines (25 loc) · 865 Bytes
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
// Function to clear completed downloads
function clearDownloads(delaySeconds) {
const delayMilliseconds = delaySeconds * 1000;
setTimeout(() => {
chrome.downloads.erase({ state: "complete" }, (erasedIds) => {
if (chrome.runtime.lastError) {
console.error("Error erasing downloads:", chrome.runtime.lastError);
} else {
console.log("Cleared completed downloads:", erasedIds);
}
});
}, delayMilliseconds);
}
// Listen for changes in download state
chrome.downloads.onChanged.addListener((downloadDelta) => {
if (
downloadDelta.state &&
downloadDelta.state.current === "complete"
) {
// Get the delay from storage, or use a default value (e.g., 5 seconds)
chrome.storage.sync.get({ clearDelay: 5 }, (items) => {
clearDownloads(items.clearDelay);
});
}
});