-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
46 lines (43 loc) · 1.35 KB
/
script.js
File metadata and controls
46 lines (43 loc) · 1.35 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
// QR Code Generator Script
const textInput = document.getElementById('textInput');
const generateBtn = document.getElementById('generateBtn');
const qrcodeDiv = document.getElementById('qrcode');
const copyBtn = document.getElementById('copyBtn');
// Generate QR Code
generateBtn.addEventListener('click', () => {
const text = textInput.value.trim();
qrcodeDiv.innerHTML = '';
if (text) {
new QRCode(qrcodeDiv, {
text: text,
width: 256,
height: 256,
colorDark: '#000000',
colorLight: '#ffffff',
correctLevel: QRCode.CorrectLevel.H
});
copyBtn.disabled = false;
} else {
alert('Please enter a URL or text!');
copyBtn.disabled = true;
}
});
// Copy QR Code Image to Clipboard
copyBtn.addEventListener('click', () => {
const qrCanvas = qrcodeDiv.querySelector('canvas');
if (qrCanvas) {
qrCanvas.toBlob((blob) => {
const item = new ClipboardItem({ 'image/png': blob });
navigator.clipboard.write([item]).then(() => {
alert('QR code image copied to clipboard!');
}).catch(err => {
console.error('Failed to copy image:', err);
alert('Failed to copy image. Please try again or right-click to save manually.');
});
});
} else {
alert('No QR code to copy. Generate a QR code first!');
}
});
// Disable copy button initially
copyBtn.disabled = true;