24 lines
843 B
JavaScript
24 lines
843 B
JavaScript
|
const main = document.querySelector(".main"),
|
||
|
qrInput = main.querySelector(".form input"),
|
||
|
generateBtn = main.querySelector(".form button"),
|
||
|
qrImg = main.querySelector(".qr-code img");
|
||
|
let preValue;
|
||
|
|
||
|
generateBtn.addEventListener("click", () => {
|
||
|
let qrValue = qrInput.value.trim();
|
||
|
if(!qrValue || preValue === qrValue) return;
|
||
|
preValue = qrValue;
|
||
|
generateBtn.innerText = "Generating QR Code...";
|
||
|
qrImg.src = `https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${qrValue}`;
|
||
|
qrImg.addEventListener("load", () => {
|
||
|
main.classList.add("active");
|
||
|
generateBtn.innerText = "Generate QR Code";
|
||
|
});
|
||
|
});
|
||
|
qrInput.addEventListener("keyup", () => {
|
||
|
if(!qrInput.value.trim()) {
|
||
|
main.classList.remove("active");
|
||
|
preValue = "";
|
||
|
}
|
||
|
});
|
||
|
// https://goqr.me/api/
|