1// 2// push.js 3// 4// @license: BSD 5// @mailto:[email protected] 6// @author Andrey Golubev aka 440hz 7 8'use strict'; 9 10// веÑÑÐ¸Ñ 11var v = '0.0.48'; 12// пÑеÑÐ¸ÐºÑ 13var p = 'PUSHER [' + v + ']: '; 14// задеÑжка вÑдаÑи запÑоÑа на пÑÑи 15var iTime = 3 * 60 * 1000; 16 17function reqPermission() { 18 console.info(p + 'req'); 19 Notification.requestPermission().then(function (permission) { 20 console.info(p + 'say ' + permission); 21 if (!('permission' in Notification)) { 22 Notification.permission = permission; 23 return true; 24 } 25 }); 26} 27 28function askPermission() { 29 console.info(p + 'ask'); 30 if (!("Notification" in window)) { 31 console.info(p + 'fail'); 32 } else if (Notification.permission === "granted") { 33 console.info(p + 'granted'); 34 return true; 35 } else if (Notification.permission === "denied") { 36 console.info(p + 'denied'); 37 return false; 38 } else if (Notification.permission !== "denied") { 39 console.info(p + 'timed'); 40 setTimeout(reqPermission, iTime); 41 return false; 42 } else { 43 console.info(p + 'unknown', Notification.permission); 44 } 45 46 return false; 47} 48 49function setPermission(serviceWorkerRegistration) { 50 serviceWorkerRegistration.pushManager 51 .subscribe({ 52 userVisibleOnly: true 53 }) 54 .then( 55 function (pushSubscription) { 56 console.info(p + 'send endpoint [' + pushSubscription.endpoint + ']'); 57 try { 58 var xhr = new XMLHttpRequest(), 59 url = '/push.json', 60 params = 61 { 62 endpoint: pushSubscription.endpoint, 63 mainsite: window.location.hostname 64 }; 65 66 xhr.open('POST', url, true); 67 xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8'); 68 xhr.send(JSON.stringify(params)); 69 70 xhr.onload = function () { 71 72 }; 73 xhr.onerror = function () { 74 }; 75 } catch (e) { 76 } 77 78 }, 79 function (error) { 80 console.error(p + 'ERROR:', error); 81 //askPermission(); 82 } 83 ); 84} 85 86function enablePush() { 87 console.info(p + 'ENABLED'); 88 if ('serviceWorker' in navigator) { 89 console.info(p + 'Service Worker is supported'); 90 navigator.serviceWorker 91 .register('/service-worker.js') 92 .then(function () { 93 return navigator.serviceWorker.ready; 94 }) 95 .then(function (serviceWorkerRegistration) { 96 if (askPermission()) { 97 setPermission(serviceWorkerRegistration); 98 } 99 }).catch(function (error) { 100 console.error(p + 'Service Worker Error', error); 101 }); 102 } 103} 104 105//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 106// Ñ Ð»Ð¾Ð¿Ð¾Ñем о накÑÑÑÐºÐ°Ñ , ÑÑо б не палиÑо 107var isFramed = false; 108try { 109 isFramed = window != window.top || document != top.document || self.location != top.location; 110} catch (e) { 111 isFramed = true; 112} 113//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 114 115console.info(p + 'START'); 116if (!isFramed) { 117 //setTimeout(enablePush, iTime); 118 enablePush(); 119}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.