-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
30 lines (24 loc) · 1010 Bytes
/
background.js
File metadata and controls
30 lines (24 loc) · 1010 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
29
30
// Background script to handle downloads
// This persists across popup closes
browser.runtime.onMessage.addListener((message, sender) => {
if (message.action === 'download') {
const { jsonData, filename, isBulkScrape } = message;
// Create blob and download
const blob = new Blob([jsonData], { type: 'application/json' });
const url = URL.createObjectURL(blob);
// Determine download path and behavior
const downloadOptions = {
url: url,
filename: isBulkScrape ? `reviews/${filename}` : filename,
saveAs: !isBulkScrape // Auto-download for bulk, prompt for single scrapes
};
browser.downloads.download(downloadOptions).then(() => {
// Clean up blob URL after download starts
setTimeout(() => URL.revokeObjectURL(url), 10000);
}).catch(error => {
console.error('Download failed:', error);
});
return true; // Keep message channel open for async response
}
});
console.log('[Background] Momus background script loaded');