forked from jobisoft/notificationbar-API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
52 lines (43 loc) · 1.16 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
42
43
44
45
46
47
48
49
50
51
browser.notificationbox.onButtonClicked.addListener((id, name) => {
console.log(`${name} clicked in ${id}`);
if (["btn2"].includes(name)) {
console.log("Programatically closing!");
browser.notificationbox.clear(id);
return true;
}
if (["btn4"].includes(name)) {
console.log("Never gonna give you up!");
// returning true will keep the box open
return true;
}
});
browser.notificationbox.onDismissed.addListener((id) => {
console.log(`${id} was dismissed`);
});
browser.notificationbox.onClosed.addListener((id, closedByUser) => {
console.log(`${id} was closed by user: ${closedByUser}`);
});
browser.compose.onBeforeSend.addListener(async (tab, details) => {
await browser.notificationbox.create(tab.windowId, "testID", {
label: "Sample notification",
buttons: [
{
id: "btn2",
label: "Delayed Close",
accesskey: "d",
},
{
id: "btn3",
label: "Okey-dokey",
accesskey: "o",
},
{
id: "btn4",
label: "Stay!"
}
]
});
let data = await browser.notificationbox.getAll();
console.log(data);
return { cancel: true };
});