diff --git a/index.html b/index.html index 631dc4b..cd6d860 100644 --- a/index.html +++ b/index.html @@ -43,9 +43,19 @@ Powered by muathye.com

- + + + +
+
+ + +
+
+ + +
+
diff --git a/script.js b/script.js index 03b94f8..2493e11 100644 --- a/script.js +++ b/script.js @@ -2,13 +2,22 @@ document.getElementById('generate-btn').addEventListener('click', () => { const text = document.getElementById('text-input').value; const canvas = document.getElementById('qr-code'); const downloadButtons = document.getElementById('download-buttons'); + const foregroundColor = document.getElementById('foreground-color').value; + const backgroundColor = document.getElementById('background-color').value; if (text) { - QRCode.toCanvas(canvas, text, function (error) { + // First, draw the basic QR code + QRCode.toCanvas(canvas, text, { + color: { + dark: foregroundColor, + light: backgroundColor + } + }, function (error) { if (error) { console.error(error); return; } + console.log('QR code generated!'); downloadButtons.classList.remove('hidden'); // Show download buttons }); @@ -18,8 +27,18 @@ document.getElementById('generate-btn').addEventListener('click', () => { // Download QR Code as SVG document.getElementById('download-svg').addEventListener('click', () => { const text = document.getElementById('text-input').value; + const foregroundColor = document.getElementById('foreground-color').value; + const backgroundColor = document.getElementById('background-color').value; + + const options = { + color: { + dark: foregroundColor, + light: backgroundColor + } + }; + if (text) { - QRCode.toString(text, { type: 'svg' }, function (error, svg) { + QRCode.toString(text, { type: 'svg', color: options.color }, function (error, svg) { if (error) { console.error(error); return; @@ -39,25 +58,15 @@ document.getElementById('download-svg').addEventListener('click', () => { // Download QR Code as PNG document.getElementById('download-png').addEventListener('click', () => { - const text = document.getElementById('text-input').value; const canvas = document.getElementById('qr-code'); - - if (text) { - QRCode.toCanvas(canvas, text, function (error) { - if (error) { - console.error(error); - return; - } - canvas.toBlob(function (blob) { - const url = URL.createObjectURL(blob); - const link = document.createElement('a'); - link.href = url; - link.download = 'qrcode.png'; - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); - URL.revokeObjectURL(url); - }, 'image/png'); - }); - } + canvas.toBlob(function (blob) { + const url = URL.createObjectURL(blob); + const link = document.createElement('a'); + link.href = url; + link.download = 'qrcode.png'; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + URL.revokeObjectURL(url); + }, 'image/png'); });