forked from nazrhom/soundcloudController
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
executable file
·64 lines (52 loc) · 1.96 KB
/
popup.js
File metadata and controls
executable file
·64 lines (52 loc) · 1.96 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
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
62
63
64
var backgroundPage = chrome.extension.getBackgroundPage();
function updateUI(status) {
// Get current status to properly display UI
setPlayPauseButton(status.playing);
setRepeat(status.repeating);
setMute(status.muted);
setTitle(status.title);
}
function executeBackgroundCommand(command) {
return backgroundPage.executeCommand.bind(null, command);
}
document.addEventListener('DOMContentLoaded', function() {
backgroundPage.emitPageStatus();
// Setup Listeners
document.getElementById('play-pause-button').addEventListener('click', executeBackgroundCommand('play-or-pause'));
document.getElementById('previous-button').addEventListener('click', executeBackgroundCommand('previous'));
document.getElementById('next-button').addEventListener('click', executeBackgroundCommand('next'));
document.getElementById('repeat-button').addEventListener('click', executeBackgroundCommand('repeat'));
document.getElementById('volume-button').addEventListener('click', executeBackgroundCommand('mute-unmute'));
});
function setPlayPauseButton (playing) {
var image = document.getElementById('play-pause');
var marquee = document.getElementById('titolo');
if (playing) {
image.src = 'img/pause.svg';
marquee.setAttribute('scrollamount', "5");
} else {
image.src = 'img/play.svg';
marquee.setAttribute('scrollamount', "3");
}
}
function setRepeat(repeating) {
var image = document.getElementById('replay');
if (repeating) {
image.src = 'img/repeat_active.svg';
} else {
image.src = 'img/repeat.svg';
}
}
function setMute(muted) {
var image = document.getElementById('volume');
if (muted) {
image.src = 'img/mute.svg';
} else {
image.src = 'img/max_volume.svg';
}
}
function setTitle(title) {
var marquee = document.getElementById('titolo');
marquee.innerHTML = title;
}
chrome.runtime.onMessage.addListener(updateUI);