-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
51 lines (42 loc) · 1.71 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
const qrCodeSettings = document.getElementById("qrcode-settings"),
qrcodeContainer = document.getElementById("qrcode"),
generateBtn = document.getElementById("generate-btn"),
downloadBtn = document.getElementById("download-btn"),
downloadBtnContainer = document.querySelector(".download-btn-container");
qrCodeSettings.onsubmit = function (e) {
e.preventDefault()
qrcodeContainer.innerHTML = ""
const formData_ = new FormData(qrCodeSettings, generateBtn)
const userInputs = {}
for (const [key, value] of formData_) {
userInputs[key] = value
}
const settings = {
text: userInputs.text,
width: userInputs.qrcodeWidth,
height: userInputs.qrcodeWidth,
typeNumber: 4,
colorDark: userInputs.txtColor,
colorLight: userInputs.bgColor,
quietZone: 10,
quietZoneColor: userInputs.bgColor,
}
if (userInputs.customLogo.name) {
settings.logo = URL.createObjectURL(userInputs.customLogo)
settings.logoBackgroundColor = userInputs.logoBg
settings.logoBackgroundTransparent = userInputs.isTransparent
settings.logoWidth = userInputs.logoWidth
settings.logoHeight = userInputs.logoWidth
}
console.log("user inputs: ", userInputs, settings)
const qrcode_ = new QRCode(qrcodeContainer, settings)
downloadBtnContainer.classList.remove("hidden")
}
downloadBtn.onclick = function(){
const qrcodeImage = document.querySelector("#qrcode canvas")
const data = qrcodeImage.toDataURL("image/png"),
aEl = document.createElement("a")
aEl.href = data
aEl.download = new Date().toLocaleDateString() + ".png"
aEl.click()
}