|
// ==UserScript== |
|
// @name Sad Web App Notifier |
|
// @namespace https://gist.github.com/codesourceress/ |
|
// @version 1 |
|
// @description Bring the necessary Desktop Notification to Outlook Web App. |
|
// @author Michaela Elschner |
|
// @match https://outlook.office.com/owa/* |
|
// @exclude */manifests/* |
|
// @grant none |
|
// ==/UserScript== |
|
|
|
console.log('Start Sad Web App Notifier'); |
|
if (!("Notification" in window)) { |
|
alert("This browser does not support desktop notification. Sad Web App Notifier will not work."); |
|
} else { |
|
Notification.requestPermission(); |
|
var BoxName = getBoxName(); |
|
checkForNewMail(); |
|
} |
|
|
|
function getBoxName(){ |
|
var name = document.URL.match(/\/([^@\/]+@[^@\/]+)\//); |
|
return name ? name[1] : false; |
|
} |
|
|
|
function checkForNewMail(){ |
|
var calendarNotification = document.getElementsByClassName('o365cs-notifications-reminders-title')[0]; |
|
if (!calendarNotification) { |
|
console.log('No calendar notification'); |
|
} else { |
|
console.log('New calendar notification!'); |
|
spawnNotification('', 'You have new calendar notification!'); |
|
} |
|
|
|
var newMailNote = document.getElementsByClassName('o365cs-notifications-newMailPopupButtonContent')[0]; |
|
if(!newMailNote) { |
|
console.log('No new mail'); |
|
} else { |
|
console.log('New mail!'); |
|
spawnNotification('', 'You have new mail!'); |
|
} |
|
setTimeout(checkForNewMail, 5000); |
|
} |
|
|
|
function spawnNotification(body, title){ |
|
if(BoxName) title += ' ('+BoxName+')'; |
|
var options = { |
|
body: body, |
|
icon: 'https://openclipart.org/image/128px/svg_to_png/214764/1424701298.png' |
|
} |
|
return new Notification(title, options); |
|
} |
So, the principle is quite simple: Periodically check for the outlook notification box in the web app... and then turn that into a desktop notification.
Improvements: