Spaces:
Running
Running
Download index.html from Examups/QR_Generator: direct link, hf CLI and curl.
- Browser
- Download file 34.3 kB
-
https://huggingface.co/spaces/Examups/QR_Generator/resolve/main/index.html
- Command line
-
hf download hf://spaces/Examups/QR_Generator/index.html
-
curl -L -o index.html https://huggingface.co/spaces/Examups/QR_Generator/resolve/main/index.html
34.3 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Advanced QR Code Generator</title> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> | |
| <style> | |
| :root { | |
| --primary: #4361ee; | |
| --secondary: #3f37c9; | |
| --accent: #4895ef; | |
| --dark: #212529; | |
| --light: #f8f9fa; | |
| --success: #4cc9f0; | |
| --danger: #f72585; | |
| --warning: #f8961e; | |
| --border-radius: 8px; | |
| --box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); | |
| } | |
| * { | |
| box-sizing: border-box; | |
| margin: 0; | |
| padding: 0; | |
| font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; | |
| } | |
| body { | |
| background-color: #f5f7fa; | |
| display: flex; | |
| justify-content: center; | |
| align-items: center; | |
| min-height: 100vh; | |
| padding: 20px; | |
| color: var(--dark); | |
| } | |
| .container { | |
| background-color: white; | |
| border-radius: var(--border-radius); | |
| box-shadow: var(--box-shadow); | |
| padding: 2rem; | |
| width: 100%; | |
| max-width: 600px; | |
| text-align: center; | |
| transition: all 0.3s ease; | |
| } | |
| h1 { | |
| color: var(--primary); | |
| margin-bottom: 1.5rem; | |
| font-size: 2rem; | |
| font-weight: 700; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| gap: 0.5rem; | |
| } | |
| .tabs { | |
| display: flex; | |
| margin-bottom: 1.5rem; | |
| border-bottom: 1px solid #e9ecef; | |
| flex-wrap: wrap; | |
| } | |
| .tab { | |
| padding: 0.75rem 1.5rem; | |
| cursor: pointer; | |
| border-bottom: 3px solid transparent; | |
| font-weight: 600; | |
| color: #6c757d; | |
| transition: all 0.3s ease; | |
| white-space: nowrap; | |
| } | |
| .tab.active { | |
| color: var(--primary); | |
| border-bottom-color: var(--primary); | |
| } | |
| .tab-content { | |
| display: none; | |
| } | |
| .tab-content.active { | |
| display: block; | |
| } | |
| .input-group { | |
| margin-bottom: 1.25rem; | |
| text-align: left; | |
| } | |
| label { | |
| display: block; | |
| margin-bottom: 0.5rem; | |
| font-weight: 600; | |
| color: #495057; | |
| font-size: 0.9rem; | |
| } | |
| input, select, textarea { | |
| width: 100%; | |
| padding: 0.75rem; | |
| border: 1px solid #ced4da; | |
| border-radius: var(--border-radius); | |
| font-size: 1rem; | |
| transition: all 0.3s; | |
| } | |
| input:focus, select:focus, textarea:focus { | |
| border-color: var(--accent); | |
| outline: none; | |
| box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.2); | |
| } | |
| .color-picker { | |
| display: flex; | |
| gap: 1rem; | |
| } | |
| .color-option { | |
| flex: 1; | |
| } | |
| .color-input { | |
| height: 40px; | |
| padding: 0.25rem; | |
| cursor: pointer; | |
| } | |
| .btn { | |
| background-color: var(--primary); | |
| color: white; | |
| border: none; | |
| padding: 0.75rem 1.5rem; | |
| border-radius: var(--border-radius); | |
| cursor: pointer; | |
| font-size: 1rem; | |
| font-weight: 600; | |
| width: 100%; | |
| transition: all 0.3s; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| gap: 0.5rem; | |
| } | |
| .btn:hover { | |
| background-color: var(--secondary); | |
| transform: translateY(-2px); | |
| } | |
| .btn-secondary { | |
| background-color: #6c757d; | |
| } | |
| .btn-secondary:hover { | |
| background-color: #5a6268; | |
| } | |
| .btn-success { | |
| background-color: var(--success); | |
| } | |
| .btn-success:hover { | |
| background-color: #3aa8d8; | |
| } | |
| .qr-container { | |
| margin: 2rem 0; | |
| display: flex; | |
| flex-direction: column; | |
| align-items: center; | |
| min-height: 256px; | |
| position: relative; | |
| } | |
| #qrCode { | |
| max-width: 100%; | |
| max-height: 300px; | |
| border: 1px solid #e9ecef; | |
| padding: 1rem; | |
| background-color: white; | |
| box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05); | |
| margin-bottom: 10px; | |
| } | |
| .qr-text-display { | |
| width: 100%; | |
| text-align: center; | |
| font-weight: bold; | |
| color: var(--dark); | |
| padding: 5px 0; | |
| max-width: 300px; | |
| word-wrap: break-word; | |
| } | |
| .action-buttons { | |
| display: flex; | |
| gap: 1rem; | |
| margin-top: 1.5rem; | |
| } | |
| .action-buttons .btn { | |
| width: auto; | |
| flex: 1; | |
| } | |
| .error { | |
| color: var(--danger); | |
| margin-top: 0.5rem; | |
| font-size: 0.875rem; | |
| display: none; | |
| } | |
| .success { | |
| color: var(--success); | |
| margin-top: 0.5rem; | |
| font-size: 0.875rem; | |
| display: none; | |
| } | |
| .advanced-options { | |
| margin-top: 1.5rem; | |
| padding: 1rem; | |
| background-color: #f8f9fa; | |
| border-radius: var(--border-radius); | |
| border: 1px dashed #dee2e6; | |
| } | |
| .advanced-options h3 { | |
| margin-bottom: 1rem; | |
| font-size: 1rem; | |
| color: #495057; | |
| display: flex; | |
| align-items: center; | |
| justify-content: space-between; | |
| cursor: pointer; | |
| } | |
| .logo-upload { | |
| display: flex; | |
| flex-direction: column; | |
| gap: 0.5rem; | |
| margin-top: 1rem; | |
| } | |
| .logo-preview { | |
| width: 60px; | |
| height: 60px; | |
| border: 1px dashed #ced4da; | |
| border-radius: var(--border-radius); | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| overflow: hidden; | |
| margin: 0 auto; | |
| } | |
| .logo-preview img { | |
| max-width: 100%; | |
| max-height: 100%; | |
| } | |
| .text-in-qr-options { | |
| margin-top: 1rem; | |
| } | |
| .filename-input { | |
| margin-top: 1rem; | |
| } | |
| @media (max-width: 576px) { | |
| .container { | |
| padding: 1.5rem; | |
| } | |
| .action-buttons { | |
| flex-direction: column; | |
| gap: 0.75rem; | |
| } | |
| .color-picker { | |
| flex-direction: column; | |
| gap: 0.75rem; | |
| } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| <h1><i class="fas fa-qrcode"></i> Advanced QR Generator</h1> | |
| <div class="tabs"> | |
| <div class="tab active" data-tab="url">URL</div> | |
| <div class="tab" data-tab="text">Text</div> | |
| <div class="tab" data-tab="contact">Contact</div> | |
| <div class="tab" data-tab="wifi">Wi-Fi</div> | |
| </div> | |
| <!-- URL Tab --> | |
| <div class="tab-content active" id="url-tab"> | |
| <div class="input-group"> | |
| <label for="url">Website URL</label> | |
| <input type="url" id="url" placeholder="https://example.com"> | |
| </div> | |
| </div> | |
| <!-- Text Tab --> | |
| <div class="tab-content" id="text-tab"> | |
| <div class="input-group"> | |
| <label for="text">Text Content</label> | |
| <textarea id="text" rows="3" placeholder="Enter any text you want to encode"></textarea> | |
| </div> | |
| </div> | |
| <!-- Contact Tab --> | |
| <div class="tab-content" id="contact-tab"> | |
| <div class="input-group"> | |
| <label for="contact-name">Name</label> | |
| <input type="text" id="contact-name" placeholder="John Doe"> | |
| </div> | |
| <div class="input-group"> | |
| <label for="contact-phone">Phone</label> | |
| <input type="tel" id="contact-phone" placeholder="+1234567890"> | |
| </div> | |
| <div class="input-group"> | |
| <label for="contact-email">Email</label> | |
| <input type="email" id="contact-email" placeholder="example@email.com"> | |
| </div> | |
| <div class="input-group"> | |
| <label for="contact-company">Company</label> | |
| <input type="text" id="contact-company" placeholder="Company Name"> | |
| </div> | |
| </div> | |
| <!-- Wi-Fi Tab --> | |
| <div class="tab-content" id="wifi-tab"> | |
| <div class="input-group"> | |
| <label for="wifi-ssid">Network Name (SSID)</label> | |
| <input type="text" id="wifi-ssid" placeholder="MyWiFiNetwork"> | |
| </div> | |
| <div class="input-group"> | |
| <label for="wifi-password">Password</label> | |
| <input type="text" id="wifi-password" placeholder="Password"> | |
| </div> | |
| <div class="input-group"> | |
| <label for="wifi-security">Security Type</label> | |
| <select id="wifi-security"> | |
| <option value="WPA">WPA/WPA2</option> | |
| <option value="WEP">WEP</option> | |
| <option value="">None (Open Network)</option> | |
| </select> | |
| </div> | |
| </div> | |
| <div class="advanced-options"> | |
| <h3> | |
| <span><i class="fas fa-cog"></i> Advanced Options</span> | |
| <i class="fas fa-chevron-down"></i> | |
| </h3> | |
| <div class="advanced-content"> | |
| <!-- New Filename Input --> | |
| <div class="input-group filename-input"> | |
| <label for="filename">File Name (without extension)</label> | |
| <input type="text" id="filename" placeholder="my-qr-code"> | |
| </div> | |
| <div class="input-group"> | |
| <label for="qrSize">QR Code Size</label> | |
| <select id="qrSize"> | |
| <option value="100">100x100</option> | |
| <option value="150">150x150</option> | |
| <option value="200" selected>200x200</option> | |
| <option value="250">250x250</option> | |
| <option value="300">300x300</option> | |
| <option value="400">400x400</option> | |
| </select> | |
| </div> | |
| <div class="input-group"> | |
| <label for="qrErrorCorrection">Error Correction</label> | |
| <select id="qrErrorCorrection"> | |
| <option value="L">Low (7%)</option> | |
| <option value="M" selected>Medium (15%)</option> | |
| <option value="Q">Quartile (25%)</option> | |
| <option value="H">High (30%)</option> | |
| </select> | |
| </div> | |
| <div class="color-picker"> | |
| <div class="color-option input-group"> | |
| <label for="qrColor">QR Color</label> | |
| <input type="color" id="qrColor" class="color-input" value="#000000"> | |
| </div> | |
| <div class="color-option input-group"> | |
| <label for="qrBgColor">Background Color</label> | |
| <input type="color" id="qrBgColor" class="color-input" value="#ffffff"> | |
| </div> | |
| </div> | |
| <div class="input-group"> | |
| <label>Add Logo (Optional)</label> | |
| <div class="logo-upload"> | |
| <input type="file" id="logoUpload" accept="image/*" style="display: none;"> | |
| <button class="btn btn-secondary" id="uploadBtn"><i class="fas fa-upload"></i> Choose Logo</button> | |
| <div class="logo-preview" id="logoPreview"> | |
| <i class="fas fa-image" style="color: #adb5bd;"></i> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="input-group text-in-qr-options"> | |
| <label for="qrText">Text Below QR Code (Optional)</label> | |
| <input type="text" id="qrText" placeholder="Text to display below QR code"> | |
| </div> | |
| <div class="input-group"> | |
| <label for="textColor">Text Color</label> | |
| <input type="color" id="textColor" class="color-input" value="#000000"> | |
| </div> | |
| <div class="input-group"> | |
| <label for="textSize">Text Size</label> | |
| <select id="textSize"> | |
| <option value="12">Small</option> | |
| <option value="16" selected>Medium</option> | |
| <option value="20">Large</option> | |
| <option value="24">Extra Large</option> | |
| </select> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="error" id="errorMsg"></div> | |
| <div class="success" id="successMsg"></div> | |
| <button class="btn" id="generateBtn"><i class="fas fa-qrcode"></i> Generate QR Code</button> | |
| <div class="qr-container"> | |
| <canvas id="qrCode"></canvas> | |
| <div class="qr-text-display" id="qrTextDisplay"></div> | |
| </div> | |
| <div class="action-buttons"> | |
| <button class="btn btn-success" id="downloadPngBtn"><i class="fas fa-download"></i> PNG</button> | |
| <button class="btn btn-success" id="downloadJpgBtn"><i class="fas fa-download"></i> JPG</button> | |
| <button class="btn btn-success" id="downloadSvgBtn"><i class="fas fa-download"></i> SVG</button> | |
| </div> | |
| </div> | |
| <script src="https://cdn.jsdelivr.net/npm/qrcode@1.5.1/build/qrcode.min.js"></script> | |
| <script> | |
| document.addEventListener('DOMContentLoaded', function() { | |
| // DOM Elements | |
| const tabs = document.querySelectorAll('.tab'); | |
| const tabContents = document.querySelectorAll('.tab-content'); | |
| const urlInput = document.getElementById('url'); | |
| const textInput = document.getElementById('text'); | |
| const contactName = document.getElementById('contact-name'); | |
| const contactPhone = document.getElementById('contact-phone'); | |
| const contactEmail = document.getElementById('contact-email'); | |
| const contactCompany = document.getElementById('contact-company'); | |
| const wifiSsid = document.getElementById('wifi-ssid'); | |
| const wifiPassword = document.getElementById('wifi-password'); | |
| const wifiSecurity = document.getElementById('wifi-security'); | |
| const qrSize = document.getElementById('qrSize'); | |
| const qrErrorCorrection = document.getElementById('qrErrorCorrection'); | |
| const qrColor = document.getElementById('qrColor'); | |
| const qrBgColor = document.getElementById('qrBgColor'); | |
| const uploadBtn = document.getElementById('uploadBtn'); | |
| const logoUpload = document.getElementById('logoUpload'); | |
| const logoPreview = document.getElementById('logoPreview'); | |
| const generateBtn = document.getElementById('generateBtn'); | |
| const downloadPngBtn = document.getElementById('downloadPngBtn'); | |
| const downloadJpgBtn = document.getElementById('downloadJpgBtn'); | |
| const downloadSvgBtn = document.getElementById('downloadSvgBtn'); | |
| const errorMsg = document.getElementById('errorMsg'); | |
| const successMsg = document.getElementById('successMsg'); | |
| const qrCodeCanvas = document.getElementById('qrCode'); | |
| const qrTextDisplay = document.getElementById('qrTextDisplay'); | |
| const advancedOptions = document.querySelector('.advanced-options h3'); | |
| const advancedContent = document.querySelector('.advanced-content'); | |
| const qrTextInput = document.getElementById('qrText'); | |
| const textColor = document.getElementById('textColor'); | |
| const textSize = document.getElementById('textSize'); | |
| const filenameInput = document.getElementById('filename'); | |
| // Variables | |
| let currentTab = 'url'; | |
| let logoImage = null; | |
| // Tab Switching | |
| tabs.forEach(tab => { | |
| tab.addEventListener('click', () => { | |
| tabs.forEach(t => t.classList.remove('active')); | |
| tabContents.forEach(c => c.classList.remove('active')); | |
| tab.classList.add('active'); | |
| currentTab = tab.dataset.tab; | |
| document.getElementById(`${currentTab}-tab`).classList.add('active'); | |
| }); | |
| }); | |
| // Advanced Options Toggle | |
| advancedOptions.addEventListener('click', () => { | |
| advancedContent.style.display = advancedContent.style.display === 'none' ? 'block' : 'none'; | |
| const icon = advancedOptions.querySelector('.fa-chevron-down'); | |
| icon.style.transform = advancedContent.style.display === 'none' ? 'rotate(0deg)' : 'rotate(180deg)'; | |
| }); | |
| // Initially hide advanced content | |
| advancedContent.style.display = 'none'; | |
| // Logo Upload | |
| uploadBtn.addEventListener('click', () => logoUpload.click()); | |
| logoUpload.addEventListener('change', function(e) { | |
| const file = e.target.files[0]; | |
| if (file) { | |
| const reader = new FileReader(); | |
| reader.onload = function(event) { | |
| logoImage = new Image(); | |
| logoImage.src = event.target.result; | |
| logoImage.onload = function() { | |
| logoPreview.innerHTML = ''; | |
| logoPreview.appendChild(logoImage); | |
| }; | |
| }; | |
| reader.readAsDataURL(file); | |
| showSuccess('Logo uploaded successfully!'); | |
| } | |
| }); | |
| // Generate QR Code | |
| generateBtn.addEventListener('click', generateQRCode); | |
| // Download Buttons | |
| downloadPngBtn.addEventListener('click', () => downloadQRCode('png')); | |
| downloadJpgBtn.addEventListener('click', () => downloadQRCode('jpeg')); | |
| downloadSvgBtn.addEventListener('click', downloadQRCodeAsSvg); | |
| // Generate on Enter key | |
| document.addEventListener('keypress', function(e) { | |
| if (e.key === 'Enter') { | |
| generateQRCode(); | |
| } | |
| }); | |
| // Main QR Generation Function | |
| function generateQRCode() { | |
| let content = ''; | |
| // Get content based on current tab | |
| switch(currentTab) { | |
| case 'url': | |
| content = urlInput.value.trim(); | |
| if (!content) { | |
| showError('Please enter a valid URL'); | |
| return; | |
| } | |
| if (!content.startsWith('http://') && !content.startsWith('https://')) { | |
| content = 'http://' + content; | |
| } | |
| break; | |
| case 'text': | |
| content = textInput.value.trim(); | |
| if (!content) { | |
| showError('Please enter some text'); | |
| return; | |
| } | |
| break; | |
| case 'contact': | |
| const name = contactName.value.trim(); | |
| const phone = contactPhone.value.trim(); | |
| const email = contactEmail.value.trim(); | |
| const company = contactCompany.value.trim(); | |
| if (!name && !phone && !email && !company) { | |
| showError('Please enter at least one contact detail'); | |
| return; | |
| } | |
| content = `BEGIN:VCARD\nVERSION:3.0\n`; | |
| if (name) content += `FN:${name}\nN:${name.split(' ').reverse().join(';')};;;\n`; | |
| if (phone) content += `TEL:${phone}\n`; | |
| if (email) content += `EMAIL:${email}\n`; | |
| if (company) content += `ORG:${company}\n`; | |
| content += `END:VCARD`; | |
| break; | |
| case 'wifi': | |
| const ssid = wifiSsid.value.trim(); | |
| const password = wifiPassword.value.trim(); | |
| const security = wifiSecurity.value; | |
| if (!ssid) { | |
| showError('Please enter a network name (SSID)'); | |
| return; | |
| } | |
| content = `WIFI:T:${security};S:${ssid};`; | |
| if (password) content += `P:${password};`; | |
| content += `;`; | |
| break; | |
| } | |
| // Clear previous errors | |
| errorMsg.style.display = 'none'; | |
| // QR Code options | |
| const options = { | |
| width: parseInt(qrSize.value), | |
| errorCorrectionLevel: qrErrorCorrection.value, | |
| margin: 2, | |
| color: { | |
| dark: qrColor.value, | |
| light: qrBgColor.value | |
| } | |
| }; | |
| // Generate QR Code | |
| QRCode.toCanvas(qrCodeCanvas, content, options, function(error) { | |
| if (error) { | |
| showError('Error generating QR code: ' + error.message); | |
| return; | |
| } | |
| // Add logo if uploaded | |
| if (logoImage) { | |
| addLogoToQRCode(); | |
| } | |
| // Display text below QR code | |
| const text = qrTextInput.value.trim(); | |
| if (text) { | |
| qrTextDisplay.textContent = text; | |
| qrTextDisplay.style.fontSize = textSize.value + 'px'; | |
| qrTextDisplay.style.color = textColor.value; | |
| qrTextDisplay.style.display = 'block'; | |
| } else { | |
| qrTextDisplay.style.display = 'none'; | |
| } | |
| showSuccess('QR Code generated successfully!'); | |
| }); | |
| } | |
| // Add Logo to QR Code | |
| function addLogoToQRCode() { | |
| const ctx = qrCodeCanvas.getContext('2d'); | |
| const center = qrCodeCanvas.width / 2; | |
| const logoSize = qrCodeCanvas.width * 0.2; // Logo size is 20% of QR code size | |
| // Draw white background for logo | |
| ctx.fillStyle = qrBgColor.value; | |
| ctx.fillRect( | |
| center - logoSize/2 - 5, | |
| center - logoSize/2 - 5, | |
| logoSize + 10, | |
| logoSize + 10 | |
| ); | |
| // Draw logo | |
| ctx.drawImage( | |
| logoImage, | |
| center - logoSize/2, | |
| center - logoSize/2, | |
| logoSize, | |
| logoSize | |
| ); | |
| } | |
| // Get filename with sanitization | |
| function getFilename(extension) { | |
| let filename = filenameInput.value.trim(); | |
| if (!filename) { | |
| // Default filename based on content type | |
| switch(currentTab) { | |
| case 'url': | |
| const url = new URL(urlInput.value.trim()); | |
| filename = `qr-${url.hostname.replace('www.', '')}`; | |
| break; | |
| case 'text': | |
| filename = 'qr-text-code'; | |
| break; | |
| case 'contact': | |
| filename = `qr-contact-${contactName.value.trim() || 'card'}`; | |
| break; | |
| case 'wifi': | |
| filename = `qr-wifi-${wifiSsid.value.trim() || 'network'}`; | |
| break; | |
| default: | |
| filename = 'qr-code'; | |
| } | |
| } | |
| // Sanitize filename | |
| filename = filename.replace(/[^a-z0-9\-]/gi, '_').toLowerCase(); | |
| return `${filename}.${extension}`; | |
| } | |
| // Download QR Code as Raster Image | |
| function downloadQRCode(format) { | |
| if (!qrCodeCanvas.toDataURL().includes('image/png')) { | |
| showError('Please generate a QR code first'); | |
| return; | |
| } | |
| // Create a temporary canvas to combine QR code and text | |
| const tempCanvas = document.createElement('canvas'); | |
| const tempCtx = tempCanvas.getContext('2d'); | |
| // Calculate dimensions | |
| const qrWidth = qrCodeCanvas.width; | |
| const qrHeight = qrCodeCanvas.height; | |
| const textHeight = qrTextDisplay.style.display === 'none' ? 0 : | |
| parseInt(getComputedStyle(qrTextDisplay).height); | |
| // Set temporary canvas dimensions | |
| tempCanvas.width = qrWidth; | |
| tempCanvas.height = qrHeight + (textHeight > 0 ? textHeight + 20 : 0); | |
| // Draw QR code | |
| tempCtx.drawImage(qrCodeCanvas, 0, 0); | |
| // Draw text if exists | |
| if (textHeight > 0) { | |
| tempCtx.font = `${textSize.value}px Arial`; | |
| tempCtx.fillStyle = textColor.value; | |
| tempCtx.textAlign = 'center'; | |
| tempCtx.fillText(qrTextDisplay.textContent, qrWidth/2, qrHeight + parseInt(textSize.value) + 10); | |
| } | |
| // Create download link | |
| const link = document.createElement('a'); | |
| link.download = getFilename(format); | |
| link.href = tempCanvas.toDataURL(`image/${format}`); | |
| link.click(); | |
| } | |
| // Download QR Code as SVG | |
| function downloadQRCodeAsSvg() { | |
| let content = ''; | |
| // Get content based on current tab (same as generateQRCode) | |
| switch(currentTab) { | |
| case 'url': | |
| content = urlInput.value.trim(); | |
| if (!content) { | |
| showError('Please enter a valid URL'); | |
| return; | |
| } | |
| if (!content.startsWith('http://') && !content.startsWith('https://')) { | |
| content = 'http://' + content; | |
| } | |
| break; | |
| case 'text': | |
| content = textInput.value.trim(); | |
| if (!content) { | |
| showError('Please enter some text'); | |
| return; | |
| } | |
| break; | |
| case 'contact': | |
| const name = contactName.value.trim(); | |
| const phone = contactPhone.value.trim(); | |
| const email = contactEmail.value.trim(); | |
| const company = contactCompany.value.trim(); | |
| if (!name && !phone && !email && !company) { | |
| showError('Please enter at least one contact detail'); | |
| return; | |
| } | |
| content = `BEGIN:VCARD\nVERSION:3.0\n`; | |
| if (name) content += `FN:${name}\nN:${name.split(' ').reverse().join(';')};;;\n`; | |
| if (phone) content += `TEL:${phone}\n`; | |
| if (email) content += `EMAIL:${email}\n`; | |
| if (company) content += `ORG:${company}\n`; | |
| content += `END:VCARD`; | |
| break; | |
| case 'wifi': | |
| const ssid = wifiSsid.value.trim(); | |
| const password = wifiPassword.value.trim(); | |
| const security = wifiSecurity.value; | |
| if (!ssid) { | |
| showError('Please enter a network name (SSID)'); | |
| return; | |
| } | |
| content = `WIFI:T:${security};S:${ssid};`; | |
| if (password) content += `P:${password};`; | |
| content += `;`; | |
| break; | |
| } | |
| // Generate SVG QR Code | |
| QRCode.toString(content, { | |
| type: 'svg', | |
| width: parseInt(qrSize.value), | |
| errorCorrectionLevel: qrErrorCorrection.value, | |
| margin: 2, | |
| color: { | |
| dark: qrColor.value, | |
| light: qrBgColor.value | |
| } | |
| }, function(error, svg) { | |
| if (error) { | |
| showError('Error generating SVG: ' + error.message); | |
| return; | |
| } | |
| // Add text to SVG if provided | |
| const text = qrTextInput.value.trim(); | |
| if (text) { | |
| const parser = new DOMParser(); | |
| const svgDoc = parser.parseFromString(svg, 'image/svg+xml'); | |
| const svgElement = svgDoc.querySelector('svg'); | |
| // Update SVG dimensions to include text | |
| const qrSizeValue = parseInt(qrSize.value); | |
| const newHeight = qrSizeValue + 40; // Extra space for text | |
| svgElement.setAttribute('height', newHeight); | |
| // Create text element | |
| const textElement = svgDoc.createElementNS('http://www.w3.org/2000/svg', 'text'); | |
| textElement.setAttribute('x', '50%'); | |
| textElement.setAttribute('y', qrSizeValue + 30); | |
| textElement.setAttribute('text-anchor', 'middle'); | |
| textElement.setAttribute('fill', textColor.value); | |
| textElement.setAttribute('font-size', textSize.value); | |
| textElement.setAttribute('font-weight', 'bold'); | |
| textElement.setAttribute('font-family', 'Arial'); | |
| textElement.textContent = text; | |
| svgElement.appendChild(textElement); | |
| svg = new XMLSerializer().serializeToString(svgDoc); | |
| } | |
| // Create download link | |
| const link = document.createElement('a'); | |
| link.download = getFilename('svg'); | |
| link.href = 'data:image/svg+xml,' + encodeURIComponent(svg); | |
| link.click(); | |
| }); | |
| } | |
| // Show error message | |
| function showError(message) { | |
| errorMsg.textContent = message; | |
| errorMsg.style.display = 'block'; | |
| setTimeout(() => errorMsg.style.display = 'none', 5000); | |
| } | |
| // Show success message | |
| function showSuccess(message) { | |
| successMsg.textContent = message; | |
| successMsg.style.display = 'block'; | |
| setTimeout(() => successMsg.style.display = 'none', 3000); | |
| } | |
| }); | |
| </script> | |
| </body> | |
| </html> |