Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var focus = true;
  2. window.onfocus = function() {focus = true;};
  3. window.onblur = function() {focus = false;};
  4. MPP.client.ws.onmessage = function(message) {
  5.     if (typeof message.data === "string") {
  6.         message = JSON.parse(message.data);
  7.         if (message[0].m == "a") {
  8.             if (Notification.permission == "granted") {
  9.                 if (!focus) {
  10.                     new Notification("Message", {body: message[0].a});
  11.                 }
  12.             } else if (Notification !== "denied") {
  13.                 Notification.requestPermission(function (permission) {
  14.                     if (permission === "granted") {
  15.                         new Notification("Now I will annoy you.", {body: "It is true"});
  16.                     }
  17.                 });
  18.             }
  19.         }
  20.     }
  21. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement