Skip to content

Commit 9c63d7c

Browse files
author
Floris
committed
Optie voor QR-code scannen met Barcode Detection API toegevoegd op
ondersteunde apparaten. Knoppen gegevens verwijderen beetje aangepast. Positie van datumtekst gefikst bij draaien. Padding verminderd bij schakelaarcontainers in instellingen.
1 parent b27ca57 commit 9c63d7c

4 files changed

Lines changed: 171 additions & 21 deletions

File tree

index.html

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,34 @@ <h2>Weet je het zeker?</h2>
396396
</section>
397397
</div>
398398
</dialog>
399+
<dialog
400+
id="scanQrCode"
401+
role="dialog"
402+
aria-label="QR-code scannen"
403+
closedby="any"
404+
>
405+
<div>
406+
<svg
407+
xmlns="http://www.w3.org/2000/svg"
408+
viewBox="0 -960 960 960"
409+
id="icon"
410+
>
411+
<path
412+
d="M120-680q-17 0-28.5-11.5T80-720v-120q0-17 11.5-28.5T120-880h120q17 0 28.5 11.5T280-840q0 17-11.5 28.5T240-800h-80v80q0 17-11.5 28.5T120-680Zm0 600q-17 0-28.5-11.5T80-120v-120q0-17 11.5-28.5T120-280q17 0 28.5 11.5T160-240v80h80q17 0 28.5 11.5T280-120q0 17-11.5 28.5T240-80H120Zm600 0q-17 0-28.5-11.5T680-120q0-17 11.5-28.5T720-160h80v-80q0-17 11.5-28.5T840-280q17 0 28.5 11.5T880-240v120q0 17-11.5 28.5T840-80H720Zm91.5-611.5Q800-703 800-720v-80h-80q-17 0-28.5-11.5T680-840q0-17 11.5-28.5T720-880h120q17 0 28.5 11.5T880-840v120q0 17-11.5 28.5T840-680q-17 0-28.5-11.5ZM700-200v-60h60v60h-60Zm0-120v-60h60v60h-60Zm-60 60v-60h60v60h-60Zm-60 60v-60h60v60h-60Zm-60-60v-60h60v60h-60Zm120-120v-60h60v60h-60Zm-60 60v-60h60v60h-60Zm-60-60v-60h60v60h-60Zm40-140q-17 0-28.5-11.5T520-560v-160q0-17 11.5-28.5T560-760h160q17 0 28.5 11.5T760-720v160q0 17-11.5 28.5T720-520H560ZM240-200q-17 0-28.5-11.5T200-240v-160q0-17 11.5-28.5T240-440h160q17 0 28.5 11.5T440-400v160q0 17-11.5 28.5T400-200H240Zm0-320q-17 0-28.5-11.5T200-560v-160q0-17 11.5-28.5T240-760h160q17 0 28.5 11.5T440-720v160q0 17-11.5 28.5T400-520H240Zm20 260h120v-120H260v120Zm0-320h120v-120H260v120Zm320 0h120v-120H580v120Z"
413+
/>
414+
</svg>
415+
<h2>QR-code scannen</h2>
416+
<div class="scan-container">
417+
<video id="video" autoplay playsinline></video>
418+
<div class="scan-frame">
419+
<span class="corner tl"></span>
420+
<span class="corner tr"></span>
421+
<span class="corner bl"></span>
422+
<span class="corner br"></span>
423+
</div>
424+
</div>
425+
</div>
426+
</dialog>
399427
<dialog
400428
id="customAppointments"
401429
role="dialog"
@@ -1002,6 +1030,28 @@ <h2 data-translate="settings">Instellingen</h2>
10021030
>Koppelcode</label
10031031
>
10041032
</div>
1033+
<div class="scanBtn">
1034+
<button
1035+
id="submenu"
1036+
command="show-modal"
1037+
commandfor="scanQrCode"
1038+
style="
1039+
padding: 2px;
1040+
background-color: var(--primary-foreground);
1041+
"
1042+
>
1043+
<svg
1044+
xmlns="http://www.w3.org/2000/svg"
1045+
viewBox="0 -960 960 960"
1046+
id="icon"
1047+
>
1048+
<path
1049+
d="M120-680q-17 0-28.5-11.5T80-720v-120q0-17 11.5-28.5T120-880h120q17 0 28.5 11.5T280-840q0 17-11.5 28.5T240-800h-80v80q0 17-11.5 28.5T120-680Zm0 600q-17 0-28.5-11.5T80-120v-120q0-17 11.5-28.5T120-280q17 0 28.5 11.5T160-240v80h80q17 0 28.5 11.5T280-120q0 17-11.5 28.5T240-80H120Zm600 0q-17 0-28.5-11.5T680-120q0-17 11.5-28.5T720-160h80v-80q0-17 11.5-28.5T840-280q17 0 28.5 11.5T880-240v120q0 17-11.5 28.5T840-80H720Zm91.5-611.5Q800-703 800-720v-80h-80q-17 0-28.5-11.5T680-840q0-17 11.5-28.5T720-880h120q17 0 28.5 11.5T880-840v120q0 17-11.5 28.5T840-680q-17 0-28.5-11.5ZM700-200v-60h60v60h-60Zm0-120v-60h60v60h-60Zm-60 60v-60h60v60h-60Zm-60 60v-60h60v60h-60Zm-60-60v-60h60v60h-60Zm120-120v-60h60v60h-60Zm-60 60v-60h60v60h-60Zm-60-60v-60h60v60h-60Zm40-140q-17 0-28.5-11.5T520-560v-160q0-17 11.5-28.5T560-760h160q17 0 28.5 11.5T760-720v160q0 17-11.5 28.5T720-520H560ZM240-200q-17 0-28.5-11.5T200-240v-160q0-17 11.5-28.5T240-440h160q17 0 28.5 11.5T440-400v160q0 17-11.5 28.5T400-200H240Zm0-320q-17 0-28.5-11.5T200-560v-160q0-17 11.5-28.5T240-760h160q17 0 28.5 11.5T440-720v160q0 17-11.5 28.5T400-520H240Zm20 260h120v-120H260v120Zm0-320h120v-120H260v120Zm320 0h120v-120H580v120Z"
1050+
/>
1051+
</svg>
1052+
<span>QR-code scannen</span>
1053+
</button>
1054+
</div>
10051055
</section>
10061056
</div>
10071057
<div id="somtoday" class="submenu">

material.css

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
display: inherit;
2323
border-radius: 1rem;
2424
}
25-
.theme__input:checked + .theme__icon::after {
26-
border-radius: 1rem;
27-
}
2825
.theme__icon {
2926
display: inline-block;
3027
width: 3.5rem;
@@ -37,16 +34,6 @@
3734
font-family: Inter;
3835
font-weight: 500;
3936
}
40-
.theme__icon::after {
41-
content: "";
42-
width: 3.5rem;
43-
height: 2.9rem;
44-
display: block;
45-
border-radius: 1.5rem;
46-
position: relative;
47-
bottom: 2.9rem;
48-
transition: 0.2s border-radius;
49-
}
5037
.theme__icon::before {
5138
content: "";
5239
background: linear-gradient(
@@ -407,7 +394,7 @@ body[data-theme="pink monochrome"] {
407394
--thumb-out: var(--thumb-space-between-edges);
408395
max-width: calc(100vw - 92px);
409396
width: 260px;
410-
padding: 18px 16px;
397+
padding: 16px;
411398
}
412399
.switch__design {
413400
width: var(--width);
@@ -419,7 +406,7 @@ body[data-theme="pink monochrome"] {
419406
transition: 0.1s;
420407
border: 2px solid var(--thumb-background);
421408
float: right;
422-
bottom: 5px;
409+
bottom: 6.5px;
423410
font-family: Inter;
424411
}
425412
.switch__design::before {

schedule.js

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,9 @@ document.getElementById("ltr").addEventListener("click", () => {
969969
}
970970
document.getElementById("weekBtn").click();
971971
});
972+
document.querySelector(".scanBtn").addEventListener("click", () => {
973+
startScanner();
974+
});
972975
if (
973976
localStorage.getItem("dag") == "false" ||
974977
(!localStorage.getItem("dag") && window.innerWidth > 1000)
@@ -980,6 +983,56 @@ if (
980983
if (window.innerWidth < 330) {
981984
document.getElementById("dayBtn").click();
982985
}
986+
987+
const video = document.getElementById("video");
988+
989+
async function startScanner() {
990+
// Check support
991+
if (!("BarcodeDetector" in window)) {
992+
return;
993+
}
994+
995+
// Create detector for QR codes only
996+
const barcodeDetector = new BarcodeDetector({
997+
formats: ["qr_code"],
998+
});
999+
1000+
// Start camera
1001+
const stream = await navigator.mediaDevices.getUserMedia({
1002+
video: { facingMode: "environment" },
1003+
});
1004+
1005+
video.srcObject = stream;
1006+
1007+
// Scan loop
1008+
async function scan() {
1009+
try {
1010+
const barcodes = await barcodeDetector.detect(video);
1011+
1012+
if (barcodes.length > 0) {
1013+
document.getElementById("schoolName").value = JSON.parse(
1014+
barcodes[0].rawValue
1015+
).institution;
1016+
document.getElementById("authorizationCode").value = JSON.parse(
1017+
barcodes[0].rawValue
1018+
).code;
1019+
// Stop scanning after success
1020+
stream.getTracks().forEach((track) => track.stop());
1021+
return;
1022+
}
1023+
} catch (err) {
1024+
console.error(err);
1025+
}
1026+
1027+
requestAnimationFrame(scan);
1028+
}
1029+
1030+
requestAnimationFrame(scan);
1031+
}
1032+
1033+
if (!("BarcodeDetector" in window)) {
1034+
document.querySelector(".scanBtn").remove();
1035+
}
9831036
async function showLessonInfo(lessonHTML, lesson) {
9841037
const original = document.getElementById(lesson.appointmentInstance);
9851038
original.classList.add("clicked");
@@ -1012,7 +1065,8 @@ async function showLessonInfo(lessonHTML, lesson) {
10121065
if (!lesson.content) {
10131066
lesson.content = "";
10141067
}
1015-
let warning = lesson.changeDescription + lesson.schedulerRemark + lesson.content;
1068+
let warning =
1069+
lesson.changeDescription + lesson.schedulerRemark + lesson.content;
10161070

10171071
if (lesson.cancelled == true) {
10181072
lesson.appointmentType = "cancelled";

style.css

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,58 @@ dialog {
131131
view-transition-name: dialog;
132132
width: 292px;
133133
}
134+
#scanQrCode {
135+
width: 250px;
136+
}
137+
#video {
138+
border-radius: 18px;
139+
aspect-ratio: 1 / 1;
140+
object-fit: cover;
141+
background-color: var(--primary-foreground);
142+
}
143+
.scan-frame {
144+
position: absolute;
145+
inset: 0;
146+
}
147+
.scan-container {
148+
width: 100%;
149+
}
150+
.corner {
151+
width: 32px;
152+
height: 32px;
153+
border-width: 3px;
154+
border-style: solid;
155+
position: absolute;
156+
border-color: var(--primary-border);
157+
}
158+
.tl {
159+
top: 111px;
160+
left: 15px;
161+
border-right: 0;
162+
border-bottom: 0;
163+
border-radius: 24px 0 0 0;
164+
}
165+
.tr {
166+
top: 111px;
167+
right: 15px;
168+
border-left: 0;
169+
border-bottom: 0;
170+
border-radius: 0 24px 0 0;
171+
}
172+
.bl {
173+
bottom: 10px;
174+
left: 15px;
175+
border-right: 0;
176+
border-top: 0;
177+
border-radius: 0 0 0 24px;
178+
}
179+
.br {
180+
bottom: 10px;
181+
right: 15px;
182+
border-left: 0;
183+
border-top: 0;
184+
border-radius: 0 0 24px 0;
185+
}
134186

135187
@keyframes popIn {
136188
from {
@@ -195,12 +247,14 @@ h2.date {
195247
display: inline;
196248
}
197249
section div:first-of-type,
198-
section #submenu:first-of-type {
250+
section #submenu:first-of-type,
251+
#clearSettings section #submenu:first-of-type {
199252
border-top-left-radius: 1rem;
200253
border-top-right-radius: 1rem;
201254
}
202255
section div:last-of-type,
203-
section #submenu:last-of-type {
256+
section #submenu:last-of-type,
257+
#clearSettings section #submenu:last-of-type {
204258
border-bottom-left-radius: 1rem;
205259
border-bottom-right-radius: 1rem;
206260
margin-bottom: 0;
@@ -263,7 +317,8 @@ table {
263317
#clearSettings #content {
264318
width: 282px;
265319
}
266-
#clearSettings div {
320+
#clearSettings div,
321+
#scanQrCode div {
267322
display: flex;
268323
flex-direction: column;
269324
gap: 1rem;
@@ -282,13 +337,16 @@ table {
282337
}
283338
#clearSettings #submenu {
284339
padding: 1rem;
340+
border-radius: 0.4rem;
341+
margin-bottom: 0.25rem;
285342
background-color: var(--primary-accent);
286343
color: var(--accent-text);
287344
display: flex;
288345
justify-content: center;
289346
align-items: center;
290347
}
291-
#clearSettings #icon {
348+
#clearSettings #icon,
349+
#scanQrCode #icon {
292350
fill: var(--accent-text);
293351
width: 2rem;
294352
height: 2rem;
@@ -410,7 +468,7 @@ details strong {
410468
height: calc(100vh - 3.75rem);
411469
}
412470
.ltrEnabled strong.date {
413-
margin: 12px;
471+
margin: 12px 10px;
414472
transform: translateY(-1.5rem);
415473
}
416474
.ltrEnabled div {
@@ -628,6 +686,7 @@ dialog details {
628686
}
629687
details {
630688
overflow: hidden;
689+
font-weight: 450;
631690
}
632691
summary::marker {
633692
font-family: inherit;

0 commit comments

Comments
 (0)