-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
68 lines (60 loc) · 2.45 KB
/
script.js
File metadata and controls
68 lines (60 loc) · 2.45 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
document.addEventListener("DOMContentLoaded", () => {
const qrOptions = {
width: 300,
height: 300,
type: "svg",
data: "https://fosspel.github.io/qr-code-generator/",
image: "",
dotsOptions: { color: "#000000", type: "square" },
backgroundOptions: { color: "#ffffff" },
imageOptions: { crossOrigin: "anonymous", margin: 10 }
};
const qrCode = new QRCodeStyling(qrOptions);
qrCode.append(document.getElementById("qr-code-container"));
const qrText = document.getElementById("qr-text");
const qrSize = document.getElementById("qr-size");
const qrSizeValue = document.getElementById("qr-size-value");
const qrColor = document.getElementById("qr-color");
const qrBgColor = document.getElementById("qr-bg-color");
const dotStyle = document.getElementById("dot-style");
const logoUpload = document.getElementById("logo-upload");
const removeLogoBtn = document.getElementById("remove-logo");
const downloadBtn = document.getElementById("download-btn");
const updateQRCode = () => {
const size = parseInt(qrSize.value, 10);
qrCode.update({
width: size,
height: size,
data: qrText.value.trim() === "" ? " " : qrText.value,
dotsOptions: { color: qrColor.value, type: dotStyle.value },
backgroundOptions: { color: qrBgColor.value }
});
};
qrText.addEventListener("input", updateQRCode);
qrSize.addEventListener("input", () => {
qrSizeValue.textContent = `${qrSize.value}px`;
updateQRCode();
});
qrColor.addEventListener("input", updateQRCode);
qrBgColor.addEventListener("input", updateQRCode);
dotStyle.addEventListener("change", updateQRCode);
logoUpload.addEventListener("change", (e) => {
if (e.target.files && e.target.files[0]) {
const reader = new FileReader();
reader.onload = (event) => {
qrCode.update({ image: event.target.result });
removeLogoBtn.classList.remove("hidden");
};
reader.readAsDataURL(e.target.files[0]);
}
});
removeLogoBtn.addEventListener("click", () => {
qrCode.update({ image: "" });
logoUpload.value = "";
removeLogoBtn.classList.add("hidden");
});
downloadBtn.addEventListener("click", () => {
qrCode.download({ name: "qrcode", extension: "png" });
});
updateQRCode();
});