-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
37 lines (32 loc) · 783 Bytes
/
background.js
File metadata and controls
37 lines (32 loc) · 783 Bytes
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
chrome.runtime.onMessage.addListener( data => {
if ( data.type === 'notification' ) {
notify( data.message );
}
});
chrome.runtime.onInstalled.addListener( () => {
chrome.contextMenus.create({
id: 'notify',
title: "Notify!: %s",
contexts:[ "selection" ]
});
});
chrome.contextMenus.onClicked.addListener( ( info, tab ) => {
if ( 'notify' === info.menuItemId ) {
notify( info.selectionText );
}
} );
const notify = message => {
chrome.storage.local.get( ['notifyCount'], data => {
let value = data.notifyCount || 0;
chrome.storage.local.set({ 'notifyCount': Number( value ) + 1 });
} );
return chrome.notifications.create(
'',
{
type: 'basic',
title: 'Notify!',
message: message || 'Notify!',
iconUrl: './assets/icons/128.png',
}
);
};