Added Greasemonkey script for Google+

This commit is contained in:
Tobias Schmidl 2014-03-08 07:04:14 +01:00
parent a9cbc11984
commit 7e7a6eb86a

View file

@ -0,0 +1,72 @@
// ==UserScript==
// @name Google+ desktop notification
// @namespace https://www.schtobia.de/
// @version 0.1.0
// @description Google+ desktop notification (based on HTML5)
// @include http*://plus.google.com/*
// @include http*://encrypted.google.com/*
// @include http*://google.com/*
// @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()
{
newNotifications = notificationsElement.innerHTML;
if (newNotifications > lastNotifications )
{
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,
"icon" : "https://ssl.gstatic.com/s2/oz/images/faviconr3.ico"
}
)
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();