Changeset 1543099
- Timestamp:
- 11/30/2016 07:16:35 AM (9 years ago)
- File:
-
- 1 edited
-
web-push-notifications-lite/trunk/js/sdk/init.js (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
web-push-notifications-lite/trunk/js/sdk/init.js
r1430511 r1543099 1 1 'use strict'; 2 2 3 4 3 5 var scripts = document.getElementsByTagName( "script" ) ; 6 4 7 var currentScriptUrl = ( document.currentScript || scripts[scripts.length] ).src ; 8 5 9 var scriptName = currentScriptUrl.length > 0 ? currentScriptUrl : scripts[scripts.length].baseURI.split( "/" ).pop() ; 10 6 11 var arr = scriptName.split('?'); 12 7 13 var params = arr[1]; 8 14 15 16 9 17 //document.getElementById('pushem-notification-https-sub').style.display = 'none'; 10 18 19 20 11 21 if ('serviceWorker' in navigator) { 12 22 13 navigator.serviceWorker.register('/wp-content/plugins/em_desktop_notifications/js/sdk/sw.js').then(function(reg) { 23 24 25 navigator.serviceWorker.register('/wp-content/plugins/web-push-notifications-lite/js/sdk/sw.js').then(function(reg) { 26 14 27 //console.log(':^)', reg); 28 15 29 //console.log('some'); 16 30 17 navigator.serviceWorker.getRegistration('/wp-content/plugins/em_desktop_notifications/js/sdk/sw.js').then(function(reg) { 31 32 33 navigator.serviceWorker.getRegistration('/wp-content/plugins/web-push-notifications-lite/js/sdk/sw.js').then(function(reg) { 34 18 35 reg.pushManager.getSubscription(reg).then(function(sub) { 19 36 37 38 20 39 //SET COOKIE, USE FOR ANONYMOUS 40 21 41 if (sub != null) { 42 22 43 var d = new Date(new Date().getTime() + 3600 * 1000 * 365); 44 23 45 document.cookie = "emdn_gcm_endpoint="+sub.endpoint+"; path=/; expires="+d; 46 24 47 //document.getElementById('pushem-notification-https-sub').style.display = 'block'; 48 25 49 } 50 26 51 //END OF COOKIE 27 52 53 54 28 55 var get_settings_line = 'https://pushem.org/api/sources/get_settings/?'+params; 29 56 57 58 30 59 fetch(get_settings_line).then(function(response) { 60 31 61 response.json().then(function(data) { 32 62 63 64 33 65 //console.log(data.source.mode); 66 34 67 if (sub == null) { 68 35 69 //console.log("Unsubed1"); 70 36 71 72 37 73 if (data.source.mode == 'auto') { 74 38 75 reg.pushManager.subscribe({ 76 39 77 userVisibleOnly: true 78 40 79 }).then(function(sub) { 41 80 81 82 42 83 //SET COOKIE, USE FOR ANONYMOUS 84 43 85 var d = new Date(new Date().getTime() + 3600 * 1000 * 365); 86 44 87 document.cookie = "emdn_gcm_endpoint="+sub.endpoint+"; path=/; expires="+d; 88 45 89 //END OF COOKIE 46 90 91 92 47 93 //console.log(sub); 94 48 95 //console.log('endpoint:', sub.endpoint); 96 49 97 98 50 99 document.getElementById('pushem-notification-https-unsub').innerHTML = data.source.unsubbtn; 100 51 101 document.getElementById('pushem-notification-https-unsub').style.display = 'block'; 52 102 103 104 53 105 document.getElementById('pushem-notification-https-msg').innerHTML = data.source.submsg; 106 54 107 document.getElementById('pushem-notification-https-msg').style.display = 'block'; 108 55 109 setTimeout(function() { document.getElementById('pushem-notification-https-msg').style.display = 'none' }, 2000); 110 56 111 112 57 113 var endpoint_line = "https://pushem.org/api/subscribers/add/?"+params+"&sub_endpoint="+sub.endpoint; 114 58 115 116 59 117 fetch(endpoint_line).then(function(response) { 60 118 119 120 61 121 }); 62 122 123 124 63 125 var httpunsubbtn = document.getElementById('pushem-notification-https-unsub'); 126 64 127 httpunsubbtn.style.cursor = 'pointer'; 128 65 129 httpunsubbtn.onclick = function() { 130 66 131 reg.pushManager.getSubscription(reg).then(function(sub) { 132 67 133 sub.unsubscribe().then(function(event) { 68 134 135 136 69 137 //SET COOKIE, USE FOR ANONYMOUS 138 70 139 var d = new Date(new Date().getTime() + 3600 * 1000 * 365); 140 71 141 var s = ""; 142 72 143 document.cookie = "emdn_gcm_endpoint="+s+"; path=/; expires="+d; 144 73 145 //END OF COOKIE 146 74 147 //console.log('Unsubed2'); 148 75 149 document.getElementById('pushem-notification-https-unsub').style.display = 'none'; 150 76 151 document.getElementById('pushem-notification-https-sub').style.display = 'block'; 77 152 153 154 78 155 document.getElementById('pushem-widget-https').style.display = 'none'; 156 79 157 document.getElementById('pushem-widget-https-bg').style.display = 'none'; 80 158 159 160 81 161 document.getElementById('pushem-notification-https-msg').innerHTML = data.source.unsubmsg; 162 82 163 document.getElementById('pushem-notification-https-msg').style.display = 'block'; 164 83 165 setTimeout(function() { document.getElementById('pushem-notification-https-msg').style.display = 'none' }, 2000); 84 166 167 168 85 169 var idget_line = "https://pushem.org/api/subscribers/get_by_endpoint/?"+params+"&sub_endpoint="+sub.endpoint; 170 86 171 172 87 173 //console.log(idget_line); 88 174 175 176 89 177 fetch(idget_line).then(function(response) { 178 90 179 response.json().then(function(data) { 91 180 181 182 92 183 var idremove_line = "https://pushem.org/api/subscribers/remove/?"+params+"&id="+data.subscriber.id; 184 93 185 fetch(idremove_line).then(function(response) { 94 186 187 188 95 189 }); 96 190 97 }); 98 }); 191 192 193 }); 194 195 }); 196 197 198 199 99 200 100 201 101 202 102 203 var httpsubbtn = document.getElementById('pushem-notification-https-sub'); 204 103 205 httpsubbtn.style.cursor = 'pointer'; 206 104 207 httpsubbtn.onclick = function() { 208 105 209 reg.pushManager.subscribe({ 210 106 211 userVisibleOnly: true 212 107 213 }).then(function(sub) { 108 214 215 216 109 217 //SET COOKIE, USE FOR ANONYMOUS 218 110 219 var d = new Date(new Date().getTime() + 3600 * 1000 * 365); 220 111 221 document.cookie = "emdn_gcm_endpoint="+sub.endpoint+"; path=/; expires="+d; 222 112 223 //END OF COOKIE 113 224 225 226 114 227 //console.log(sub); 228 115 229 //console.log('endpoint:', sub.endpoint); 116 230 231 232 117 233 document.getElementById('pushem-notification-https-sub').style.display = 'none'; 234 118 235 document.getElementById('pushem-notification-https-unsub').style.display = 'block'; 119 236 237 238 120 239 document.getElementById('pushem-widget-https').style.display = 'none'; 240 121 241 document.getElementById('pushem-widget-https-bg').style.display = 'none'; 122 242 243 244 123 245 document.getElementById('pushem-notification-https-msg').innerHTML = data.source.submsg; 246 124 247 document.getElementById('pushem-notification-https-msg').style.display = 'block'; 248 125 249 setTimeout(function() { document.getElementById('pushem-notification-https-msg').style.display = 'none' }, 2000); 126 250 251 252 127 253 var endpoint_line = "https://pushem.org/api/subscribers/add/?"+params+"&sub_endpoint="+sub.endpoint; 128 254 255 256 129 257 fetch(endpoint_line).then(function(response) { 130 258 131 }); 259 260 261 }); 262 263 132 264 133 265 }); 266 134 267 }; 135 268 136 269 137 }); 270 271 272 273 }); 274 138 275 }); 276 139 277 }; 140 278 279 280 141 281 }); 282 142 283 } else { 284 143 285 document.getElementById('pushem-notification-https-sub').innerHTML = data.source.subbtn; 286 144 287 document.getElementById('pushem-notification-https-sub').style.display = 'block'; 145 288 289 290 146 291 var httpsubbtn = document.getElementById('pushem-notification-https-sub'); 292 147 293 httpsubbtn.style.cursor = 'pointer'; 294 148 295 httpsubbtn.onclick = function() { 296 149 297 reg.pushManager.subscribe({ 298 150 299 userVisibleOnly: true 300 151 301 }).then(function(sub) { 152 302 303 304 153 305 //SET COOKIE, USE FOR ANONYMOUS 306 154 307 var d = new Date(new Date().getTime() + 3600 * 1000 * 365); 308 155 309 document.cookie = "emdn_gcm_endpoint="+sub.endpoint+"; path=/; expires="+d; 310 156 311 //END OF COOKIE 157 312 313 314 158 315 //console.log(sub); 316 159 317 //console.log('endpoint:', sub.endpoint); 160 318 319 320 161 321 document.getElementById('pushem-notification-https-sub').style.display = 'none'; 322 162 323 document.getElementById('pushem-notification-https-unsub').style.display = 'block'; 163 324 325 326 164 327 document.getElementById('pushem-widget-https').style.display = 'none'; 328 165 329 document.getElementById('pushem-widget-https-bg').style.display = 'none'; 166 330 331 332 167 333 document.getElementById('pushem-notification-https-msg').innerHTML = data.source.submsg; 334 168 335 document.getElementById('pushem-notification-https-msg').style.display = 'block'; 336 169 337 setTimeout(function() { document.getElementById('pushem-notification-https-msg').style.display = 'none' }, 2000); 170 338 339 340 171 341 var endpoint_line = "https://pushem.org/api/subscribers/add/?"+params+"&sub_endpoint="+sub.endpoint; 172 342 343 344 173 345 fetch(endpoint_line).then(function(response) { 174 346 175 }); 347 348 349 }); 350 351 352 353 354 355 356 176 357 177 358 … … 181 362 182 363 var httpunsubbtn = document.getElementById('pushem-notification-https-unsub'); 364 183 365 httpunsubbtn.style.cursor = 'pointer'; 366 184 367 httpunsubbtn.onclick = function() { 368 185 369 reg.pushManager.getSubscription(reg).then(function(sub) { 370 186 371 sub.unsubscribe().then(function(event) { 187 372 373 374 188 375 //SET COOKIE, USE FOR ANONYMOUS 376 189 377 var d = new Date(new Date().getTime() + 3600 * 1000 * 365); 378 190 379 var s = ""; 380 191 381 document.cookie = "emdn_gcm_endpoint="+s+"; path=/; expires="+d; 382 192 383 //END OF COOKIE 384 193 385 //console.log('Unsubed2'); 386 194 387 document.getElementById('pushem-notification-https-unsub').style.display = 'none'; 388 195 389 document.getElementById('pushem-notification-https-sub').style.display = 'block'; 196 390 391 392 197 393 document.getElementById('pushem-widget-https').style.display = 'none'; 394 198 395 document.getElementById('pushem-widget-https-bg').style.display = 'none'; 199 396 397 398 200 399 document.getElementById('pushem-notification-https-msg').innerHTML = data.source.unsubmsg; 400 201 401 document.getElementById('pushem-notification-https-msg').style.display = 'block'; 402 202 403 setTimeout(function() { document.getElementById('pushem-notification-https-msg').style.display = 'none' }, 2000); 203 404 405 406 204 407 var idget_line = "https://pushem.org/api/subscribers/get_by_endpoint/?"+params+"&sub_endpoint="+sub.endpoint; 408 205 409 410 206 411 //console.log(idget_line); 207 412 413 414 208 415 fetch(idget_line).then(function(response) { 416 209 417 response.json().then(function(data) { 210 418 419 420 211 421 var idremove_line = "https://pushem.org/api/subscribers/remove/?"+params+"&id="+data.subscriber.id; 422 212 423 fetch(idremove_line).then(function(response) { 213 424 425 426 214 427 }); 215 428 216 }); 217 }); 429 430 431 }); 432 433 }); 434 435 436 437 218 438 219 439 220 440 221 441 var httpsubbtn = document.getElementById('pushem-notification-https-sub'); 442 222 443 httpsubbtn.style.cursor = 'pointer'; 444 223 445 httpsubbtn.onclick = function() { 446 224 447 reg.pushManager.subscribe({ 448 225 449 userVisibleOnly: true 450 226 451 }).then(function(sub) { 227 452 453 454 228 455 //SET COOKIE, USE FOR ANONYMOUS 456 229 457 var d = new Date(new Date().getTime() + 3600 * 1000 * 365); 458 230 459 document.cookie = "emdn_gcm_endpoint="+sub.endpoint+"; path=/; expires="+d; 460 231 461 //END OF COOKIE 232 462 463 464 233 465 //console.log(sub); 466 234 467 //console.log('endpoint:', sub.endpoint); 235 468 469 470 236 471 document.getElementById('pushem-notification-https-sub').style.display = 'none'; 472 237 473 document.getElementById('pushem-notification-https-unsub').style.display = 'block'; 238 474 475 476 239 477 document.getElementById('pushem-widget-https').style.display = 'none'; 478 240 479 document.getElementById('pushem-widget-https-bg').style.display = 'none'; 241 480 481 482 242 483 document.getElementById('pushem-notification-https-msg').innerHTML = data.source.submsg; 484 243 485 document.getElementById('pushem-notification-https-msg').style.display = 'block'; 486 244 487 setTimeout(function() { document.getElementById('pushem-notification-https-msg').style.display = 'none' }, 2000); 245 488 489 490 246 491 var endpoint_line = "https://pushem.org/api/subscribers/add/?"+params+"&sub_endpoint="+sub.endpoint; 247 492 493 494 248 495 fetch(endpoint_line).then(function(response) { 249 496 250 }); 497 498 499 }); 500 501 251 502 252 503 }); 504 253 505 }; 254 506 255 507 256 }); 508 509 510 511 }); 512 257 513 }); 514 258 515 }; 259 516 … … 267 524 268 525 526 527 528 529 530 531 532 533 534 535 536 269 537 }); 538 270 539 }; 540 271 541 } 272 542 543 544 273 545 } else { 546 274 547 //console.log("Subed", sub.endpoint); 548 275 549 //console.log(data.source.unsubbtn); 550 276 551 document.getElementById('pushem-notification-https-unsub').innerHTML = data.source.unsubbtn; 552 277 553 document.getElementById('pushem-notification-https-unsub').style.display = 'block'; 278 554 555 556 279 557 var httpunsubbtn = document.getElementById('pushem-notification-https-unsub'); 558 280 559 httpunsubbtn.style.cursor = 'pointer'; 560 281 561 httpunsubbtn.onclick = function() { 562 282 563 reg.pushManager.getSubscription(reg).then(function(sub) { 564 283 565 sub.unsubscribe().then(function(event) { 284 566 567 568 285 569 //SET COOKIE, USE FOR ANONYMOUS 570 286 571 var d = new Date(new Date().getTime() + 3600 * 1000 * 365); 572 287 573 var s = ""; 574 288 575 document.cookie = "emdn_gcm_endpoint="+s+"; path=/; expires="+d; 576 289 577 //END OF COOKIE 290 578 579 580 291 581 //console.log('Unsubed3'); 582 292 583 document.getElementById('pushem-notification-https-unsub').style.display = 'none'; 584 293 585 document.getElementById('pushem-notification-https-sub').style.display = 'block'; 294 586 587 588 295 589 document.getElementById('pushem-widget-https').style.display = 'none'; 590 296 591 document.getElementById('pushem-widget-https-bg').style.display = 'none'; 297 592 593 594 298 595 document.getElementById('pushem-notification-https-msg').innerHTML = data.source.unsubmsg; 596 299 597 document.getElementById('pushem-notification-https-msg').style.display = 'block'; 598 300 599 setTimeout(function() { document.getElementById('pushem-notification-https-msg').style.display = 'none' }, 2000); 301 600 601 602 302 603 var idget_line = "https://pushem.org/api/subscribers/get_by_endpoint/?"+params+"&sub_endpoint="+sub.endpoint; 604 303 605 606 304 607 //console.log(idget_line); 305 608 609 610 306 611 fetch(idget_line).then(function(response) { 612 307 613 response.json().then(function(data) { 308 614 615 616 309 617 var idremove_line = "https://pushem.org/api/subscribers/remove/?"+params+"&id="+data.subscriber.id; 618 310 619 fetch(idremove_line).then(function(response) { 311 620 621 622 312 623 }); 313 624 314 }); 315 }); 625 626 627 }); 628 629 }); 630 631 632 633 316 634 317 635 318 636 319 637 var httpsubbtn = document.getElementById('pushem-notification-https-sub'); 638 320 639 httpsubbtn.style.cursor = 'pointer'; 640 321 641 httpsubbtn.onclick = function() { 642 322 643 reg.pushManager.subscribe({ 644 323 645 userVisibleOnly: true 646 324 647 }).then(function(sub) { 325 648 649 650 326 651 //SET COOKIE, USE FOR ANONYMOUS 652 327 653 var d = new Date(new Date().getTime() + 3600 * 1000 * 365); 654 328 655 document.cookie = "emdn_gcm_endpoint="+sub.endpoint+"; path=/; expires="+d; 656 329 657 //END OF COOKIE 330 658 659 660 331 661 //console.log(sub); 662 332 663 //console.log('endpoint:', sub.endpoint); 333 664 665 666 334 667 document.getElementById('pushem-notification-https-sub').style.display = 'none'; 668 335 669 document.getElementById('pushem-notification-https-unsub').style.display = 'block'; 336 670 671 672 337 673 document.getElementById('pushem-widget-https').style.display = 'none'; 674 338 675 document.getElementById('pushem-widget-https-bg').style.display = 'none'; 339 676 677 678 340 679 document.getElementById('pushem-notification-https-msg').innerHTML = data.source.submsg; 680 341 681 document.getElementById('pushem-notification-https-msg').style.display = 'block'; 682 342 683 setTimeout(function() { document.getElementById('pushem-notification-https-msg').style.display = 'none' }, 2000); 343 684 685 686 344 687 var endpoint_line = "https://pushem.org/api/subscribers/add/?"+params+"&sub_endpoint="+sub.endpoint; 345 688 689 690 346 691 fetch(endpoint_line).then(function(response) { 347 692 348 }); 693 694 695 }); 696 697 349 698 350 699 }); 700 351 701 }; 352 702 353 703 354 }); 704 705 706 707 }); 708 355 709 }); 710 356 711 }; 357 712 713 714 358 715 } 716 359 717 }); 718 360 719 }); 720 361 721 }); 722 362 723 }); 363 724 725 726 364 727 }).catch(function(error) { 728 365 729 //console.log(':^(', error); 730 366 731 }); 367 732 733 734 368 735 } 369 736 737 738
Note: See TracChangeset
for help on using the changeset viewer.