Changeset 2505833
- Timestamp:
- 03/30/2021 10:02:45 AM (5 years ago)
- Location:
- emitto
- Files:
-
- 5 edited
-
readme.txt (modified) (1 diff)
-
trunk/emitto.php (modified) (1 diff)
-
trunk/includes/emitto-functions.php (modified) (1 diff)
-
trunk/public/popup.js (modified) (1 diff)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
emitto/readme.txt
r2505820 r2505833 4 4 Plugin URI: https://emitto.io/ 5 5 Author: https://producthive.io/ 6 Version: 2. 0.96 Version: 2.1.0 7 7 Text Domain: Emitto 8 8 License: GPL v2 or later -
emitto/trunk/emitto.php
r2505820 r2505833 5 5 Plugin URI: https://producthive.io 6 6 Author: https://producthive.io 7 Version: 2. 0.97 Version: 2.1.0 8 8 This program is free software: you can redistribute it and/or modify 9 9 it under the terms of the GNU General Public License as published by -
emitto/trunk/includes/emitto-functions.php
r2505820 r2505833 9 9 } 10 10 //Emitto - Core Functionality 11 define( 'MY_PLUGIN_VERSION', '2. 0.9' );11 define( 'MY_PLUGIN_VERSION', '2.1.0' ); 12 12 13 13 -
emitto/trunk/public/popup.js
r2505820 r2505833 478 478 479 479 function updateSubscriptionOnServer(subscription) { 480 console.log('enter update subscription on server'); 481 let browser = ''; 482 let os = ''; 483 let ip = ''; 484 let geolocation; 485 486 487 switch (navigator.platform) { 488 case 'Mac68K' || 'MacPPC' || 'MacIntel': 489 os = 'MacOS'; 490 break; 491 case 'MacPPC' : 492 os = 'MacOS'; 493 break; 494 case 'MacIntel': 495 os = 'MacOS'; 496 break; 497 case 'Win16' : 498 os = 'Windows'; 499 break; 500 case 'Win32' : 501 os = 'Windows'; 502 break; 503 case 'WinCE' : 504 os = 'Windows'; 505 break; 506 default : 507 os = navigator.platform 508 } 509 510 511 fetch('https://api.ipify.org/?format=json') 512 .then(res => res.json()) 513 .then(data => ip = data.ip) 514 .then(() => { 515 516 console.log('ip address: ', ip) 517 518 // fetch('http://ip-api.com/json/' + ip) 519 // .then(res => res.json()) 520 // .then(data => location.country = data.country) 521 // .then(data => location.city = data.city) 522 //.then(() => { 523 524 fetch('https://api.ipstack.com/' + ip + '?access_key=e2bbf0946bb04e9b05fc97110ce18fed&format=1') 525 526 .then(result => result.json()) 527 .then(data => { 528 // location.city = data.city; 529 // location.country = data.country_name; 530 geolocation = data 480 if (Notification.permission === "denied") { 481 console.log("Notifications for this website are blocked by browser options") 482 } else { 483 console.log('enter update subscription on server'); 484 let browser = ''; 485 let os = ''; 486 let ip = ''; 487 let geolocation; 488 489 490 switch (navigator.platform) { 491 case 'Mac68K' || 'MacPPC' || 'MacIntel': 492 os = 'MacOS'; 493 break; 494 case 'MacPPC' : 495 os = 'MacOS'; 496 break; 497 case 'MacIntel': 498 os = 'MacOS'; 499 break; 500 case 'Win16' : 501 os = 'Windows'; 502 break; 503 case 'Win32' : 504 os = 'Windows'; 505 break; 506 case 'WinCE' : 507 os = 'Windows'; 508 break; 509 default : 510 os = navigator.platform 511 } 512 513 514 fetch('https://api.ipify.org/?format=json') 515 .then(res => res.json()) 516 .then(data => ip = data.ip) 517 .then(() => { 518 519 console.log('ip address: ', ip) 520 521 // fetch('http://ip-api.com/json/' + ip) 522 // .then(res => res.json()) 523 // .then(data => location.country = data.country) 524 // .then(data => location.city = data.city) 525 //.then(() => { 526 527 fetch('https://api.ipstack.com/' + ip + '?access_key=e2bbf0946bb04e9b05fc97110ce18fed&format=1') 528 529 .then(result => result.json()) 530 .then(data => { 531 // location.city = data.city; 532 // location.country = data.country_name; 533 geolocation = data 534 } 535 ) 536 537 .then(() => { 538 539 browser = (function () { 540 let test = function (regexp) { 541 return regexp.test(window.navigator.userAgent); 542 } 543 switch (true) { 544 case test(/edg/i): 545 return "Edge"; 546 case test(/opr/i) && (!!window.opr || !!window.opera): 547 return "Opera"; 548 case test(/chrome/i) && !!window.chrome: 549 return "Chrome"; 550 case test(/trident/i): 551 return "Internet Explorer"; 552 case test(/firefox/i): 553 return "Firefox"; 554 case test(/safari/i): 555 return "Safari"; 556 default: 557 return "other"; 558 } 559 })(); 560 console.log('browser: ', browser) 561 console.log('geolocation: ', geolocation); 562 //subscription = JSON.stringify(subscription) 563 564 const origin = { 565 app: browser, 566 OS: os, 567 timezoneOffset: geolocation.time_zone.code, 568 timezoneName: geolocation.time_zone.id, 569 countryFlag: geolocation.location.country_flag, 570 country: geolocation.country_name, 571 city: geolocation.city, 572 favicon: faviconPic, 573 }; 574 575 subscription.origin = {} 576 console.log("subscription before json: ", subscription) 577 subscription = JSON.stringify(subscription); 578 console.log('subscription :', subscription); 579 let obj = JSON.parse(subscription); 580 obj.origin = origin 581 subscription = JSON.stringify(obj); 582 583 console.log('subscription :', subscription); 584 //console.log('subscription JSON:', JSON.stringify(subscription)); 585 586 587 fetch(base_uri_app + 'save-subscription/' + web_push_id, { 588 method: 'POST', 589 headers: { 590 'Content-Type': 'application/json', 591 'Accept': 'application/json' 592 }, 593 594 595 body: subscription 596 }) 597 .then(function (response) { 598 if (!response.ok) { 599 throw new Error('Bad status code from server.'); 600 } 601 return response.json(); 602 }) 603 .then(function (responseData) { 604 if (!(responseData && responseData.success)) { 605 throw new Error('Bad response from server.'); 606 } 607 }) 608 609 }) 610 .catch(function (error) { 611 const origin = { 612 app: browser, 613 OS: os, 614 timezoneOffset: '', 615 timezoneName: '', 616 countryFlag: '', 617 country: '', 618 city: '', 619 favicon: faviconPic, 620 }; 621 622 subscription.origin = {} 623 console.log("subscription before json: ", subscription) 624 subscription = JSON.stringify(subscription); 625 console.log('subscription :', subscription); 626 let obj = JSON.parse(subscription); 627 obj.origin = origin 628 subscription = JSON.stringify(obj); 629 630 console.log('subscription :', subscription); 631 //console.log('subscription JSON:', JSON.stringify(subscription)); 632 633 634 fetch(base_uri_app + 'save-subscription/' + web_push_id, { 635 method: 'POST', 636 headers: { 637 'Content-Type': 'application/json', 638 'Accept': 'application/json' 639 }, 640 641 642 body: subscription 643 }) 644 .then(function (response) { 645 if (!response.ok) { 646 throw new Error('Bad status code from server.'); 647 } 648 return response.json(); 649 }) 650 .then(function (responseData) { 651 if (!(responseData && responseData.success)) { 652 throw new Error('Bad response from server.'); 653 } 654 }) 655 656 }) 657 } 658 ) 659 .catch(function (error) { 660 console.log('error: ', error) 661 browser = (function () { 662 let test = function (regexp) { 663 return regexp.test(window.navigator.userAgent); 664 } 665 switch (true) { 666 case test(/edg/i): 667 return "Edge"; 668 case test(/opr/i) && (!!window.opr || !!window.opera): 669 return "Opera"; 670 case test(/chrome/i) && !!window.chrome: 671 return "Chrome"; 672 case test(/trident/i): 673 return "Internet Explorer"; 674 case test(/firefox/i): 675 return "Firefox"; 676 case test(/safari/i): 677 return "Safari"; 678 default: 679 return "other"; 680 } 681 })(); 682 console.log('browser: ', browser) 683 console.log('geolocation: ', geolocation); 684 //subscription = JSON.stringify(subscription) 685 686 const origin = { 687 app: browser, 688 OS: os, 689 timezoneOffset: '', 690 timezoneName: '', 691 countryFlag: '', 692 country: '', 693 city: '', 694 favicon: faviconPic, 695 }; 696 697 subscription.origin = {} 698 console.log("subscription before json: ", subscription) 699 subscription = JSON.stringify(subscription); 700 console.log('subscription :', subscription); 701 let obj = JSON.parse(subscription); 702 obj.origin = origin 703 subscription = JSON.stringify(obj); 704 705 console.log('subscription :', subscription); 706 //console.log('subscription JSON:', JSON.stringify(subscription)); 707 708 709 fetch(base_uri_app + 'save-subscription/' + web_push_id, { 710 method: 'POST', 711 headers: { 712 'Content-Type': 'application/json', 713 'Accept': 'application/json' 714 }, 715 716 717 body: subscription 718 }) 719 .then(function (response) { 720 if (!response.ok) { 721 throw new Error('Bad status code from server.'); 531 722 } 532 ) 533 534 .then(() => { 535 536 browser = (function () { 537 let test = function (regexp) { 538 return regexp.test(window.navigator.userAgent); 539 } 540 switch (true) { 541 case test(/edg/i): 542 return "Edge"; 543 case test(/opr/i) && (!!window.opr || !!window.opera): 544 return "Opera"; 545 case test(/chrome/i) && !!window.chrome: 546 return "Chrome"; 547 case test(/trident/i): 548 return "Internet Explorer"; 549 case test(/firefox/i): 550 return "Firefox"; 551 case test(/safari/i): 552 return "Safari"; 553 default: 554 return "other"; 555 } 556 })(); 557 console.log('browser: ', browser) 558 console.log('geolocation: ', geolocation); 559 //subscription = JSON.stringify(subscription) 560 561 const origin = { 562 app: browser, 563 OS: os, 564 timezoneOffset: geolocation.time_zone.code, 565 timezoneName: geolocation.time_zone.id, 566 countryFlag: geolocation.location.country_flag, 567 country: geolocation.country_name, 568 city: geolocation.city, 569 favicon: faviconPic, 570 }; 571 572 subscription.origin = {} 573 console.log("subscription before json: ", subscription) 574 subscription = JSON.stringify(subscription); 575 console.log('subscription :', subscription); 576 let obj = JSON.parse(subscription); 577 obj.origin = origin 578 subscription = JSON.stringify(obj); 579 580 console.log('subscription :', subscription); 581 //console.log('subscription JSON:', JSON.stringify(subscription)); 582 583 584 fetch(base_uri_app + 'save-subscription/' + web_push_id, { 585 method: 'POST', 586 headers: { 587 'Content-Type': 'application/json', 588 'Accept': 'application/json' 589 }, 590 591 592 body: subscription 593 }) 594 .then(function (response) { 595 if (!response.ok) { 596 throw new Error('Bad status code from server.'); 597 } 598 return response.json(); 599 }) 600 .then(function (responseData) { 601 if (!(responseData && responseData.success)) { 602 throw new Error('Bad response from server.'); 603 } 604 }) 605 723 return response.json(); 606 724 }) 607 .catch(function (error) { 608 const origin = { 609 app: browser, 610 OS: os, 611 timezoneOffset: '', 612 timezoneName: '', 613 countryFlag: '', 614 country: '', 615 city: '', 616 favicon: faviconPic, 617 }; 618 619 subscription.origin = {} 620 console.log("subscription before json: ", subscription) 621 subscription = JSON.stringify(subscription); 622 console.log('subscription :', subscription); 623 let obj = JSON.parse(subscription); 624 obj.origin = origin 625 subscription = JSON.stringify(obj); 626 627 console.log('subscription :', subscription); 628 //console.log('subscription JSON:', JSON.stringify(subscription)); 629 630 631 fetch(base_uri_app + 'save-subscription/' + web_push_id, { 632 method: 'POST', 633 headers: { 634 'Content-Type': 'application/json', 635 'Accept': 'application/json' 636 }, 637 638 639 body: subscription 640 }) 641 .then(function (response) { 642 if (!response.ok) { 643 throw new Error('Bad status code from server.'); 644 } 645 return response.json(); 646 }) 647 .then(function (responseData) { 648 if (!(responseData && responseData.success)) { 649 throw new Error('Bad response from server.'); 650 } 651 }) 652 725 .then(function (responseData) { 726 if (!(responseData && responseData.success)) { 727 throw new Error('Bad response from server.'); 728 } 653 729 }) 654 } 655 ) 656 .catch(function (error) { 657 console.log('error: ', error) 658 browser = (function () { 659 let test = function (regexp) { 660 return regexp.test(window.navigator.userAgent); 661 } 662 switch (true) { 663 case test(/edg/i): 664 return "Edge"; 665 case test(/opr/i) && (!!window.opr || !!window.opera): 666 return "Opera"; 667 case test(/chrome/i) && !!window.chrome: 668 return "Chrome"; 669 case test(/trident/i): 670 return "Internet Explorer"; 671 case test(/firefox/i): 672 return "Firefox"; 673 case test(/safari/i): 674 return "Safari"; 675 default: 676 return "other"; 677 } 678 })(); 679 console.log('browser: ', browser) 680 console.log('geolocation: ', geolocation); 681 //subscription = JSON.stringify(subscription) 682 683 const origin = { 684 app: browser, 685 OS: os, 686 timezoneOffset: '', 687 timezoneName: '', 688 countryFlag: '', 689 country: '', 690 city: '', 691 favicon: faviconPic, 692 }; 693 694 subscription.origin = {} 695 console.log("subscription before json: ", subscription) 696 subscription = JSON.stringify(subscription); 697 console.log('subscription :', subscription); 698 let obj = JSON.parse(subscription); 699 obj.origin = origin 700 subscription = JSON.stringify(obj); 701 702 console.log('subscription :', subscription); 703 //console.log('subscription JSON:', JSON.stringify(subscription)); 704 705 706 fetch(base_uri_app + 'save-subscription/' + web_push_id, { 707 method: 'POST', 708 headers: { 709 'Content-Type': 'application/json', 710 'Accept': 'application/json' 711 }, 712 713 714 body: subscription 730 715 731 }) 716 .then(function (response) { 717 if (!response.ok) { 718 throw new Error('Bad status code from server.'); 719 } 720 return response.json(); 721 }) 722 .then(function (responseData) { 723 if (!(responseData && responseData.success)) { 724 throw new Error('Bad response from server.'); 725 } 726 }) 727 728 }) 729 732 } 730 733 } 731 734 -
emitto/trunk/readme.txt
r2505820 r2505833 4 4 Plugin URI: https://emitto.io/ 5 5 Author: https://producthive.io/ 6 Version: 2. 0.96 Version: 2.1.0 7 7 Text Domain: Emitto 8 8 License: GPL v2 or later
Note: See TracChangeset
for help on using the changeset viewer.