-
Notifications
You must be signed in to change notification settings - Fork 1
/
background.js
31 lines (30 loc) · 1000 Bytes
/
background.js
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
31
let linkSet = new Set();
let scrapingEnabled = false;
browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === 'addLink' && scrapingEnabled) {
const link = message.link;
if (!linkSet.has(link)) {
linkSet.add(link);
sendResponse({ success: true });
} else {
sendResponse({ success: false });
}
} else if (message.action === 'getAllLinks') {
sendResponse({ links: Array.from(linkSet) });
} else if (message.action === 'startScraping') {
scrapingEnabled = true;
sendResponse({ success: true });
} else if (message.action === 'stopScraping') {
scrapingEnabled = false;
sendResponse({ success: true });
} else if (message.action === 'resetLinks') {
linkSet.clear();
sendResponse({ success: true });
} else if (message.action === 'getScrapingStatus') {
sendResponse({ scrapingEnabled });
} else {
sendResponse({ success: false, error: 'Unknown action' });
}
return true;
}
)