2024-08-07 13:51:27 +07:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
2025-02-05 15:29:26 +07:00
|
|
|
<title>QR Code Scanner</title>
|
2024-08-07 13:51:27 +07:00
|
|
|
<style>
|
2025-02-05 15:29:26 +07:00
|
|
|
body {
|
|
|
|
font-family: Arial, sans-serif;
|
|
|
|
background-color: #f2f2f2;
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
height: 100vh;
|
|
|
|
margin: 0;
|
|
|
|
}
|
|
|
|
#container {
|
|
|
|
background-color: #ffffff;
|
|
|
|
padding: 20px;
|
|
|
|
border-radius: 10px;
|
|
|
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
#qr-reader {
|
|
|
|
width: 100%;
|
|
|
|
height: auto;
|
|
|
|
margin-bottom: 20px;
|
|
|
|
}
|
|
|
|
#qr-reader-results {
|
|
|
|
padding: 10px;
|
|
|
|
background-color: #f8f8f8;
|
|
|
|
border: 1px solid #ddd;
|
|
|
|
border-radius: 5px;
|
|
|
|
}
|
2024-08-07 13:51:27 +07:00
|
|
|
button {
|
|
|
|
margin-top: 30px;
|
|
|
|
margin-bottom: 30px;
|
2025-02-05 15:29:26 +07:00
|
|
|
padding: 10px 20px;
|
|
|
|
background-color: #4CAF50;
|
|
|
|
color: white;
|
|
|
|
border: none;
|
|
|
|
border-radius: 5px;
|
|
|
|
cursor: pointer;
|
|
|
|
transition: background-color 0.3s;
|
|
|
|
}
|
|
|
|
button:hover {
|
|
|
|
background-color: #45a049;
|
2024-08-07 13:51:27 +07:00
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
2025-02-05 15:29:26 +07:00
|
|
|
<div id="container">
|
|
|
|
<h2>QR Code Scanner</h2>
|
|
|
|
<div id="qr-reader"></div>
|
|
|
|
<div id="qr-reader-results"></div>
|
|
|
|
<button id="camera-button">Open Camera</button>
|
|
|
|
</div>
|
2024-08-07 13:51:27 +07:00
|
|
|
<script src="qrcode.min.js"></script>
|
|
|
|
<script>
|
|
|
|
function docReady(fn) {
|
2025-02-05 15:29:26 +07:00
|
|
|
// lihat apakah DOM sudah tersedia
|
2024-08-07 13:51:27 +07:00
|
|
|
if (document.readyState === "complete" ||
|
|
|
|
document.readyState === "interactive") {
|
2025-02-05 15:29:26 +07:00
|
|
|
// panggil di detik berikutnya yang tersedia
|
2024-08-07 13:51:27 +07:00
|
|
|
setTimeout(fn, 1);
|
|
|
|
} else {
|
|
|
|
document.addEventListener("DOMContentLoaded", fn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAllUrlParams(e) {
|
|
|
|
var t = e ? e.split("?")[1] : window.location.search.slice(1),
|
|
|
|
a = {};
|
|
|
|
if (t)
|
|
|
|
for (var n = (t = t.split("#")[0]).split("&"), o = 0; o < n.length; o++) {
|
|
|
|
var i = n[o].split("="),
|
|
|
|
r = void 0,
|
|
|
|
d = i[0].replace(/\[\d*\]/, function (e) {
|
|
|
|
return (r = e.slice(1, -1)), "";
|
|
|
|
}),
|
|
|
|
s = void 0 === i[1] || i[1];
|
|
|
|
a[(d = d.toLowerCase())]
|
|
|
|
? ("string" == typeof a[d] && (a[d] = [a[d]]),
|
|
|
|
void 0 === r ? a[d].push(s) : (a[d][r] = s))
|
|
|
|
: (a[d] = s);
|
|
|
|
}
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
docReady(function() {
|
|
|
|
var resultContainer = document.getElementById('qr-reader-results');
|
|
|
|
var lastResult, countResults = 0;
|
2025-02-05 15:29:26 +07:00
|
|
|
var html5QrcodeScanner;
|
|
|
|
var isCameraOpen = false;
|
|
|
|
|
2024-08-07 13:51:27 +07:00
|
|
|
function onScanSuccess(decodedText, decodedResult) {
|
|
|
|
if (decodedText !== lastResult) {
|
|
|
|
++countResults;
|
|
|
|
lastResult = decodedText;
|
|
|
|
if(getAllUrlParams().back != undefined){
|
|
|
|
window.location = unescape(getAllUrlParams().back) + escape(decodedText);
|
|
|
|
}else{
|
|
|
|
if(decodedText.startsWith('http')){
|
|
|
|
window.location = decodedText;
|
|
|
|
}else{
|
|
|
|
alert(decodedText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-02-05 15:29:26 +07:00
|
|
|
function toggleCamera() {
|
|
|
|
if (isCameraOpen) {
|
|
|
|
html5QrcodeScanner.clear();
|
|
|
|
document.getElementById('camera-button').textContent = "Open Camera";
|
|
|
|
isCameraOpen = false;
|
|
|
|
} else {
|
|
|
|
html5QrcodeScanner = new Html5QrcodeScanner(
|
|
|
|
"qr-reader", {
|
|
|
|
fps: 10,
|
|
|
|
qrbox: 250
|
|
|
|
});
|
|
|
|
html5QrcodeScanner.render(onScanSuccess);
|
|
|
|
document.getElementById('camera-button').textContent = "Close Camera";
|
|
|
|
isCameraOpen = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById('camera-button').addEventListener('click', toggleCamera);
|
2024-08-07 13:51:27 +07:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
|
2025-02-05 15:29:26 +07:00
|
|
|
</html>
|