2014-03-08 07:04:14 +01:00
|
|
|
// ==UserScript==
|
|
|
|
// @name Google+ desktop notification
|
|
|
|
// @namespace https://www.schtobia.de/
|
2017-11-21 09:48:39 +01:00
|
|
|
// @version 0.2.7
|
2014-03-08 07:04:14 +01:00
|
|
|
// @description Google+ desktop notification (based on HTML5)
|
2017-11-21 09:48:39 +01:00
|
|
|
// @author Tobias Schmidl
|
2014-03-10 06:51:46 +01:00
|
|
|
// @include http://plus.google.com/
|
|
|
|
// @include https://plus.google.com/
|
2014-03-08 10:11:30 +01:00
|
|
|
// @include http://plus.google.com/u/0/*
|
|
|
|
// @include https://plus.google.com/u/0/*
|
|
|
|
// @exclude http://plus.google.com/u/0/_/*
|
|
|
|
// @exclude https://plus.google.com/u/0/_/*
|
2014-03-08 07:04:14 +01:00
|
|
|
// @grant GM_getValue
|
|
|
|
// @run-at document-end
|
|
|
|
// @downloadURL https://github.com/schtobia/greasemonkey/raw/master/googleplus-notification.user.js
|
|
|
|
// @updateURL https://github.com/schtobia/greasemonkey/raw/master/googleplus-notification.user.js
|
|
|
|
// ==/UserScript==
|
|
|
|
//
|
|
|
|
|
|
|
|
var Notification = window.Notification || window.mozNotification || window.webkitNotification;
|
|
|
|
|
|
|
|
var notificationsElement = document.getElementsByClassName("gb_Fa")[0];
|
|
|
|
var newNotifications = 0;
|
|
|
|
|
|
|
|
var lastNotifications = 0;
|
|
|
|
var notificationInstance = null;
|
|
|
|
|
|
|
|
var timeout = GM_getValue("timeout", 10000);
|
|
|
|
|
|
|
|
var intervalID = null;
|
|
|
|
|
|
|
|
notify = function()
|
|
|
|
{
|
2014-03-08 07:34:14 +01:00
|
|
|
if (notificationsElement == null)
|
|
|
|
{
|
|
|
|
console.log(GM_info.script.name + ": The DOM node is empty! Clearing the interval timer " + intervalID + "!");
|
|
|
|
clearInterval(intervalID);
|
|
|
|
intervalID = null;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-08 07:04:14 +01:00
|
|
|
newNotifications = notificationsElement.innerHTML;
|
|
|
|
|
2014-03-08 07:08:05 +01:00
|
|
|
if (newNotifications > lastNotifications)
|
2014-03-08 07:04:14 +01:00
|
|
|
{
|
|
|
|
var msg = (newNotifications - lastNotifications) + " new Notification(s)";
|
|
|
|
|
|
|
|
console.log(GM_info.script.name + ": Trying to set notification...", msg);
|
|
|
|
|
|
|
|
notificationInstance = new Notification("Google+ (" + newNotifications + ')',
|
|
|
|
{
|
|
|
|
"dir" : "auto",
|
|
|
|
"body" : msg,
|
2015-02-18 15:48:28 +01:00
|
|
|
"icon" : document.baseURI + "/favicon.ico",
|
2014-03-08 20:05:54 +01:00
|
|
|
"lang" : "en-US"
|
2014-03-08 07:04:14 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
lastNotifications = newNotifications;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
registerNotification = function()
|
|
|
|
{
|
|
|
|
Notification.requestPermission(function(grantedPermission){
|
|
|
|
if (grantedPermission === "granted")
|
|
|
|
{
|
|
|
|
console.log(GM_info.script.name + ": permission granted");
|
|
|
|
intervalID = setInterval(notify, timeout);
|
|
|
|
console.log(GM_info.script.name + ": intervalID: " + intervalID);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
console.log(GM_info.script.name + ": permission NOT granted");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Normal flow of operations below! */
|
|
|
|
if (!Notification)
|
|
|
|
{
|
|
|
|
alert("Notifications are not supported for this browser version yet.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
registerNotification();
|