-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
41 lines (38 loc) · 1.12 KB
/
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
32
33
34
35
36
37
38
39
40
41
let monitorWindow = null;
// Open monitor window when extension icon is clicked
chrome.action.onClicked.addListener(() => {
if (monitorWindow) {
// If window exists, focus it
chrome.windows.update(monitorWindow.id, { focused: true });
} else {
// Create new window
chrome.windows.create(
{
url: chrome.runtime.getURL("monitor.html"),
type: "popup",
width: 800,
height: 600,
},
(window) => {
monitorWindow = window;
}
);
}
});
// Track window closure
chrome.windows.onRemoved.addListener((windowId) => {
if (monitorWindow && monitorWindow.id === windowId) {
monitorWindow = null;
}
});
// Handle notifications
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === "NEW_TOKEN") {
chrome.notifications.create({
type: "basic",
iconUrl: "icon.png",
title: "New Token Listed!",
message: `New token found: ${message.tokenName}`,
});
}
});