-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotifications.js
More file actions
36 lines (35 loc) · 1.2 KB
/
notifications.js
File metadata and controls
36 lines (35 loc) · 1.2 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
32
33
34
35
36
const sendNotification = (step, total, limit) => {
chrome.permissions.contains({permissions: ['notifications']}, (result) => {
if (result) {
if (step > 0 && total >= limit || step < 0 && total <= limit) {
chrome.notifications.getAll((items) => {
if (items && Object.keys(items).length > 0) {
//console.log('notification already opened:', items)
} else {
const options = {
type: 'basic',
iconUrl: 'Res/Icons/icon48.png',
title: chrome.i18n.getMessage('notification_title'),
message: chrome.i18n.getMessage('notification_message') + limit,
requireInteraction: true,
priority: 2
}
chrome.notifications.create('LimitReachedNotification', options, () => {
chrome.notifications.onClicked.addListener(clearAllNotifications)
chrome.notifications.onClosed.addListener(clearAllNotifications)
})
}
})
}
}
})
}
const clearAllNotifications = () => {
chrome.notifications.getAll((items) => {
if (items) {
for (let key in items) {
chrome.notifications.clear(key)
}
}
})
}