-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex2.html
More file actions
88 lines (83 loc) · 3.37 KB
/
index2.html
File metadata and controls
88 lines (83 loc) · 3.37 KB
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
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Scanner de Tickets</title>
<script src="https://unpkg.com/html5-qrcode@2.3.8/minified/html5-qrcode.min.js"></script>
<style>
body { font-family: Arial, sans-serif; padding: 20px; text-align: center; background: #f0f0f0; }
h1 { font-size: 1.5rem; margin-bottom: 1rem; }
#result { margin-top: 1rem; font-size: 1.3rem; font-weight: bold; }
#result.valid { color: green; }
#result.invalid { color: red; }
#reader { display: none; margin: auto; }
#scan-btn { padding: 10px 20px; font-size: 1rem; cursor: pointer; }
</style>
</head>
<body>
<h1>Scanner de Tickets</h1>
<button id="scan-btn">Scan</button>
<div id="reader" style="width: 300px;"></div>
<div id="result">En attente du scan...</div>
<script>
const validTickets = new Set();
fetch('tickets.json')
.then(response => response.json())
.then(data => data.forEach(t => validTickets.add(t)))
.catch(err => console.error("Erreur chargement JSON", err));
const scannedTickets = new Set();
let scannerStarted = false;
let html5QrCode;
function onScanSuccess(decodedText) {
if (scannedTickets.has(decodedText)) {
document.getElementById('result').innerText = 'Ticket déjà scanné';
document.getElementById('result').className = 'invalid';
return;
}
scannedTickets.add(decodedText);
if (validTickets.has(decodedText)) {
document.getElementById('result').innerText = '✅ Ticket Valide';
document.getElementById('result').className = 'valid';
} else {
document.getElementById('result').innerText = '❌ Ticket Invalide';
document.getElementById('result').className = 'invalid';
}
// Optionally stop scanner after a scan
if (html5QrCode) {
html5QrCode.stop();
document.getElementById('reader').style.display = 'none';
scannerStarted = false;
}
}
document.getElementById('scan-btn').addEventListener('click', function() {
if (scannerStarted) return;
document.getElementById('reader').style.display = 'block';
html5QrCode = new Html5Qrcode("reader");
Html5Qrcode.getCameras().then(cameras => {
if (cameras && cameras.length) {
// Try to select the rear camera if available
const rearCamera = cameras.find(cam => cam.label.toLowerCase().includes('back') || cam.label.toLowerCase().includes('rear')) || cameras[0];
html5QrCode.start(
rearCamera.id,
{ fps: 10, qrbox: 250 },
onScanSuccess
).catch(err => {
document.getElementById('result').innerText = 'Erreur accès caméra: ' + err;
document.getElementById('result').className = 'invalid';
document.getElementById('reader').style.display = 'none';
scannerStarted = false;
});
scannerStarted = true;
} else {
document.getElementById('result').innerText = 'Aucune caméra détectée';
document.getElementById('result').className = 'invalid';
}
}).catch(err => {
document.getElementById('result').innerText = 'Erreur détection caméra: ' + err;
document.getElementById('result').className = 'invalid';
});
});
</script>
</body>
</html>