File size: 3,150 Bytes
474324c
 
5875fd6
474324c
 
 
5875fd6
 
474324c
 
 
 
 
 
 
5875fd6
 
474324c
 
 
5875fd6
474324c
 
 
5875fd6
474324c
5875fd6
474324c
 
 
 
 
 
 
864d4cd
3f8536b
474324c
 
 
3f8536b
474324c
 
 
5875fd6
864d4cd
474324c
 
 
ec7940e
 
3f8536b
474324c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5875fd6
3f8536b
474324c
 
 
 
 
 
 
 
 
 
5875fd6
ec7940e
474324c
 
 
 
 
 
864d4cd
474324c
 
 
 
 
 
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
let qrCode = null;
let currentQRText = '';

// Update character count
document.getElementById('inputText').addEventListener('input', function() {
    document.getElementById('textLength').textContent = this.value.length;
});

// Generate QR Code
function generateQR() {
    const text = document.getElementById('inputText').value.trim();
    
    if (!text) {
        alert('❌ Please enter some text or URL');
        return;
    }

    currentQRText = text;
    const size = parseInt(document.getElementById('sizeSelect').value);
    const errorCorrection = document.getElementById('errorSelect').value;

    // Clear previous QR code
    const container = document.getElementById('qrcodeContainer');
    container.innerHTML = '';

    // Generate new QR code
    try {
        qrCode = new QRCode(container, {
            text: text,
            width: size,
            height: size,
            colorDark: '#000000',
            colorLight: '#ffffff',
            correctLevel: QRCode.CorrectLevel[errorCorrection]
        });

        // Show download buttons
        document.getElementById('downloadPNG').style.display = 'block';
        document.getElementById('downloadJPG').style.display = 'block';

        // Update status
        document.getElementById('status').textContent = 'βœ… QR Code Generated';
        document.getElementById('status').style.color = '#4CAF50';

    } catch (error) {
        alert('❌ Error generating QR code: ' + error.message);
        document.getElementById('status').textContent = '❌ Error generating QR code';
        document.getElementById('status').style.color = '#f44336';
    }
}

// Download QR Code
function downloadQR(format) {
    const canvas = document.querySelector('#qrcodeContainer canvas');
    
    if (!canvas) {
        alert('❌ Please generate QR code first');
        return;
    }

    let link = document.createElement('a');
    
    if (format === 'png') {
        link.download = 'qrcode.png';
        link.href = canvas.toDataURL('image/png');
    } else if (format === 'jpg') {
        link.download = 'qrcode.jpg';
        link.href = canvas.toDataURL('image/jpeg', 0.95);
    }

    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
}

// Clear all
function clearAll() {
    document.getElementById('inputText').value = '';
    document.getElementById('qrcodeContainer').innerHTML = '';
    document.getElementById('downloadPNG').style.display = 'none';
    document.getElementById('downloadJPG').style.display = 'none';
    document.getElementById('textLength').textContent = '0';
    document.getElementById('status').textContent = 'No QR generated yet';
    document.getElementById('status').style.color = '#666';
    currentQRText = '';
}

// Set example
function setExample(text) {
    document.getElementById('inputText').value = text;
    document.getElementById('textLength').textContent = text.length;
    setTimeout(generateQR, 100);
}

// Allow Enter key to generate
document.getElementById('inputText').addEventListener('keydown', function(e) {
    if (e.ctrlKey && e.key === 'Enter') {
        generateQR();
    }
});