-
Notifications
You must be signed in to change notification settings - Fork 1
/
popup.js
35 lines (30 loc) · 858 Bytes
/
popup.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
// Some helpers.
const dom = query => document.querySelector(query);
const addClass = (query, className) => dom(query).classList.add(className);
const removeClass = (query, className) =>
dom(query).classList.remove(className);
// Contact the background page.
var bg = chrome.extension.getBackgroundPage();
// Listeners for button.
dom('#start').onclick = function() {
bg.start();
setIcon('icon48-active');
addClass('#controls', 'playing');
};
dom('#stop').onclick = function() {
bg.stop();
setIcon('icon48');
removeClass('#controls', 'playing');
};
// Check if audio is playing in the background, reflect that in the popup.
if (bg.checkIfPlaying()) {
addClass('#controls', 'playing');
} else {
setIcon('icon48');
}
// Helper to set icon.
function setIcon(file) {
chrome.browserAction.setIcon({
path: `icons/${file}.png`,
});
}