-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
203 lines (178 loc) · 6.21 KB
/
index.html
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<title>VanividsBillisterne</title>
<!-- Meta -->
<meta charset="utf-8">
<meta name="description" content="VanividsBillisterne is a PWA that gets your vehicle speed & information about driving, and awards points to the craziest driver!">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#13A4ED">
<!-- <link rel='manifest' href='./manifest.json'> -->
<link rel="manifest" href="https://progressier.app/HueXpyOEEwkt8eK79AZT/progressier.json"/>
<script defer src="https://progressier.app/HueXpyOEEwkt8eK79AZT/script.js"></script>
<script>
// Registering our Service worker
if('serviceWorker' in navigator) {
navigator.serviceWorker.register('sw.js', { scope: './' })
}
</script>
<style>
/* Remove all margins and paddings & Remove blue highlight on mobile */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
/* Set font-size to 62.5% so 0.1rem = 1 px & change the default font-family & color*/
html {
font-size: 62.5%;
scroll-behavior: smooth;
background-color: #263238;
color: #F8F8FF;
font-family: "WorkSans", sans-serif;
font-weight: 400;
font-style: normal;
}
/* Stretch to fill the entire page */
html, body {
min-height: 100vh;
overflow-x: hidden;
}
/* Display flex */
body {
display: flex;
flex-direction: column;
justify-content: space-between;
line-height: 1.4;
}
/* Remove all link styling */
a {
text-decoration: none;
color: inherit;
}
/* Remove style from lists */
ul, ol {
list-style: none;
}
/* Utility Classes */
/* Make anything unselectable */
.unselectable {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-webkit-user-drag: none;
-webkit-touch-callout: none;
}
.error {
font-size: 1.69rem;
color: #CF1313;
}
header {
display: flex;
flex-flow: row nowrap;
justify-content: center;
}
header h1 {
font-size: 3.8rem;
}
main {
display: flex;
flex-flow: column nowrap;
align-items: center;
}
main #speed {
font-size: 3.69rem;
}
footer {
text-align: center;
font-size: .769rem;
}
</style>
</head>
<body>
<header>
<h1>VanividsBillisterne</h1>
</header>
<main>
<h2 id="speed"></h2>
<p id="error" class="error"></p>
</main>
<footer>
<h2>© 2023 - 2023 <a href="/" target="_self">Marcus Mortensen Jensen</a>, All Rights Reserved.</h2>
</footer>
<script>
var speedo = document.querySelector("#speed");
var error = document.querySelector("#error");
var geoWatch;
window.addEventListener("load", () => {
if ('geolocation' in navigator && 'watchPosition' in navigator.geolocation) {
geoWatch = navigator.geolocation.watchPosition(appendSpeed, positionError, {
enableHighAccuracy: true,
timeout: 15000,
maximumAge: 0
});
} else {
speedo.innerText = 'Geolocation API is not supported.';
}
});
function appendSpeed(position) {
var newSpeed = `${position.coords.speed == undefined ? '0' : (position.coords.speed * 3.6).toFixed(0)} km/h`;
speedo.innerText = newSpeed;
error.innerText = "";
// sendNotification(newSpeed);
}
function positionError(error) {
switch (error.code) {
case error.PERMISSION_DENIED:
error.innerText = "Permission denied";
break;
case error.POSITION_UNAVAILABLE:
error.innerText = "The position is unavailable";
break;
case error.TIMEOUT:
error.innerText = "The request timed out";
break;
case error.UNKNOWN_ERROR:
error.innerText = "An unknown error occured";
break;
}
}
function sendNotification(body) {
fetchLocalNotificationPermission();
if (!('Notification' in window) || !('ServiceWorkerRegistration' in window)) {
alert('Persistent Notification API not supported!');
return;
}
try {
navigator.serviceWorker.getRegistration().then((reg) => {
if(Notification.permission === 'granted') {
const title = 'VanvidsBillisterne';
reg.showNotification(title, {
body: body,
icon: "images/icons/icon-192x192.png",
badge: "images/icons/icon-96x96.png"
});
}
}).catch((err) => {
alert('Service Worker registration error: ' + err)
});
} catch (err) {
alert('Notification API error: ' + err);
}
}
function fetchLocalNotificationPermission() {
if (!('Notification' in window)) {
alert('Notification API not supported!');
return;
}
Notification.requestPermission(function (result) {
// alert(result);
});
}
</script>
</body>
</html>