-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
51 lines (44 loc) · 1.64 KB
/
script.js
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
function generateQRCode(size = 400) {
const url = document.querySelector('input[name="url"]').value;
const payload = JSON.stringify({ url, size }); // Serialize data as JSON
fetch("https://ngqri.onrender.com/generate_qr", {
method: "POST",
body: payload, // Use the serialized JSON payload
headers: {
"Content-Type": "application/json", // Set the content type to JSON
},
})
.then((response) => response.blob())
.then((blob) => {
const qrImage = URL.createObjectURL(blob);
const qrImageElement = document.createElement("img");
qrImageElement.src = qrImage;
document.getElementById("qr_image").innerHTML = "";
document.getElementById("qr_image").appendChild(qrImageElement);
// Show download links after generating QR code
document.getElementById("download_links").style.display = "block";
});
}
function downloadQRCode(size) {
const url = document.querySelector('input[name="url"]').value;
const payload = JSON.stringify({ url, size }); // Serialize data as JSON
fetch("https://ngqri.onrender.com/generate_qr", {
method: "POST",
body: payload, // Use the serialized JSON payload
headers: {
"Content-Type": "application/json", // Set the content type to JSON
},
})
.then((response) => response.blob())
.then((blob) => {
const qrImage = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = qrImage;
link.download = `qrcode_${size}x${size}.png`;
link.click();
});
}
document.querySelector("form").addEventListener("submit", function (event) {
event.preventDefault();
generateQRCode();
});