-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
91 lines (81 loc) · 3.17 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
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Barcode Scanner</title>
<script src="https://unpkg.com/@zxing/library@latest"></script>
<style>
#scanner-container { position: relative; }
#video { width: 100%; max-width: 500px; }
#overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 2px solid #ff0000; box-sizing: border-box; }
</style>
</head>
<body>
<h1>Barcode Scanner</h1>
<div id="scanner-container">
<video id="video"></video>
<div id="overlay"></div>
</div>
<br>
<button id="startButton">Scanner starten</button>
<button id="testAudioButton">Audio testen</button>
<br><br>
<input type="text" id="result" readonly>
<!-- Gehostete beep MP3 -->
<audio id="beepSound" src="https://soundbible.com/mp3/Electronic_Chime-KevanGC-495939803.mp3" preload="auto"></audio>
<script>
const video = document.getElementById('video');
const overlay = document.getElementById('overlay');
const startButton = document.getElementById('startButton');
const testAudioButton = document.getElementById('testAudioButton');
const resultInput = document.getElementById('result');
const beepSound = document.getElementById('beepSound');
let codeReader;
let lastScannedCode = '';
function beep() {
beepSound.play().catch(error => console.warn('Beep playback failed', error));
}
startButton.addEventListener('click', () => {
startScanner();
});
testAudioButton.addEventListener('click', () => {
beep();
});
function startScanner() {
codeReader = new ZXing.BrowserMultiFormatReader();
codeReader.listVideoInputDevices()
.then((videoInputDevices) => {
const selectedDeviceId = videoInputDevices[0].deviceId;
codeReader.decodeFromVideoDevice(selectedDeviceId, 'video', (result, err) => {
if (result) {
if (result.text !== lastScannedCode) {
lastScannedCode = result.text;
resultInput.value = result.text;
beep();
flashOverlay();
}
}
if (err && !(err instanceof ZXing.NotFoundException)) {
console.error(err);
}
});
})
.catch((err) => {
console.error(err);
});
}
function flashOverlay() {
overlay.style.backgroundColor = 'rgba(0, 255, 0, 0.5)'; // Grüner Flash
setTimeout(() => {
overlay.style.backgroundColor = 'transparent';
}, 100);
}
window.addEventListener('beforeunload', () => {
if (codeReader) {
codeReader.reset();
}
});
</script>
</body>
</html>