-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy patht61.js
36 lines (32 loc) · 965 Bytes
/
t61.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
// Register the music player
chrome.extension.sendRequest({type: 'register'}, function(response) {
// Do stuff with response
});
function simulateClick(elementId) {
var evt = document.createEvent('MouseEvents');
evt.initMouseEvent('click', true, false, document, 0, 0, 0, 0, 0, false,
false, false, false, 0, null);
document.getElementById(elementId).dispatchEvent(evt);
}
function isVisible(elementId) {
return document.getElementById(elementId).style.display !== 'none';
}
chrome.extension.onConnect.addListener(function(port) {
port.onMessage.addListener(function(msg) {
switch(msg) {
case 'previous':
simulateClick('large_previous_song_button');
break;
case 'playpause':
if (isVisible('pause_button')) {
simulateClick('pause_button');
} else {
simulateClick('play_button');
}
break;
case 'next':
simulateClick('large_next_song_button');
break;
}
});
});