-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
43 lines (34 loc) · 1.09 KB
/
Copy pathscript.js
File metadata and controls
43 lines (34 loc) · 1.09 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
let inp = document.querySelector("input");
let btn = document.querySelector("button");
let qrBox = document.getElementById("qrBox");
function qrCodeGenerator(){
if(inp.value === ""){
document.querySelector(".alertbox").style.display = "block";
document.querySelector(".down").style.display = "none";
qrBox.innerText = "";
}else{
document.querySelector(".alertbox").style.display = "none";
document.querySelector(".down").style.display = "block";
qrBox.innerText = "";
new QRCode(qrBox, {
text: inp.value,
colorLight: "#7c7c7c33"
});
}
}
btn.addEventListener("click", qrCodeGenerator);
inp.addEventListener("keydown", function(e){
if(e.key === "Enter"){
qrCodeGenerator();
}
})
let downBtn = document.querySelector(".down");
downBtn.addEventListener("click", function(){
let img = qrBox.querySelector("img");
if(!img) return;
let link = document.createElement("a");
link.href = img.src;
link.download = "qrcode.png";
link.click();
downBtn.appendChild("link");
})