Check on callback if the DOM nodes exist.

If the don't, clear the timer, as each subsequent run would operate on the same empty nodes.
This commit is contained in:
Tobias Schmidl 2014-03-08 07:34:14 +01:00
parent ebd2a09947
commit 4b14ea8de1
2 changed files with 18 additions and 2 deletions

View file

@ -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.1.1 // @version 0.2.0
// @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/*
@ -32,6 +32,14 @@ var intervalID = null;
notify = function() notify = function()
{ {
if (friendRequestsElement == null || messagesElement == null || notificationsElement == null)
{
console.log(GM_info.script.name + ": One of the DOM nodes is empty! Clearing the interval timer " + intervalID + "!");
clearInterval(intervalID);
intervalID = null;
return;
}
newFriendRequests = friendRequestsElement.innerHTML; newFriendRequests = friendRequestsElement.innerHTML;
newMessages = messagesElement.innerHTML; newMessages = messagesElement.innerHTML;
newNotifications = notificationsElement.innerHTML; newNotifications = notificationsElement.innerHTML;

View file

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name Google+ desktop notification // @name Google+ desktop notification
// @namespace https://www.schtobia.de/ // @namespace https://www.schtobia.de/
// @version 0.1.1 // @version 0.2.0
// @description Google+ desktop notification (based on HTML5) // @description Google+ desktop notification (based on HTML5)
// @include http*://plus.google.com/* // @include http*://plus.google.com/*
// @grant GM_getValue // @grant GM_getValue
@ -25,6 +25,14 @@ var intervalID = null;
notify = function() notify = function()
{ {
if (notificationsElement == null)
{
console.log(GM_info.script.name + ": The DOM node is empty! Clearing the interval timer " + intervalID + "!");
clearInterval(intervalID);
intervalID = null;
return;
}
newNotifications = notificationsElement.innerHTML; newNotifications = notificationsElement.innerHTML;
if (newNotifications > lastNotifications) if (newNotifications > lastNotifications)