Advertisement
SSYT

FM Desktop Notifications

Apr 11th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Desktop notifications
  2. // SSYT power codes !
  3. (function(_, $) {
  4.     document.addEventListener('DOMContentLoaded', function () {
  5.         if (Notification.permission !== "granted")
  6.             Notification.requestPermission();
  7.     });
  8.  
  9.     function notif(list) {
  10.         if (!Notification) {
  11.             alert('Desktop notifications not available in your browser. Try Chromium.');
  12.             return;
  13.         }
  14.  
  15.         if (Notification.permission !== "granted")
  16.             Notification.requestPermission();
  17.         else {
  18.             switch(list)
  19.             {
  20.                 case 'pm': {
  21.                     var sad = $('div#submenu ul li a.mainmenu[href*="/privmsg?folder=inbox"]');
  22.                     if(sad.text().match(/\d+/g) == '1' && /\d*/.test(sad.text())) {
  23.                         console.log(sad.text());
  24.                         new Notification('FM Notification', {
  25.                             icon: 'http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png',
  26.                             body: "Ai "+ sad.text().match(/\d+/g) +" mesaje private noi !",
  27.                         });
  28.                     }
  29.                     break;
  30.                 }
  31.                
  32.                 case 'report': {
  33.                     var sad = $('div#submenu ul li a.mainmenu[href*="/privmsg?folder=inbox"]');
  34.                     if(sad.text().match(/\d+/g) == '1' && /\d*/.test(sad.text())) {
  35.                         console.log(sad.text());
  36.                         new Notification('FM Notification', {
  37.                             icon: 'http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png',
  38.                             body: "Ai "+ sad.text().match(/\d+/g) +" mesaje private noi !",
  39.                         });
  40.                     }
  41.                     break;
  42.                 }
  43.             }
  44.         }
  45.     };
  46.  
  47.     $(function(){notif('pm');notif('report');});
  48. }({}, jQuery));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement