Moderator: moderators
setNotification(song);
function setNotification(song)
{
var n;
//webkitNotifications
if (window.webkitNotifications.checkPermission() != 0)
{
setAllowNotification();
return 0;
}
n = window.webkitNotifications.createNotification('/icons/now_playing.png', song.title, song.artist + ' - ' + song.album);
n.ondisplay = function() {
setTimeout(function(){
n.cancel();
},5000); };
n.show();
}
function setAllowNotification()
{
window.webkitNotifications.requestPermission(permissionGranted);
}
function permissionGranted()
{
if (window.webkitNotifications.checkPermission() == 0)
setNotification();
}
// ==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);
}
// ==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);
//insert e small delay to let the player update the albumart url
setTimeout('setNotification(songs[getCurrentSongIndex()])', 500);
};
// 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/desktop_notification.png';
for (var j = 0; j<nowPlaying.length; j++){
if(nowPlaying[j].streamUrl == song.streamUrl) {
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);
}
tricer wrote:I created the .js file per the instructions and also changed @match. I dragged it into chrome and allowed the program when prompted.
It isn't working for me. Desktop notifications work for me from Gmail, but this doesn't.
Can anyone think of what else I may need to do?
tsquillario wrote:I just happened to stumble on this thread while Googling for some related stuff. I'm implementing the Desktop Notifications in the MiniSub Chrome App. I'm in the process of coding and testing it right now. It will be included in the next version.
Chrome App
https://chrome.google.com/webstore/detail/jccdpflnecheidefpofmlblgebobbloc
Forum Thread
http://forum.subsonic.org/forum/viewtopic.php?f=8&t=7553
Return to Mods, Apps and Clients
Users browsing this forum: No registered users and 6 guests