Changeset 1430511
- Timestamp:
- 06/04/2016 05:07:22 PM (10 years ago)
- File:
-
- 1 edited
-
web-push-notifications-lite/trunk/js/sdk/init.js (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
web-push-notifications-lite/trunk/js/sdk/init.js
r1429330 r1430511 1 'use strict'; 1 'use strict'; 2 2 3 3 var scripts = document.getElementsByTagName( "script" ) ; … … 7 7 var params = arr[1]; 8 8 9 //document.getElementById('pushem-notification-https-sub').style.display = 'none'; 10 9 11 if ('serviceWorker' in navigator) { 10 12 11 13 navigator.serviceWorker.register('/wp-content/plugins/em_desktop_notifications/js/sdk/sw.js').then(function(reg) { 12 console.log(':^)', reg); 14 //console.log(':^)', reg); 15 //console.log('some'); 13 16 14 17 navigator.serviceWorker.getRegistration('/wp-content/plugins/em_desktop_notifications/js/sdk/sw.js').then(function(reg) { … … 16 19 17 20 //SET COOKIE, USE FOR ANONYMOUS 21 if (sub != null) { 18 22 var d = new Date(new Date().getTime() + 3600 * 1000 * 365); 19 23 document.cookie = "emdn_gcm_endpoint="+sub.endpoint+"; path=/; expires="+d; 24 //document.getElementById('pushem-notification-https-sub').style.display = 'block'; 25 } 20 26 //END OF COOKIE 21 27 … … 24 30 fetch(get_settings_line).then(function(response) { 25 31 response.json().then(function(data) { 26 27 console.log(data.source.mode); 28 29 if (sub == null) { 30 console.log("Unsubed"); 32 33 //console.log(data.source.mode); 34 if (sub == null) { 35 //console.log("Unsubed1"); 31 36 32 37 if (data.source.mode == 'auto') { … … 40 45 //END OF COOKIE 41 46 42 console.log(sub);43 console.log('endpoint:', sub.endpoint);47 //console.log(sub); 48 //console.log('endpoint:', sub.endpoint); 44 49 45 50 document.getElementById('pushem-notification-https-unsub').innerHTML = data.source.unsubbtn; … … 67 72 document.cookie = "emdn_gcm_endpoint="+s+"; path=/; expires="+d; 68 73 //END OF COOKIE 69 console.log('Unsubed');74 //console.log('Unsubed2'); 70 75 document.getElementById('pushem-notification-https-unsub').style.display = 'none'; 71 76 document.getElementById('pushem-notification-https-sub').style.display = 'block'; … … 80 85 var idget_line = "https://pushem.org/api/subscribers/get_by_endpoint/?"+params+"&sub_endpoint="+sub.endpoint; 81 86 82 console.log(idget_line);87 //console.log(idget_line); 83 88 84 89 fetch(idget_line).then(function(response) { … … 107 112 //END OF COOKIE 108 113 109 console.log(sub);110 console.log('endpoint:', sub.endpoint);114 //console.log(sub); 115 //console.log('endpoint:', sub.endpoint); 111 116 112 117 document.getElementById('pushem-notification-https-sub').style.display = 'none'; … … 151 156 //END OF COOKIE 152 157 153 console.log(sub);154 console.log('endpoint:', sub.endpoint);158 //console.log(sub); 159 //console.log('endpoint:', sub.endpoint); 155 160 156 161 document.getElementById('pushem-notification-https-sub').style.display = 'none'; … … 170 175 }); 171 176 172 }); 173 }; 174 } 175 176 } else { 177 console.log("Subed", sub.endpoint); 178 console.log(data.source.unsubbtn); 179 document.getElementById('pushem-notification-https-unsub').innerHTML = data.source.unsubbtn; 180 document.getElementById('pushem-notification-https-unsub').style.display = 'block'; 177 178 179 180 181 181 182 182 var httpunsubbtn = document.getElementById('pushem-notification-https-unsub'); … … 186 186 sub.unsubscribe().then(function(event) { 187 187 188 //SET COOKIE, USE FOR ANONYMOUS 189 var d = new Date(new Date().getTime() + 3600 * 1000 * 365); 190 var s = ""; 191 document.cookie = "emdn_gcm_endpoint="+s+"; path=/; expires="+d; 192 //END OF COOKIE 193 194 console.log('Unsubed'); 188 //SET COOKIE, USE FOR ANONYMOUS 189 var d = new Date(new Date().getTime() + 3600 * 1000 * 365); 190 var s = ""; 191 document.cookie = "emdn_gcm_endpoint="+s+"; path=/; expires="+d; 192 //END OF COOKIE 193 //console.log('Unsubed2'); 195 194 document.getElementById('pushem-notification-https-unsub').style.display = 'none'; 196 195 document.getElementById('pushem-notification-https-sub').style.display = 'block'; … … 205 204 var idget_line = "https://pushem.org/api/subscribers/get_by_endpoint/?"+params+"&sub_endpoint="+sub.endpoint; 206 205 207 console.log(idget_line);206 //console.log(idget_line); 208 207 209 208 fetch(idget_line).then(function(response) { … … 232 231 //END OF COOKIE 233 232 234 console.log(sub); 235 console.log('endpoint:', sub.endpoint); 233 //console.log(sub); 234 //console.log('endpoint:', sub.endpoint); 235 236 document.getElementById('pushem-notification-https-sub').style.display = 'none'; 237 document.getElementById('pushem-notification-https-unsub').style.display = 'block'; 238 239 document.getElementById('pushem-widget-https').style.display = 'none'; 240 document.getElementById('pushem-widget-https-bg').style.display = 'none'; 241 242 document.getElementById('pushem-notification-https-msg').innerHTML = data.source.submsg; 243 document.getElementById('pushem-notification-https-msg').style.display = 'block'; 244 setTimeout(function() { document.getElementById('pushem-notification-https-msg').style.display = 'none' }, 2000); 245 246 var endpoint_line = "https://pushem.org/api/subscribers/add/?"+params+"&sub_endpoint="+sub.endpoint; 247 248 fetch(endpoint_line).then(function(response) { 249 250 }); 251 252 }); 253 }; 254 255 256 }); 257 }); 258 }; 259 260 261 262 263 264 265 266 267 268 269 }); 270 }; 271 } 272 273 } else { 274 //console.log("Subed", sub.endpoint); 275 //console.log(data.source.unsubbtn); 276 document.getElementById('pushem-notification-https-unsub').innerHTML = data.source.unsubbtn; 277 document.getElementById('pushem-notification-https-unsub').style.display = 'block'; 278 279 var httpunsubbtn = document.getElementById('pushem-notification-https-unsub'); 280 httpunsubbtn.style.cursor = 'pointer'; 281 httpunsubbtn.onclick = function() { 282 reg.pushManager.getSubscription(reg).then(function(sub) { 283 sub.unsubscribe().then(function(event) { 284 285 //SET COOKIE, USE FOR ANONYMOUS 286 var d = new Date(new Date().getTime() + 3600 * 1000 * 365); 287 var s = ""; 288 document.cookie = "emdn_gcm_endpoint="+s+"; path=/; expires="+d; 289 //END OF COOKIE 290 291 //console.log('Unsubed3'); 292 document.getElementById('pushem-notification-https-unsub').style.display = 'none'; 293 document.getElementById('pushem-notification-https-sub').style.display = 'block'; 294 295 document.getElementById('pushem-widget-https').style.display = 'none'; 296 document.getElementById('pushem-widget-https-bg').style.display = 'none'; 297 298 document.getElementById('pushem-notification-https-msg').innerHTML = data.source.unsubmsg; 299 document.getElementById('pushem-notification-https-msg').style.display = 'block'; 300 setTimeout(function() { document.getElementById('pushem-notification-https-msg').style.display = 'none' }, 2000); 301 302 var idget_line = "https://pushem.org/api/subscribers/get_by_endpoint/?"+params+"&sub_endpoint="+sub.endpoint; 303 304 //console.log(idget_line); 305 306 fetch(idget_line).then(function(response) { 307 response.json().then(function(data) { 308 309 var idremove_line = "https://pushem.org/api/subscribers/remove/?"+params+"&id="+data.subscriber.id; 310 fetch(idremove_line).then(function(response) { 311 312 }); 313 314 }); 315 }); 316 317 318 319 var httpsubbtn = document.getElementById('pushem-notification-https-sub'); 320 httpsubbtn.style.cursor = 'pointer'; 321 httpsubbtn.onclick = function() { 322 reg.pushManager.subscribe({ 323 userVisibleOnly: true 324 }).then(function(sub) { 325 326 //SET COOKIE, USE FOR ANONYMOUS 327 var d = new Date(new Date().getTime() + 3600 * 1000 * 365); 328 document.cookie = "emdn_gcm_endpoint="+sub.endpoint+"; path=/; expires="+d; 329 //END OF COOKIE 330 331 //console.log(sub); 332 //console.log('endpoint:', sub.endpoint); 236 333 237 334 document.getElementById('pushem-notification-https-sub').style.display = 'none'; … … 266 363 267 364 }).catch(function(error) { 268 console.log(':^(', error);365 //console.log(':^(', error); 269 366 }); 270 367
Note: See TracChangeset
for help on using the changeset viewer.