diff --git a/config/userdata.js.example b/config/userdata.js.example
index c16c899..ffe60e1 100644
--- a/config/userdata.js.example
+++ b/config/userdata.js.example
@@ -7,5 +7,6 @@ var userInfo = {
userFollow: true,
gMapsAPIKey: "YOUR_API_KEY_HERE",
botPath: true,
- actionsEnabled: false
+ actionsEnabled: false,
+ pushEnabled: true
};
diff --git a/index.html b/index.html
index fc04c61..3fd5f81 100644
--- a/index.html
+++ b/index.html
@@ -61,6 +61,18 @@
+
+
+ Push notifications
+
+
+
+
Logs
diff --git a/js/main.js b/js/main.js
index 10ab923..7eae570 100644
--- a/js/main.js
+++ b/js/main.js
@@ -201,6 +201,16 @@ var mapView = {
$('#switchPan').prop('checked', self.settings.userFollow);
$('#switchZoom').prop('checked', self.settings.userZoom);
$('#strokeOn').prop('checked', self.settings.botPath);
+ $('#pushOn').prop('checked', self.settings.pushEnabled);
+
+ $('#pushOn').change(function() {
+ self.settings.pushEnabled = this.checked;
+ if (this.checked && Notification.permission !== "granted" ) {
+ Notification.requestPermission();
+ } else {
+ self.settings.pushEnabled = false;
+ }
+ });
$('#switchPan').change(function() {
if (this.checked) {
@@ -470,6 +480,7 @@ var mapView = {
message: "[" + self.settings.users[user_index] + "] " + poke_name + " appeared",
color: "green-text"
});
+ self.notify( 'Pokemon status', poke_name + ' appeared' );
user.catchables[data.spawnpoint_id] = new google.maps.Marker({
map: self.map,
position: {
@@ -509,6 +520,7 @@ var mapView = {
self.log({
message: "[" + self.settings.users[user_index] + "] " + poke_name + " has been caught or fled"
});
+ self.notify( 'Pokemon status', poke_name + ' caught (or fled)' );
for (var key in user.catchables) {
user.catchables[key].setMap(null);
}
@@ -1018,7 +1030,33 @@ var mapView = {
}
}
return level;
- }
+ },
+ notify: function(title, message) {
+ var self = this;
+ // Only show notification if enabled
+ if (self.settings.pushEnabled && Notification.permission == "granted") {
+
+ // Bind notification
+ self.settings.notification = new Notification(title, {
+ body: message
+ });
+
+ // Bind onclick event
+ self.settings.notification.onclick(function() {
+ window.open(window.location.href);
+ });
+
+ } else {
+ console.log( 'Notification: ' + title + ' with message:"' + message + '" has not been send to the client.');
+ console.log( 'Reason: ' );
+ if( !self.settings.pushEnabled ) {
+ console.log( 'Push is not enabled' );
+ } else if (Notification.permission !== 'granted') {
+ console.log( 'Push is not permitted' );
+ }
+ }
+
+ }
};
if (!String.prototype.format) {