This repository has been archived by the owner on Apr 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
pppandora.js
131 lines (110 loc) · 3.6 KB
/
pppandora.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
var songTitle = null,
songArtist = null,
songAlbum = null,
songArt = null;
// $('.PauseButton').on('click', function () {
// // send message to extension saying it is paused
// chrome.runtime.sendMessage({message: "paused"});
// });
$('.PlayButton').on('click', function () {
var status = $('.PlayButton').data('qa');
// send message to extension saying it is playing
chrome.runtime.sendMessage({
message: status == 'pause_button' ? "playing" : "paused"
});
});
// DOM Events Listed Below:
//
// DOMNodeInserted
// DOMNodeRemoved
// DOMAttrModified
// DOMSubtreeModified
// $('.nowPlayingTopInfo__current__trackName').bind("DOMNodeInserted", function () {
// songTitle = $(this).text();
// getSongInfo();
// });
// $('.nowPlayingTopInfo__current__artistName').bind("DOMNodeInserted", function () {
// songArtist = $(this).text();
// getSongInfo();
// });
// $('.nowPlayingTopInfo__current__albumName').bind("DOMNodeInserted",function () {
// songAlbum = $(this).text();
// getSongInfo();
// });
// $('.nowPlayingTopInfo__artContainer__art').bind("DOMNodeInserted", function () {
// // var imgs = $(this).find('img');
// // if (imgs.length > 1) {
// // songArt = $(imgs[1]).attr('src');
// // } else {
// // songArt = $(imgs[0]).attr('src');
// // }
// songArt = $('meta[property="og:image"]').attr('content');
// getSongInfo();
// });
var nowPlayingSong = "";
var nowPlayingArtist = "";
var nowPlayingAlbum = "";
var nowPlayingAlbumArt = "";
setInterval(function () {
var currentSong = $('.nowPlayingTopInfo__current__trackName').text().trim();
var currentArtist = $('.nowPlayingTopInfo__current__artistName').text().trim();
var currentAlbum = $('.nowPlayingTopInfo__current__albumName').text().trim();
var currentAlbumArt = $('.nowPlayingTopInfo__artContainer__art').first().css('background-image').replace(/url\(|\)|\"/g, '').trim()
if (currentSong != ""
&& currentArtist != ""
&& currentAlbum != ""
&& currentAlbumArt != ""
&& nowPlayingSong != currentSong
&& nowPlayingArtist != currentArtist
&& nowPlayingAlbum != currentAlbum
&& nowPlayingAlbumArt != currentAlbumArt)
{
getSongInfo();
nowPlayingSong = currentSong;
nowPlayingArtist = currentArtist;
nowPlayingAlbum = currentAlbum;
nowPlayingAlbumArt = currentAlbumArt;
}
getPlaying();
}, 100)
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.greeting == "hello") {
sendResponse({message: "hi"});
getSongInfo();
}
});
function getPlaying() {
var status = $('.PlayButton').data('qa');
chrome.runtime.sendMessage({
message: status == 'pause_button' ? "playing" : "paused"
});
}
function getSongInfo() {
songTitle = $('.nowPlayingTopInfo__current__trackName').text().trim();
songArtist = $('.nowPlayingTopInfo__current__artistName').text().trim();
songAlbum = $('.nowPlayingTopInfo__current__albumName').text().trim();
songArt = $('.nowPlayingTopInfo__artContainer__art').first().css('background-image').replace(/url\(|\)|\"/g, '').trim()
checkIfReadyToSend();
}
function checkIfReadyToSend() {
if ( songTitle != null && songTitle != "" &&
songArtist != null && songArtist != "" &&
songAlbum != null && songAlbum != "" &&
songArt != null && songArt != "") {
sendSongChanged();
}
}
function sendSongChanged() {
chrome.runtime.sendMessage({ message: "songChanged",
songTitle: songTitle,
songArtist: songArtist,
songArt: songArt,
songAlbum: songAlbum });
// clear all variables for next check
songTitle = null;
songArtist = null;
songAlbum = null;
songArt = null;
}
// getPlaying(); getSongInfo();