From 7e7a6eb86ae951127184781e1935047729a1e91d Mon Sep 17 00:00:00 2001 From: Tobias Schmidl Date: Sat, 8 Mar 2014 07:04:14 +0100 Subject: [PATCH] Added Greasemonkey script for Google+ --- googleplus-notification.user.js | 72 +++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 googleplus-notification.user.js diff --git a/googleplus-notification.user.js b/googleplus-notification.user.js new file mode 100644 index 0000000..1be0026 --- /dev/null +++ b/googleplus-notification.user.js @@ -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();