-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice_worker.js
42 lines (32 loc) · 1.16 KB
/
service_worker.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
32
33
34
35
36
37
38
39
40
41
42
const contextHandler = async (info, tab) => {
chrome.storage.local.set({ selectedText: info.selectionText }, () => {
chrome.sidePanel.open({tabId: tab.id});
});
};
chrome.runtime.onConnect.addListener((port) => {
if (port.name === 'sidePanelPort') {
port.onDisconnect.addListener(() => {
chrome.storage.local.clear(() => {
if (chrome.runtime.lastError) {
console.error('Error clearing storage:', chrome.runtime.lastError);
} else {
console.log('Storage cleared successfully.');
}
});
});
}
});
chrome.runtime.onInstalled.addListener(function(details) {
chrome.contextMenus.create({
"title": "AI Summarizer",
"id": "aisummarizer-extension",
"contexts": ["selection"]
});
chrome.sidePanel.setPanelBehavior({openPanelOnActionClick: true });
if (details.reason == "install") {
chrome.tabs.create({
"url": "https://github.com/gigaArpit/AI-Summarizer/blob/main/docs/extension-welcome.md"
});
}
});
chrome.contextMenus.onClicked.addListener(contextHandler);