🏠 Home 

Microsoft Calendar Notifications

Creates browser notifications for the Web-based Outlook-Calendar application. Useful in Linux (in Linux notifications do not work). Tested in Chrome 66.


Install this script?
  1. // ==UserScript==
  2. // @name Microsoft Calendar Notifications
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Creates browser notifications for the Web-based Outlook-Calendar application. Useful in Linux (in Linux notifications do not work). Tested in Chrome 66.
  6. // @author David López Castellote
  7. // @match https://outlook.office.com/*
  8. // @grant none
  9. // ==/UserScript==
  10. (function() {
  11. 'use strict';
  12. var allowNotification = true;
  13. function notifyMe( event ) {
  14. // Let's check if the browser supports notifications
  15. if (!("Notification" in window)) {
  16. alert("Este navegador no soporta notificaciones de escritorio.");
  17. }
  18. // Let's check whether notification permissions have already been granted
  19. else if (Notification.permission === "granted") {
  20. // If it's okay let's create a notification
  21. createNotification( event );
  22. }
  23. // Otherwise, we need to ask the user for permission
  24. else if (Notification.permission !== "denied") {
  25. Notification.requestPermission(function(permission) {
  26. // If the user accepts, let's create a notification
  27. if (permission === "granted") {
  28. createNotification( event );
  29. }
  30. });
  31. }
  32. }
  33. function createNotification( event ) {
  34. var title = "Calendar";
  35. var options = {
  36. body: event,
  37. icon: 'https://raw.githubusercontent.com/Dellos7/nav-favicon/master/ms-calendar-favicon.ico',
  38. requireInteraction: true
  39. };
  40. var notification = new Notification(title, options);
  41. notification.onclick = function() {
  42. window.focus();
  43. };
  44. }
  45. function setTitleObserver() {
  46. console.log('Activando notificaciones de Calendar...');
  47. requestNotificationsPermission( function() {
  48. console.log("DOM fully loaded and parsed");
  49. setTimeout( function() {
  50. console.log('CALENDAR TARGET');
  51. var target = document.querySelector('.o365cs-notifications-notificationPopupArea');
  52. console.log(target);
  53. var observer = new window.WebKitMutationObserver(function(mutations) {
  54. mutations.forEach(function(mutation) {
  55. console.log(mutation);
  56. var target = mutation.target;
  57. if (document.hidden && target.nodeName === 'DIV' && target.offsetParent.className === 'o365cs-notifications-notificationPopup ms-bcl-nl' && allowNotification) {
  58. allowNotification = false;
  59. console.log('NOTIFICATION: ' + target.innerText);
  60. notifyMe( target.innerText );
  61. setTimeout( function() {
  62. allowNotification = true;
  63. }, 1000 );
  64. return false;
  65. }
  66. });
  67. });
  68. observer.observe(target, {
  69. subtree: true,
  70. characterData: true,
  71. childList: true
  72. });
  73. }, 5000);
  74. });
  75. }
  76. function requestNotificationsPermission( callback ) {
  77. Notification.requestPermission().then(function(r###lt) {
  78. console.log('Permiso para notificaciones de Calendar: ' + r###lt);
  79. callback();
  80. });
  81. }
  82. setTitleObserver();
  83. })();