-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstuff.js
75 lines (64 loc) · 2.32 KB
/
stuff.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var _trackInstalling = function (worker) {
worker.addEventListener('statechange', function() {
if (worker.state == 'installed') {
_updateReady(worker);
}
});
},
_updateReady = function (worker) {
var promptResponse = confirm('List has an update available. Want to reload it?');
if (promptResponse) {
console.log('New ServiceWorker skipping waiting.');
worker.postMessage({action: 'skipWaiting'});
}
},
_installServiceWorker = function () {
window.addEventListener('load', function() {
var nav = navigator;
nav.serviceWorker.register('sw.js').then(function(registration) {
if (!nav.serviceWorker.controller) {
return;
}
if (registration.waiting) {
_updateReady(registration.waiting);
return;
}
if (registration.installing) {
_trackInstalling(registration.installing);
return;
}
registration.addEventListener('updatefound', function() {
_trackInstalling(registration.installing);
});
})['catch'](function(err) {
console.log('ServiceWorker registration failed: ', err);
});
var refreshing;
nav.serviceWorker.addEventListener('controllerchange', function() {
if (refreshing) return;
window.location.reload();
refreshing = true;
});
});
};
if ('serviceWorker' in navigator) {
_installServiceWorker();
}
(function () {
var userAgent = navigator.userAgent.toString();
var links = document.getElementsByTagName('a');
var count = links.length;
for (var i = 0; i < count; i++) {
if (links[i].href.indexOf('geo:') > -1) {
let latLng = links[i].href.substring(4);
let address = links[i].dataset.address;
if (userAgent.match(/iPad|iPhone|iPod/ig)) {
links[i].href = 'http://maps.apple.com/?q=' + links[i].textContent + '&sll=' + latLng;
} else if (userAgent.match(/android/ig)) {
links[i].href = links[i].href + '?q=' + latLng + '(' + address + ')';
} else {
links[i].href = 'https://www.openstreetmap.org/search?query=' + address + '#map=14/' + latLng;
}
}
}
})();