-
Notifications
You must be signed in to change notification settings - Fork 0
/
background-script.js
61 lines (47 loc) · 1.29 KB
/
background-script.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
52
53
54
55
56
57
58
59
60
61
// let nowPlayingButtons = [
// {
// title: 'previous'
// }, {
// title: 'next'
// }
// ];
let nowPlayingId = 'nowplaying-notification';
let displayNotifications = true;
function notifyNowPlaying(msg) {
if (!displayNotifications) return;
chrome.notifications.create(
nowPlayingId, {
type: 'basic',
title: 'Now playing',
iconUrl: chrome.runtime.getURL('/icons/play.png'),
message: msg.name
// buttons: nowPlayingButtons
}
);
setTimeout(function () {
chrome.notifications.clear(nowPlayingId);
}, 4000);
}
// function buttonClicked(notificationId, buttonIndex){
// if(notificationId == )
// }
function toggleDisplayNotifications() {
displayNotifications = !displayNotifications;
updateBrowserAction();
}
function updateBrowserAction() {
let path, title;
if (displayNotifications) {
path = 'icons/play48.png';
title = 'YT Album Player: On';
} else {
path = 'icons/play-inactive48.png';
title = 'YT Album Player: Off';
}
chrome.browserAction.setIcon({ path });
chrome.browserAction.setTitle({ title });
}
chrome.runtime.onMessage.addListener(notifyNowPlaying);
// browser.notifications.onButtonClicked.addListener();
chrome.browserAction.onClicked.addListener(toggleDisplayNotifications);
updateBrowserAction();