Set registration directly in the anonymous function

This commit is contained in:
Tobias Schmidl 2014-02-24 15:49:24 +01:00
parent 88698df178
commit b8ad957e64

View file

@ -1,7 +1,7 @@
// ==UserScript==
// @name Facebook desktop notification
// @namespace https://www.schtobia.de/
// @version 0.0.6
// @version 0.0.7
// @description Facebook desktop notification (based on HTML5)
// @include http*://www.facebook.com/*
// @include http*://facebook.com/*
@ -9,7 +9,7 @@
// @run-at document-end
// @downloadURL https://github.com/schtobia/greasemonkey/raw/master/facebook-notification.user.js
// @updateURL https://github.com/schtobia/greasemonkey/raw/master/facebook-notification.user.js
// @resource FacebookLogo https://s-static.ak.facebook.com/rsrc.php/yi/r/q9U99v3_saj.ico
// @resource facebookLogo https://s-static.ak.facebook.com/rsrc.php/yi/r/q9U99v3_saj.ico
// ==/UserScript==
//
@ -29,6 +29,8 @@ var notificationInstance = null;
var timeout = GM_getValue("timeout", 30000);
var intervalID = null;
notify = function()
{
newFriendRequests = friendRequestsElement.innerHTML;
@ -48,11 +50,13 @@ notify = function()
if (newNotifications>lastNotifications)
msg=msg+"| "+(newNotifications-lastNotifications)+" new Notification(s) |";
console.log(GM_info.script.name + ": Trying to set notification...", msg);
notificationInstance = new Notification("Facebook (" + newFriendRequests + '|' + newMessages + '|' + newNotifications + ')',
{
"dir" : "auto",
"body" : msg,
"icon" : GM_getResourceURL("FacebookLogo"),
"icon" : GM_getResourceText("facebookLogo"),
}
)
@ -64,22 +68,18 @@ notify = function()
registerNotification = function()
{
var registrationSuccessful = false;
Notification.requestPermission(function(grantedPermission){
if (grantedPermission === "granted")
{
registrationSuccessful = true;
console.log("permission granted");
console.log(GM_info.script.name + ": permission granted");
intervalID = setInterval(notify, timeout);
console.log(GM_info.script.name + ": intervalID: " + intervalID);
}
else
{
registrationSuccessful = false;
console.log("permission NOT granted");
console.log(GM_info.script.name + ": permission NOT granted");
}
});
if (registrationSuccessful)
setTimeout(notify, timeout);
}
/* Normal flow of operations below! */