-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
44 lines (37 loc) · 1.19 KB
/
script.js
File metadata and controls
44 lines (37 loc) · 1.19 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
/* Parameters in API call
data=HelloWorld
size=200x200 [ 10 - 1000] [integer]x[integer]
margin=50 [ 0 - 50 ] [integer]
color=000 FFFFFF
bgcolor=099 FFFFFF
ecc=L L,M,Q,H
format=png png,jpg
*/
const base_api_url = "https://api.qrserver.com/v1/create-qr-code/?";
var textInput = document.getElementById("textInput");
const qr_image_container = document.getElementById("qr-image-container");
const qr_image = document.getElementById("qr-image");
const error = document.getElementById("error");
function showQR() {
var encodedData = encodeURIComponent(textInput.value);
let url = base_api_url + "data=" + encodedData + "&size=200x200";
qr_image.src = url;
}
function loadQR() {
let timer;
clearTimeout(timer);
if (textInput.value === "") {
qr_image_container.style.display = "none";
error.innerHTML = "Input cannot be empty";
return;
} else {
qr_image_container.style.display = "grid";
error.innerHTML = "";
qr_image.src = "./loading.gif";
timer = setTimeout(() => {
showQR();
}, 800);
}
}
textInput.value = "Hello, World!";
loadQR();