Set registration directly in the anonymous function
This commit is contained in:
parent
88698df178
commit
b8ad957e64
1 changed files with 11 additions and 11 deletions
|
@ -1,7 +1,7 @@
|
||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Facebook desktop notification
|
// @name Facebook desktop notification
|
||||||
// @namespace https://www.schtobia.de/
|
// @namespace https://www.schtobia.de/
|
||||||
// @version 0.0.6
|
// @version 0.0.7
|
||||||
// @description Facebook desktop notification (based on HTML5)
|
// @description Facebook desktop notification (based on HTML5)
|
||||||
// @include http*://www.facebook.com/*
|
// @include http*://www.facebook.com/*
|
||||||
// @include http*://facebook.com/*
|
// @include http*://facebook.com/*
|
||||||
|
@ -9,7 +9,7 @@
|
||||||
// @run-at document-end
|
// @run-at document-end
|
||||||
// @downloadURL https://github.com/schtobia/greasemonkey/raw/master/facebook-notification.user.js
|
// @downloadURL https://github.com/schtobia/greasemonkey/raw/master/facebook-notification.user.js
|
||||||
// @updateURL 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==
|
// ==/UserScript==
|
||||||
//
|
//
|
||||||
|
|
||||||
|
@ -29,6 +29,8 @@ var notificationInstance = null;
|
||||||
|
|
||||||
var timeout = GM_getValue("timeout", 30000);
|
var timeout = GM_getValue("timeout", 30000);
|
||||||
|
|
||||||
|
var intervalID = null;
|
||||||
|
|
||||||
notify = function()
|
notify = function()
|
||||||
{
|
{
|
||||||
newFriendRequests = friendRequestsElement.innerHTML;
|
newFriendRequests = friendRequestsElement.innerHTML;
|
||||||
|
@ -48,11 +50,13 @@ notify = function()
|
||||||
if (newNotifications>lastNotifications)
|
if (newNotifications>lastNotifications)
|
||||||
msg=msg+"| "+(newNotifications-lastNotifications)+" new Notification(s) |";
|
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 + ')',
|
notificationInstance = new Notification("Facebook (" + newFriendRequests + '|' + newMessages + '|' + newNotifications + ')',
|
||||||
{
|
{
|
||||||
"dir" : "auto",
|
"dir" : "auto",
|
||||||
"body" : msg,
|
"body" : msg,
|
||||||
"icon" : GM_getResourceURL("FacebookLogo"),
|
"icon" : GM_getResourceText("facebookLogo"),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -64,22 +68,18 @@ notify = function()
|
||||||
|
|
||||||
registerNotification = function()
|
registerNotification = function()
|
||||||
{
|
{
|
||||||
var registrationSuccessful = false;
|
|
||||||
Notification.requestPermission(function(grantedPermission){
|
Notification.requestPermission(function(grantedPermission){
|
||||||
if (grantedPermission === "granted")
|
if (grantedPermission === "granted")
|
||||||
{
|
{
|
||||||
registrationSuccessful = true;
|
console.log(GM_info.script.name + ": permission granted");
|
||||||
console.log("permission granted");
|
intervalID = setInterval(notify, timeout);
|
||||||
|
console.log(GM_info.script.name + ": intervalID: " + intervalID);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
registrationSuccessful = false;
|
console.log(GM_info.script.name + ": permission NOT granted");
|
||||||
console.log("permission NOT granted");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (registrationSuccessful)
|
|
||||||
setTimeout(notify, timeout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Normal flow of operations below! */
|
/* Normal flow of operations below! */
|
||||||
|
|
Loading…
Reference in a new issue