-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
54 lines (47 loc) · 2.15 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var UI = {
content: function(playlist) {
var last = playlist[ playlist.length - 1 ];
var template = [
'<section class="music m-b-sm">',
'<div class="music-cover pull-left m-r-sm">',
'<img id="art" src="'+ last.art +'" alt="" />',
'</div>',
'<div class="music-details pull-left">',
'<div id="song-title" class="music-label font-bold">'+ last.song +'</div>',
'<div id="artist-name" class="music-label">'+ last.artist +'</div>',
'<div id="album-title" class="music-label">'+ last.album +'</div>',
'</div>',
'</section>',
'<a href="'+ last.url +'" id="download-btn" class="btn-primary font-bold text-center block btn-download" download="'+ (last.artist + ' - ' + last.song + ' - ' + last.album + '.mp4') +'">Download</a>',
'<a href="#" id="next-btn" class="btn-primary font-bold text-center block btn-next">Next</a>',
'<input type="text" value="'+ last.url +'" class="audio-url" />'
];
document.getElementById('content').innerHTML = template.join("\n");
},
pandoraTab: function( callback ) {
chrome.tabs.query({}, function( tabs ) {
for ( var i = 0; i < tabs.length; i++ ) {
if ( tabs[i].url.indexOf("pandora") !== -1 ) {
if ( typeof callback === 'function' ) callback( tabs[i] );
return false;
}
}
});
}
};
window.addEventListener('DOMContentLoaded', function() {
UI.pandoraTab(function( tab ) {
chrome.tabs.sendMessage( tab.id, { from: 'popup' }, UI.content );
});
var search = setInterval(function() {
var nextBtn = document.getElementById( 'next-btn' );
if ( nextBtn ) {
clearInterval( search );
document.getElementById( 'next-btn' ).addEventListener('click', function() {
UI.pandoraTab(function( tab ) {
chrome.tabs.sendMessage( tab.id, { from: 'popup', command: 'skip song' } );
});
});
}
}, 100);
});