qr-code-generator / index.html
FaxMe's picture
add a reset button so users can click a reset if they make a mistake - Initial Deployment
d2be290 verified
Raw History Blame Contribute Delete
15.2 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>QRify - URL to QR Code Converter</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<script src="https://cdn.jsdelivr.net/npm/qrcode-generator@1.4.4/qrcode.min.js"></script>
<style>
.gradient-bg {
background: linear-gradient(135deg, #6e8efb, #a777e3);
}
.qr-code-container {
transition: all 0.3s ease;
}
.qr-code-container:hover {
transform: translateY(-5px);
box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}
.input-field:focus {
box-shadow: 0 0 0 3px rgba(167, 119, 227, 0.5);
}
.download-btn {
transition: all 0.2s ease;
}
.download-btn:hover {
transform: scale(1.05);
}
@keyframes pulse {
0%, 100% {
opacity: 1;
}
50% {
opacity: 0.5;
}
}
.animate-pulse {
animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}
</style>
</head>
<body class="min-h-screen gradient-bg text-gray-100">
<div class="container mx-auto px-4 py-12">
<!-- Header -->
<header class="text-center mb-12">
<h1 class="text-4xl md:text-5xl font-bold mb-4">
<i class="fas fa-qrcode mr-3"></i>QRify
</h1>
<p class="text-xl md:text-2xl opacity-90">Convert any URL into a shareable QR code</p>
</header>
<!-- Main Content -->
<main class="max-w-3xl mx-auto">
<!-- Input Section -->
<div class="bg-white bg-opacity-10 backdrop-filter backdrop-blur-lg rounded-xl p-6 mb-8 shadow-xl">
<div class="flex flex-col md:flex-row gap-4">
<input
type="url"
id="urlInput"
placeholder="Enter your URL (e.g., https://example.com)"
class="input-field flex-grow px-4 py-3 rounded-lg bg-white bg-opacity-20 border border-white border-opacity-30 focus:outline-none focus:border-purple-300 placeholder-white placeholder-opacity-70"
>
<button
id="generateBtn"
class="px-6 py-3 bg-purple-600 hover:bg-purple-700 rounded-lg font-semibold transition-colors flex items-center justify-center"
>
<i class="fas fa-bolt mr-2"></i> Generate
</button>
<button
id="resetBtn"
class="px-6 py-3 bg-white bg-opacity-20 hover:bg-opacity-30 rounded-lg font-semibold transition-colors flex items-center justify-center"
>
<i class="fas fa-undo mr-2"></i> Reset
</button>
</div>
<div id="errorMessage" class="mt-2 text-red-300 text-sm hidden"></div>
</div>
<!-- QR Code Display Section -->
<div id="qrSection" class="hidden">
<div class="bg-white bg-opacity-10 backdrop-filter backdrop-blur-lg rounded-xl p-8 shadow-xl">
<h2 class="text-2xl font-semibold mb-6 text-center">Your QR Code is Ready!</h2>
<div class="flex flex-col lg:flex-row items-center gap-8">
<!-- QR Code Container -->
<div class="qr-code-container bg-white p-4 rounded-lg flex-1 max-w-xs mx-auto">
<div id="qrCode" class="w-full h-full"></div>
</div>
<!-- Details and Actions -->
<div class="flex-1">
<div class="mb-6">
<h3 class="text-lg font-medium mb-2">Destination URL:</h3>
<p id="destinationUrl" class="break-all bg-white bg-opacity-10 px-3 py-2 rounded"></p>
</div>
<div class="flex flex-wrap gap-3">
<button id="downloadBtn" class="download-btn px-5 py-2 bg-white text-purple-700 rounded-lg font-medium flex items-center">
<i class="fas fa-download mr-2"></i> Download
</button>
<button id="shareBtn" class="download-btn px-5 py-2 bg-purple-600 hover:bg-purple-700 rounded-lg font-medium flex items-center">
<i class="fas fa-share-alt mr-2"></i> Share
</button>
<button id="copyBtn" class="download-btn px-5 py-2 bg-white bg-opacity-20 hover:bg-opacity-30 rounded-lg font-medium flex items-center">
<i class="fas fa-copy mr-2"></i> Copy Link
</button>
</div>
</div>
</div>
</div>
</div>
<!-- Loading State -->
<div id="loadingSection" class="hidden text-center py-12">
<div class="animate-pulse flex flex-col items-center">
<div class="w-16 h-16 bg-white bg-opacity-20 rounded-full mb-4"></div>
<div class="h-4 bg-white bg-opacity-20 rounded w-1/3 mb-2"></div>
<div class="h-4 bg-white bg-opacity-20 rounded w-1/2"></div>
</div>
</div>
</main>
<!-- Features Section -->
<section class="max-w-6xl mx-auto mt-16">
<h2 class="text-2xl md:text-3xl font-bold text-center mb-8">Why Use QRify?</h2>
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
<div class="bg-white bg-opacity-10 backdrop-filter backdrop-blur-lg rounded-xl p-6">
<div class="text-purple-300 mb-4 text-3xl">
<i class="fas fa-bolt"></i>
</div>
<h3 class="text-xl font-semibold mb-2">Instant Generation</h3>
<p class="opacity-90">Create QR codes in seconds with our lightning-fast generator.</p>
</div>
<div class="bg-white bg-opacity-10 backdrop-filter backdrop-blur-lg rounded-xl p-6">
<div class="text-purple-300 mb-4 text-3xl">
<i class="fas fa-share-alt"></i>
</div>
<h3 class="text-xl font-semibold mb-2">Easy Sharing</h3>
<p class="opacity-90">Share your QR codes effortlessly with friends, colleagues, or customers.</p>
</div>
<div class="bg-white bg-opacity-10 backdrop-filter backdrop-blur-lg rounded-xl p-6">
<div class="text-purple-300 mb-4 text-3xl">
<i class="fas fa-mobile-alt"></i>
</div>
<h3 class="text-xl font-semibold mb-2">Mobile Friendly</h3>
<p class="opacity-90">Works perfectly on all devices, from smartphones to desktops.</p>
</div>
</div>
</section>
<!-- Footer -->
<footer class="mt-16 text-center text-white text-opacity-70 text-sm">
<p>Made with <i class="fas fa-heart text-red-400"></i> by QRify Team</p>
<p class="mt-1">© 2023 QRify - All rights reserved</p>
</footer>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const urlInput = document.getElementById('urlInput');
const generateBtn = document.getElementById('generateBtn');
const resetBtn = document.getElementById('resetBtn');
const qrSection = document.getElementById('qrSection');
const loadingSection = document.getElementById('loadingSection');
const errorMessage = document.getElementById('errorMessage');
const destinationUrl = document.getElementById('destinationUrl');
const downloadBtn = document.getElementById('downloadBtn');
const shareBtn = document.getElementById('shareBtn');
const copyBtn = document.getElementById('copyBtn');
const qrCodeContainer = document.getElementById('qrCode');
let currentQRCode = null;
let currentUrl = '';
// Generate QR Code
generateBtn.addEventListener('click', generateQRCode);
urlInput.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
generateQRCode();
}
});
function generateQRCode() {
const url = urlInput.value.trim();
// Validate URL
if (!url) {
showError('Please enter a URL');
return;
}
try {
// Add https:// if not present
let formattedUrl = url;
if (!url.startsWith('http://') && !url.startsWith('https://')) {
formattedUrl = 'https://' + url;
}
new URL(formattedUrl); // This will throw if invalid
// Show loading
loadingSection.classList.remove('hidden');
qrSection.classList.add('hidden');
errorMessage.classList.add('hidden');
// Simulate loading (for demo purposes)
setTimeout(() => {
createQRCode(formattedUrl);
loadingSection.classList.add('hidden');
qrSection.classList.remove('hidden');
}, 800);
} catch (e) {
showError('Please enter a valid URL');
}
}
function createQRCode(url) {
currentUrl = url;
destinationUrl.textContent = url;
// Clear previous QR code
qrCodeContainer.innerHTML = '';
// Generate new QR code
const qr = qrcode(0, 'L');
qr.addData(url);
qr.make();
// Create QR code image
const qrImg = qr.createImgTag(4, 0);
qrCodeContainer.innerHTML = qrImg;
currentQRCode = qr;
}
function showError(message) {
errorMessage.textContent = message;
errorMessage.classList.remove('hidden');
}
// Download QR Code
downloadBtn.addEventListener('click', function() {
if (!currentQRCode) return;
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
const size = currentQRCode.getModuleCount() * 4;
canvas.width = size;
canvas.height = size;
// Create QR code pixels
for (let row = 0; row < currentQRCode.getModuleCount(); row++) {
for (let col = 0; col < currentQRCode.getModuleCount(); col++) {
ctx.fillStyle = currentQRCode.isDark(row, col) ? '#000000' : '#ffffff';
ctx.fillRect(col * 4, row * 4, 4, 4);
}
}
// Convert to image and download
canvas.toBlob(function(blob) {
const link = document.createElement('a');
link.download = `qrify-${new Date().getTime()}.png`;
link.href = URL.createObjectURL(blob);
link.click();
}, 'image/png');
});
// Share QR Code
shareBtn.addEventListener('click', function() {
if (!currentQRCode || !navigator.share) {
// Fallback for browsers that don't support Web Share API
alert('Web Share API not supported in your browser. Please download the QR code instead.');
return;
}
navigator.share({
title: 'Check out this QR code',
text: `Scan this QR code to visit ${currentUrl}`,
url: currentUrl
}).catch(err => {
console.log('Error sharing:', err);
});
});
// Copy URL to clipboard
copyBtn.addEventListener('click', function() {
if (!currentUrl) return;
navigator.clipboard.writeText(currentUrl).then(() => {
// Show copied feedback
const originalText = copyBtn.innerHTML;
copyBtn.innerHTML = '<i class="fas fa-check mr-2"></i> Copied!';
setTimeout(() => {
copyBtn.innerHTML = originalText;
}, 2000);
}).catch(err => {
console.error('Could not copy text: ', err);
});
});
// Reset functionality
resetBtn.addEventListener('click', function() {
urlInput.value = '';
qrSection.classList.add('hidden');
errorMessage.classList.add('hidden');
urlInput.focus();
});
// Focus input on page load
urlInput.focus();
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=FaxMe/qr-code-generator" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>