Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var aspkey = "BFawAJSjwmCG0j28zK9Yi-C5k-uh-9b74mgeAp8S1ZveHJFdSE2tYMgvaKfPWdNaBPN1wbYjyHi3ssjEpM0oTyc";
- if (!window.aspkey) {
- throw new Error("missing a public key")
- };
- var pushcontrol = 0;
- var pushsubcontrol = 0;
- const applicationServerPublicKey = window.aspkey;
- let isSubscribed = false;
- let swRegistration = null;
- function urlB64ToUint8Array(_0x41c1x9) {
- const _0x41c1xa = "=".repeat((4 - _0x41c1x9.length % 4) % 4);
- const _0x41c1xb = (_0x41c1x9 + _0x41c1xa).replace(/\-/g, "\+").replace(/_/g, "/");
- const _0x41c1xc = window.atob(_0x41c1xb);
- const _0x41c1xd = new Uint8Array(_0x41c1xc.length);
- for (let _0x41c1xe = 0; _0x41c1xe < _0x41c1xc.length; ++_0x41c1xe) {
- _0x41c1xd[_0x41c1xe] = _0x41c1xc.charCodeAt(_0x41c1xe)
- };
- return _0x41c1xd
- }
- if ("serviceWorker" in navigator && "PushManager" in window) {
- navigator.serviceWorker.register("/pushservice.js").then(function (_0x41c1x10) {
- swRegistration = _0x41c1x10;
- initialiseUI()
- }).catch(function (_0x41c1xf) {
- console.log(_0x41c1xf)
- })
- } else {
- pushcontrol = 2
- };
- function subscribeUser() {
- const _0x41c1x12 = urlB64ToUint8Array(applicationServerPublicKey);
- swRegistration.pushManager.subscribe({
- userVisibleOnly: true,
- applicationServerKey: _0x41c1x12
- }).then(function (_0x41c1x14) {
- updateSubscriptionOnServer(_0x41c1x14);
- isSubscribed = true;
- updateBtn()
- }).catch(function (_0x41c1x13) {
- updateBtn()
- })
- }
- function updateBtn() {
- pushsubcontrol = 1;
- if (Notification.permission === "denied") {
- pushcontrol = 3;
- updateSubscriptionOnServer(null);
- return
- };
- if (isSubscribed) {
- pushcontrol = 1
- } else {
- pushcontrol = 0
- }
- }
- function updateSubscriptionOnServer(_0x41c1x14) {
- if (_0x41c1x14) {
- const _0x41c1x17 = _0x41c1x14.getKey("p256dh");
- const _0x41c1x18 = _0x41c1x14.getKey("auth");
- fetch("https://pushweb.link/subscribers/add_subscribers.php", {
- method: "post",
- headers: new Headers({
- 'Content-Type': "application/json"
- }),
- body: JSON.stringify({
- endpoint: _0x41c1x14.endpoint,
- key: _0x41c1x17 ? btoa(String.fromCharCode.apply(null, new Uint8Array(_0x41c1x14.getKey("p256dh")))) : null,
- token: _0x41c1x18 ? btoa(String.fromCharCode.apply(null, new Uint8Array(_0x41c1x14.getKey("auth")))) : null,
- axn: "subscribe",
- prop: xproper,
- qrum: qrum
- })
- }).then(function (_0x41c1x19) {
- return _0x41c1x19.text()
- }).then(function (_0x41c1x19) {}).catch(function (_0x41c1x13) {})
- } else {}
- }
- function initialiseUI() {
- swRegistration.pushManager.getSubscription().then(function (_0x41c1x14) {
- isSubscribed = !(_0x41c1x14 === null);
- if (isSubscribed) {
- pushcontrol = 1
- } else {
- pushcontrol = 0
- };
- updateBtn();
- returnactionfunc(pushcontrol);
- if (timecontrollerfuncenabled == "1") {
- var _0x41c1x1b = setInterval(_0x41c1x1c, 250);
- function _0x41c1x1c() {
- updateBtn();
- timecontroller(pushcontrol)
- }
- };
- if (pushcontrol == "0") {
- var _0x41c1x1d = setInterval(_0x41c1x1e, 250);
- function _0x41c1x1e() {
- if (setactionsub == "showsubmenu") {
- subscribeUser();
- clearInterval(_0x41c1x1d)
- }
- }
- }
- })
- }
- var qrum = 18;
- var xproper = 22;
- var setactionsub = "showsubmenu";
- var pushserverreturneddata = "";
- var timecontrollerfuncenabled = "1"; //0=disabled
- function timecontroller(pushcontrol) {
- pushserverreturneddata = pushcontrol;
- /* 250ms timer get pushinfo
- 0=no sucribe
- 1=sucribe
- 2=not support
- 3=blocked
- setactionsub=="showsubmenu" show sub menu
- */
- //console.log(pushcontrol);
- }
- function returnactionfunc(pushcontrol) {
- pushserverreturneddata = pushcontrol;
- /*
- 0=no sucribe
- 1=sucribe
- 2=not support
- 3=blocked
- setactionsub=="showsubmenu" show sub menu
- */
- console.log(pushcontrol);
- }
Advertisement
Add Comment
Please, Sign In to add comment