So i've made this into a google chrome userscript (like greasemonkey).
It's a totally terrible hack-job, but it works basically. I just did it so people wouldn't need to edit their subsonic files. It would be much nicer to be built-in though for sure.
I've even updated it from above to put the album art (sort of*) into the popup.
Installation instructions:
1. Copy code below into a file called subsonicchromenotifications.user.js
2. change @match line to point to your subsonic server.
3. drag into chrome and follow instructions given by chrome.
Like above, the first time you listen to a song, it will ask for confirmation to make notifications, click allow.
- Code: Select all
// ==UserScript==
// @name Subsonic Chrome Notifications
// @namespace http://www.activeobjects.no/subsonic/forum/viewforum.php?f=8
// @description Uses chrome desktop notifications to display song title information while using Subsonic
// @match http://<subsonichostname>/*
// ==/UserScript==
var pathname = window.location.pathname
if (pathname.substring(pathname.length-13,pathname.length) == 'playlist.view'){
function addFunction(func, exec) {
var script = document.createElement("script");
script.setAttribute("type", "application/javascript");
script.textContent = (exec ? "(" : "") + func.toString() + (exec ? ")();" : "");
setTimeout(function() {
document.head.appendChild(script)
},500);
}
// this function is run with access to the real browser environment.
inject = function() {
// store the original skip (hopefully to preserve functionality for future changes to subsonic)
skip_orig = skip;
// add new skip with notification
skip = function(index) {
skip_orig(index);
setNotification(songs[getCurrentSongIndex()]);
};
// notification functions
setNotification = function(song) {
var n;
//webkitNotifications
if (window.webkitNotifications.checkPermission() != 0) {
setAllowNotification();
return 0;
}
// get album art from nowPlatingService, and create the notification inside the callback
window.parent.right.nowPlayingService.getNowPlaying(function(nowPlaying) {
var imgUrl = 'icons/now_playing.png';
for (var j = 0; j<nowPlaying.length; j++){
if(nowPlaying[j].artist == song.artist) {
imgUrl = nowPlaying[j].coverArtUrl;
break;
}
}
n = window.webkitNotifications.createNotification(imgUrl, song.title, song.artist + ' - ' + song.album);
n.ondisplay = function() {
setTimeout(function() {
n.cancel();
},5000);
};
n.show();
});
}
setAllowNotification = function() {
window.webkitNotifications.requestPermission(permissionGranted);
}
permissionGranted = function() {
if (window.webkitNotifications.checkPermission() == 0)
setNotification();
}
} // end of injected code
addFunction(inject,true);
}
*it tries to get the album-art, but I did it in a very shitty hacky way that should work most of the time but not always.