Files

79 lines
3.2 KiB
HTML
Raw Permalink Normal View History

2022-09-04 13:23:53 -05:00
<!DOCTYPE html>
<html>
<head>
2022-09-04 16:52:21 -05:00
<title>QRTransfer</title>
2022-09-05 11:24:51 -05:00
<style>
input {
position: absolute;
left: 150px;
}
</style>
2022-09-04 13:23:53 -05:00
<script src="qrenc-4.0.0.js" type="text/javascript"></script>
<script type="text/javascript">
2022-09-05 11:24:51 -05:00
let fileDataB64,
2022-09-04 16:18:10 -05:00
chunkSize,
2022-09-05 11:24:51 -05:00
dataPosition,
timoutHandle,
2022-09-04 16:52:21 -05:00
activeCanvas = 0; // double buffering.
2022-09-04 13:23:53 -05:00
const $ = (ele) => document.getElementById(ele);
const serveCodes = () => {
2022-09-05 11:24:51 -05:00
let numChunks = Math.ceil(fileDataB64.length / chunkSize);
let currChunk = Math.ceil(dataPosition / chunkSize) + 1;
2022-09-04 16:18:10 -05:00
let delay = Number($("delay").value);
let minLeft = ((numChunks - currChunk) * delay) / 1000 / 60;
$("status").innerText = `${currChunk}/${numChunks}/${((currChunk / numChunks) * 100).toFixed(2)}% (${minLeft.toFixed(2)} min left.)`;
2022-09-05 11:24:51 -05:00
displayQR(currChunk + "|" + fileDataB64.substring(dataPosition, dataPosition + chunkSize), Number($("qrSize").value), Number($("ecc").value));
dataPosition += chunkSize;
2022-09-04 13:23:53 -05:00
2022-09-05 11:24:51 -05:00
if (dataPosition < fileDataB64.length) {
timoutHandle = window.setTimeout(serveCodes, delay);
2022-09-04 13:23:53 -05:00
}
};
const displayQR = (data, size, ecc) => {
2022-09-05 11:24:51 -05:00
window.scrollTo(0, 0);
2022-09-04 16:18:10 -05:00
var qr = new QR($("qrcanv" + activeCanvas), data, size, size, ecc);
$("qrcanv" + (activeCanvas === 0 ? 1 : 0)).style.display = "none";
$("qrcanv" + activeCanvas).style.display = "block";
activeCanvas = activeCanvas === 0 ? 1 : 0;
2022-09-04 13:23:53 -05:00
};
2022-09-05 11:24:51 -05:00
const startAction = (fileName) => {
2022-09-04 13:23:53 -05:00
chunkSize = Number($("chunkSize").value);
2022-09-05 11:24:51 -05:00
dataPosition = Number($("startChunk").value * chunkSize);
2022-09-04 13:23:53 -05:00
var xhr = new XMLHttpRequest();
xhr.open("GET", fileName, true);
xhr.responseType = "arraybuffer";
xhr.onload = (e) => {
tgt = e.currentTarget;
if (tgt.status == 200) {
2022-09-05 11:24:51 -05:00
let allCharCodes = new Uint8Array(tgt.response);
let allChars = new Array(allCharCodes.length);
allCharCodes.map((x, idx) => (allChars[idx] = String.fromCharCode(x)));
2022-09-04 16:18:10 -05:00
// it seems that the qr library doesn't support binary data - converting to base64
2022-09-05 11:24:51 -05:00
fileDataB64 = window.btoa(allChars.join(""));
timoutHandle && window.clearTimeout(timoutHandle);
timoutHandle = window.setTimeout(serveCodes, 3000);
2022-09-04 13:23:53 -05:00
}
};
xhr.send();
};
</script>
</head>
<body>
2022-09-05 11:24:51 -05:00
<center><canvas id="qrcanv0"></canvas><canvas id="qrcanv1"></canvas></center>
2022-09-04 16:18:10 -05:00
<hr />
2022-09-05 11:24:51 -05:00
Status:<span id="status">...</span> <button onclick="startAction($('inputFileName').value)">Start(3 sec delay)</button>
2022-09-04 16:18:10 -05:00
<hr />
2022-09-05 11:24:51 -05:00
Filename:<input type="text" id="inputFileName" value="testInput/5K.dat" /> <br />
ECC (1-4):<input type="number" value="4" id="ecc" /> <br />
Qr-Size:<input type="number" value="800" id="qrSize" /> <br />
Chunk-Size<input type="number" value="1200" id="chunkSize" /> <br />
Start-Chunk:<input type="number" value="0" id="startChunk" /> <br />
2022-09-04 16:18:10 -05:00
Delay:<input type="number" value="1500" id="delay" />
2022-09-04 13:23:53 -05:00
</body>
</html>