-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
393 lines (358 loc) · 17.3 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Barnard Castle</title>
<meta name="description" content="Simple app to scan NHS COVID-19 QR codes if you cannot use the official app">
<meta property="og:title" content="Barnard Castle">
<meta property="og:description" content="Scan NHS COVID-19 QR codes without an app">
<meta property="og:type" content="website">
<meta property="og:url" content="https://covidqr.nti.me.uk/" />
<meta property="og:image" content="https://covidqr.nti.me.uk/images/barnard-castle.png">
<meta property="og:site_name" content="Barnard Castle">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://covidqr.nti.me.uk/images/barnard-castle.png">
<meta name="twitter:image:alt" content="QR code">
<meta name="twitter:title" content="Barnard Castle">
<meta name="twitter:description" content="Scan NHS COVID-19 QR codes without an app">
<link rel="apple-touch-icon" sizes="57x57" href="/images/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="/images/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="/images/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="/images/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="/images/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="/images/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="/images/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="/images/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="/images/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="/images/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="/images/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.png">
<link rel="manifest" href="/manifest.json">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="/images/ms-icon-144x144.png">
<meta name="theme-color" content="#ffffff">
<link rel="stylesheet" type="text/css" href="css/bulma.min.css?v=1" />
<link rel="stylesheet" type="text/css" href="css/castle.css?v=2" />
<script defer src="lib/fontawesome/js/all.js"></script>
</head>
<body>
<section id="scan-dialog" class="modal">
<div class="modal-background"></div>
<div class="modal-content">
<p class="has-text-centered">
<video autoplay playsinline id="video"></video>
</p>
</div>
<button class="modal-close is-large" aria-label="close" id="stop-button"></button>
<button class="m-3 button is-rounded is-light is-outlined" aria-label="flash" id="flash-button">
<span class="icon is-small">
<i class="fas fa-bolt"></i>
</span>
</button>
</section>
<header class="hero">
<div class="hero-body">
<div class="container">
<h1 class="title">Barnard Castle</h1>
<h2 class="subtitle">NHS COVID-19 QR Scanner</h2>
<div class="content">
<p>Simple app to scan NHS COVID-19 QR codes if you cannot use the official app.</p>
<p>You can keep track of where you've been by saving check-ins in your browser, publish the location
of venues, or just find out
what's in those huge QR codes!</p>
<h3>Privacy</h3>
<p>No personal data is collected by this app. Check-ins are stored on your device and can be removed
using the <b>Clear history</b> button at any time.</p>
<p>If you choose to publish location venues, only the contents of the QR code and location data will
be sent.</p>
</div>
<div class="buttons">
<button class="button is-primary is-light has-text-grey-darker has-text-weight-semibold is-medium" id="start-button">
<span class="icon is-small">
<i class="fas fa-camera"></i>
</span>
<span>Scan</span>
</button>
</div>
<div class="field is-grouped is-grouped-multiline">
<div class="control">
<div class="button is-light" id="file-button">
<div class="file is-light">
<label class="file-label">
<input class="file-input" type="file" accept="image/*" name="qr-file" id="qr-file">
<span class="file-cta">
<span class="file-icon">
<i class="fas fa-image"></i>
</span>
<span class="file-label">
Choose an image…
</span>
</span>
</label>
</div>
</div>
</div>
<div class="control">
<button class="button is-light" id="qr-paste-button">
<span class="icon is-small">
<i class="fas fa-paste"></i>
</span>
<span>Paste UKC19TRACING text</span>
</button>
</div>
</div>
</div>
</div>
</header>
<main class="section pt-0">
<div class="container">
<div class="columns">
<div class="column">
<div id="no-nhsqr-message" class="message is-info is-hidden">
<div class="message-body has-text-grey-darker">
No NHS COVID-19 QR code detected
</div>
</div>
<div class="box" id="venue-box">
<div class="field is-hidden">
<label class="label" for="qr-content">QR Code Contents</label>
<div class="control">
<textarea class="textarea has-fixed-area" id="qr-content" placeholder="UKC19TRACING:1:"
readonly></textarea>
</div>
</div>
<div class="field">
<label class="label" for="venue-text">Venue Details</label>
<div class="control">
<textarea class="textarea is-info has-fixed-area" id="venue-text" readonly></textarea>
</div>
</div>
<div class="field is-grouped is-grouped-left">
<p class="control">
<button class="button" id="add-button" disabled>
<span class="icon is-small">
<i class="fas fa-door-open"></i>
</span>
<span>Check in</span>
</button>
</p>
<p class="control">
<button class="button" id="share-button" disabled>
<span class="icon is-small">
<i class="fas fa-map-marker-alt"></i>
</span>
<span>Publish venue</span>
</button>
</p>
</div>
</div>
<div id="publish-success-message" class="message is-success is-hidden">
<div class="message-body has-text-grey-darker">
Thank you, venue location published
</div>
</div>
<div id="publish-fail-message" class="message is-warning is-hidden">
<div class="message-body has-text-grey-darker">
Sorry, could not publish venue location
</div>
</div>
</div>
<div class="column">
<div class="box">
<div class="content">
<table class="table">
<thead>
<tr>
<th>Time</th>
<th>Venue</th>
<th>ID</th>
</tr>
</thead>
<tbody id="qr-history"></tbody>
</table>
<div class="field is-grouped is-grouped-right">
<p class="control">
<button class="button is-danger is-light has-text-danger-dark" id="clear-button">
<span class="icon is-small">
<i class="fas fa-trash-alt"></i>
</span>
<span>Clear history</span>
</button>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
<footer class="footer">
<div class="content has-text-centered">
<p>
<a href="https://github.com/jt-nti/barnard-castle" class="has-text-link-dark">Source code on
GitHub</a>.
</p>
</div>
</footer>
<script src="lib/jsQR.js"></script>
<script src="lib/load-image.all.min.js"></script>
<script src="lib/jwt-decode.min.js"></script>
<script src="js/castle.js"></script>
<script>
const startButton = document.getElementById('start-button');
const stopButton = document.getElementById('stop-button');
const flashButton = document.getElementById('flash-button');
const fileInput = document.getElementById('qr-file');
const pasteButton = document.getElementById('qr-paste-button');
const video = document.getElementById('video');
const qrContent = document.getElementById('qr-content');
const addButton = document.getElementById('add-button');
const shareButton = document.getElementById('share-button');
const qrHistory = document.getElementById('qr-history');
const clearButton = document.getElementById('clear-button');
var state = new State(document.documentElement,
document.getElementById('scan-dialog'),
document.getElementById('start-button'),
document.getElementById('file-button'),
document.getElementById('qr-file'),
document.getElementById('qr-paste-button'),
document.getElementById('no-nhsqr-message'),
document.getElementById('venue-text'),
document.getElementById('venue-box'),
document.getElementById('add-button'),
document.getElementById('share-button'),
document.getElementById('publish-success-message'),
document.getElementById('publish-fail-message'));
initDb().then(function (response) {
db = response;
loadScans(qrHistory);
});
var tickDuration = 200;
var tickTimeoutId;
var scanTimeoutId;
function tick() {
try {
var canvasElement = document.createElement("canvas");
var canvas = canvasElement.getContext("2d");
canvasElement.height = video.videoHeight;
canvasElement.width = video.videoWidth;
canvas.drawImage(video, 0, 0, canvasElement.width, canvasElement.height);
var imageData = canvas.getImageData(0, 0, canvasElement.width, canvasElement.height);
var code = jsQR(imageData.data, imageData.width, imageData.height, { inversionAttempts: 'dontInvert' });
if (code) {
// barcode was found!
qrContent.value = code.data;
if (previewCode(state, qrContent)) {
stop();
return;
}
}
}
catch (t) {
console.log("PROBLEM: " + t);
}
tickTimeoutId = setTimeout(function () { tick(); }, tickDuration);
}
function toggleFlash() {
const stream = video.srcObject;
const track = stream.getVideoTracks()[0];
const supportedConstraints = navigator.mediaDevices.getSupportedConstraints();
const settings = track.getSettings();
const torchSetting = settings.torch;
if (!supportedConstraints.torch || torchSetting == undefined) {
console.log('No torch detected');
console.log('Supported constraints', supportedConstraints);
console.log('Settings', settings);
return;
}
track.applyConstraints({ advanced: [{ torch: !torchSetting }] });
}
function start() {
qrContent.value = '';
state.startScan()
// Use facingMode: environment to attemt to get the front camera on phones
navigator.mediaDevices.getUserMedia({ video: { facingMode: "environment" } }).then(function (stream) {
video.srcObject = stream;
video.play();
tickTimeoutId = setTimeout(function () { tick(); }, tickDuration);
scanTimeoutId = setTimeout(function () {
previewCode(state, qrContent);
stop();
}, 99 * tickDuration);
});
}
function stop() {
clearTimeout(tickTimeoutId);
clearTimeout(scanTimeoutId);
tickTimeoutId = null;
scanTimeoutId = null;
const stream = video.srcObject;
const tracks = stream.getTracks();
tracks.forEach(function (track) {
track.stop();
});
video.srcObject = null;
state.scanFinished();
}
startButton.addEventListener('click', () => {
start();
});
flashButton.addEventListener('click', () => {
toggleFlash();
});
pasteButton.addEventListener('click', () => {
navigator.clipboard.readText().then(text => {
qrContent.value = text;
previewCode(state, qrContent);
});
});
stopButton.addEventListener('click', () => {
qrContent.value = '';
previewCode(state, qrContent);
stop();
});
addButton.addEventListener('click', () => {
checkIn(qrHistory, qrContent.value);
});
shareButton.addEventListener('click', () => {
publishVenue(state, qrContent.value);
});
clearButton.addEventListener('click', () => {
clearScans(qrHistory);
});
fileInput.onchange = function () {
state.loadImage();
const filename = this.files[0].name;
console.log(`Loading image ${filename}`);
const options = {
maxWidth: 640,
contain: true,
canvas: true
}
loadImage(this.files[0], options)
.then(function (data) {
var canvasElement = data.image;
var canvas = canvasElement.getContext("2d");
var imageData = canvas.getImageData(0, 0, canvasElement.width, canvasElement.height);
var code = jsQR(imageData.data, imageData.width, imageData.height, { inversionAttempts: 'dontInvert' });
if (code) {
// barcode was found!
qrContent.value = code.data;
} else {
qrContent.value = '';
}
previewCode(state, qrContent);
fileInput.value = '';
state.loadImageComplete();
})
.catch(function (err) {
console.log(`Error loading image ${filename}`, err);
fileInput.value = '';
state.loadImageComplete();
});
}
</script>
</body>
</html>