-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpandora_preload.js
49 lines (49 loc) · 1.42 KB
/
pandora_preload.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
window.addEventListener('load', function() {
var ipcRenderer = require('electron').ipcRenderer;
window.simulateClick = function simulateClick(element) {
if (!element) {
return false;
}
var click = new MouseEvent('click', {
bubbles: true,
cancelable: false,
view: window
});
return element.dispatchEvent(click);
};
window.Play = function Play() {
var isPlaying = document.querySelector('div.playButton').style.display !== 'block';
var playPauseButton = null;
if (isPlaying) {
playPauseButton = document.querySelector('div.pauseButton > a');
} else {
playPauseButton = document.querySelector('div.playButton > a');
}
simulateClick(playPauseButton);
};
window.Next = function Next() {
var skipButton = document.querySelector('div.skipButton > a');
simulateClick(skipButton);
};
var lastTitle = '';
setInterval(function() {
var title = document.querySelector('.playerBarSong').textContent;
var artist = document.querySelector('.playerBarArtist').textContent;
var album = document.querySelector('.playerBarAlbum').textContent;
var art = document.querySelector('.playerBarArt').src;
// We got a new song!
if (title != lastTitle) {
new Notification(title, {
silent: true,
body: 'by ' + artist + '\non ' + album,
icon: art
});
lastTitle = title;
ipcRenderer.send('asynchronous-message', {
title: title,
artist: artist,
album: album
});
}
}, 1000);
}, false);