Skip to content

Instantly share code, notes, and snippets.

@flavioso16
Created August 18, 2016 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flavioso16/fa0bcb969bf432f55cba1b255d441e3a to your computer and use it in GitHub Desktop.
Save flavioso16/fa0bcb969bf432f55cba1b255d441e3a to your computer and use it in GitHub Desktop.
self.addEventListener("push",function(a){a.waitUntil(self.registration.pushManager.getSubscription().then(function(a){var b=a&&a.subscriptionId?a.subscriptionId:a.endpoint.match(/([^\/]+)$/)&&RegExp.$1,c="https://apps.argos4.me/api/app/getNextChromeMessage?subscriptionId="+b;return fetch(c).then(function(a){if(200!==a.status)throw console.log("Looks like there was a problem. Status Code: "+a.status),new Error;return a.json().then(function(a){if(a)return console.log("Getting message id: "+a.id),self.registration.showNotification(a.title,{body:a.message,icon:a.iconURI,requireInteraction:!0,tag:a.tag,data:JSON.stringify({idNotification:a.id,subscriptionId:b,url:a.url})});throw console.log("Looks like there was a problem."),new Error})})}))}),self.addEventListener("notificationclick",function(a){console.log("On notification click: ",a.notification.tag),a.notification.close(),a.waitUntil(clients.matchAll({type:"window"}).then(function(b){for(var c=0;c<b.length;c++){var d=b[c];if("/"==d.url&&"focus"in d)return d.focus()}if(clients.openWindow&&(void 0!=a.notification.data||null!=a.notification.data)){var e=JSON.parse(a.notification.data);if(void 0!=e.idNotification||null!=e.idNotification){var f="https://apps.argos4.me/api/app/updateChromeMessage?subscriptionId="+e.subscriptionId+"&notificationId="+e.idNotification+"&statusChromeMessage=CLICKED";fetch(f,{method:"put"})}if(void 0!=e.url||null!=e.url)return clients.openWindow(decodeURIComponent(e.url))}}))});
@MKDan
Copy link

MKDan commented Oct 22, 2018

How this differs from https://gist.github.com/brandonrozek/0cf038df40a913fda655 ---------> Is this just the full code? And the above is a minification?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment