-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
31 lines (30 loc) · 1.33 KB
/
background.js
File metadata and controls
31 lines (30 loc) · 1.33 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
30
31
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === "checkLink") {
fetch(message.url, { method: "HEAD" })
.then(response => sendResponse({ status: response.status }))
.catch(() => sendResponse({ status: 0 }));
return true;
} else if (message.action === "storeSession") {
chrome.storage.session.get({ sessionLinks: {} }, (data) => {
let sessionLinks = data.sessionLinks || {};
if (!sessionLinks[message.sourceUrl]) {
sessionLinks[message.sourceUrl] = [];
}
// Check if the link already exists
if (!sessionLinks[message.sourceUrl].some(link => link.targetUrl === message.targetUrl)) {
sessionLinks[message.sourceUrl].push({ targetUrl: message.targetUrl, type: message.type });
chrome.storage.session.set({ sessionLinks });
}
});
} else if (message.action === "getSession") {
chrome.storage.session.get({ sessionLinks: {} }, (data) => {
sendResponse({ sessionLinks: data.sessionLinks || {} });
});
return true;
} else if (message.action === "clearSession") {
chrome.storage.session.clear(() => {
sendResponse({ success: true });
});
return true;
}
});