-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
411 lines (367 loc) · 16.8 KB
/
Copy pathindex.html
File metadata and controls
411 lines (367 loc) · 16.8 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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>QR Code Scanner - Extract Links & Data</title>
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
<script src="https://cdn.jsdelivr.net/npm/jsqr@1.4.0/dist/jsQR.min.js"></script>
<style>
.gradient-bg {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.drop-zone {
border: 3px dashed #a78bfa;
transition: all 0.3s ease;
}
.drop-zone:hover, .drop-zone.dragover {
border-color: #7c3aed;
background-color: rgba(167, 139, 250, 0.1);
transform: scale(1.02);
}
.pulse-animation {
animation: pulse 2s infinite;
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
</style>
</head>
<body class="min-h-screen gradient-bg">
<div class="container mx-auto px-4 py-12">
<!-- Header -->
<div class="text-center mb-12">
<h1 class="text-4xl md:text-5xl font-bold text-white mb-4">
📱 QR Code Scanner
</h1>
<p class="text-purple-200 text-lg">
Upload your QR code image to extract links and data instantly
</p>
</div>
<!-- Main Card -->
<div class="max-w-2xl mx-auto bg-white rounded-3xl shadow-2xl overflow-hidden">
<!-- Upload Section -->
<div class="p-8">
<div
id="dropZone"
class="drop-zone rounded-2xl p-12 text-center cursor-pointer bg-purple-50"
onclick="document.getElementById('fileInput').click()"
>
<div id="uploadContent">
<div class="text-6xl mb-4">📤</div>
<h3 class="text-xl font-semibold text-gray-700 mb-2">
Drop your QR code here
</h3>
<p class="text-gray-500 mb-4">
or click to browse files
</p>
<p class="text-sm text-gray-400">
Supports PNG, JPG, JPEG, GIF, WebP
</p>
</div>
<div id="loadingContent" class="hidden">
<div class="text-6xl mb-4 pulse-animation">🔍</div>
<p class="text-gray-600">Scanning QR code...</p>
</div>
</div>
<input
type="file"
id="fileInput"
accept="image/*"
class="hidden"
onchange="handleFileSelect(event)"
>
</div>
<!-- Preview Section -->
<div id="previewSection" class="hidden px-8 pb-4">
<div class="flex items-center justify-center">
<div class="relative">
<img
id="previewImage"
class="max-h-48 rounded-xl shadow-lg border-4 border-purple-200"
alt="QR Code Preview"
>
<button
onclick="clearAll()"
class="absolute -top-3 -right-3 bg-red-500 text-white rounded-full w-8 h-8 flex items-center justify-center hover:bg-red-600 transition-colors shadow-lg"
>
✕
</button>
</div>
</div>
</div>
<!-- Results Section -->
<div id="resultsSection" class="hidden">
<div class="bg-gradient-to-r from-green-50 to-emerald-50 p-8 border-t border-green-100">
<div class="flex items-center mb-4">
<span class="text-3xl mr-3">✅</span>
<h3 class="text-xl font-bold text-green-800">QR Code Decoded!</h3>
</div>
<!-- Data Type Badge -->
<div class="mb-4">
<span id="dataTypeBadge" class="inline-block px-4 py-1 rounded-full text-sm font-semibold bg-purple-100 text-purple-700">
Text
</span>
</div>
<!-- Extracted Data -->
<div class="bg-white rounded-xl p-4 shadow-inner mb-4">
<label class="block text-sm font-medium text-gray-500 mb-2">Extracted Data:</label>
<div id="extractedData" class="text-gray-800 break-all font-mono text-sm bg-gray-50 p-3 rounded-lg">
</div>
</div>
<!-- Link Section (if URL detected) -->
<div id="linkSection" class="hidden bg-white rounded-xl p-4 shadow-inner mb-4">
<label class="block text-sm font-medium text-gray-500 mb-2">🔗 Detected Link:</label>
<a
id="extractedLink"
href="#"
target="_blank"
class="text-purple-600 hover:text-purple-800 underline break-all font-medium"
></a>
</div>
<!-- Action Buttons -->
<div class="flex flex-wrap gap-3 mt-6">
<button
onclick="copyToClipboard()"
class="flex-1 min-w-[140px] bg-purple-600 hover:bg-purple-700 text-white font-semibold py-3 px-6 rounded-xl transition-colors flex items-center justify-center gap-2"
>
<span>📋</span> Copy Data
</button>
<button
id="openLinkBtn"
onclick="openLink()"
class="hidden flex-1 min-w-[140px] bg-green-600 hover:bg-green-700 text-white font-semibold py-3 px-6 rounded-xl transition-colors flex items-center justify-center gap-2"
>
<span>🌐</span> Open Link
</button>
<button
onclick="clearAll()"
class="flex-1 min-w-[140px] bg-gray-200 hover:bg-gray-300 text-gray-700 font-semibold py-3 px-6 rounded-xl transition-colors flex items-center justify-center gap-2"
>
<span>🔄</span> Scan Another
</button>
</div>
</div>
</div>
<!-- Error Section -->
<div id="errorSection" class="hidden">
<div class="bg-gradient-to-r from-red-50 to-orange-50 p-8 border-t border-red-100">
<div class="flex items-center mb-4">
<span class="text-3xl mr-3">❌</span>
<h3 class="text-xl font-bold text-red-800">Couldn't Read QR Code</h3>
</div>
<p id="errorMessage" class="text-red-600 mb-4">
Please make sure the image contains a valid QR code and try again.
</p>
<button
onclick="clearAll()"
class="bg-red-500 hover:bg-red-600 text-white font-semibold py-3 px-6 rounded-xl transition-colors"
>
Try Again
</button>
</div>
</div>
</div>
<!-- Features -->
<div class="max-w-4xl mx-auto mt-12 grid md:grid-cols-3 gap-6">
<div class="bg-white/20 backdrop-blur-sm rounded-2xl p-6 text-center">
<div class="text-4xl mb-3">⚡</div>
<h3 class="text-white font-semibold mb-2">Instant Scanning</h3>
<p class="text-purple-200 text-sm">Get results in milliseconds</p>
</div>
<div class="bg-white/20 backdrop-blur-sm rounded-2xl p-6 text-center">
<div class="text-4xl mb-3">🔒</div>
<h3 class="text-white font-semibold mb-2">100% Private</h3>
<p class="text-purple-200 text-sm">All processing happens locally</p>
</div>
<div class="bg-white/20 backdrop-blur-sm rounded-2xl p-6 text-center">
<div class="text-4xl mb-3">🆓</div>
<h3 class="text-white font-semibold mb-2">Completely Free</h3>
<p class="text-purple-200 text-sm">No limits, no sign-up required</p>
</div>
</div>
<!-- Footer -->
<div class="text-center mt-12 text-purple-200 text-sm">
<p>Made with ❤️ | Your QR codes are processed locally and never uploaded to any server</p>
</div>
</div>
<!-- Toast Notification -->
<div id="toast" class="fixed bottom-6 right-6 bg-gray-800 text-white px-6 py-3 rounded-xl shadow-2xl transform translate-y-20 opacity-0 transition-all duration-300">
<span id="toastMessage">Copied to clipboard!</span>
</div>
<canvas id="canvas" class="hidden"></canvas>
<script>
let extractedDataValue = '';
let isLink = false;
// Drag and drop handlers
const dropZone = document.getElementById('dropZone');
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
dropZone.addEventListener(eventName, preventDefaults, false);
});
function preventDefaults(e) {
e.preventDefault();
e.stopPropagation();
}
['dragenter', 'dragover'].forEach(eventName => {
dropZone.addEventListener(eventName, () => {
dropZone.classList.add('dragover');
});
});
['dragleave', 'drop'].forEach(eventName => {
dropZone.addEventListener(eventName, () => {
dropZone.classList.remove('dragover');
});
});
dropZone.addEventListener('drop', (e) => {
const files = e.dataTransfer.files;
if (files.length > 0) {
handleFile(files[0]);
}
});
function handleFileSelect(event) {
const file = event.target.files[0];
if (file) {
handleFile(file);
}
}
function handleFile(file) {
if (!file.type.startsWith('image/')) {
showError('Please upload an image file.');
return;
}
showLoading(true);
hideResults();
const reader = new FileReader();
reader.onload = function(e) {
const img = new Image();
img.onload = function() {
// Show preview
document.getElementById('previewImage').src = e.target.result;
document.getElementById('previewSection').classList.remove('hidden');
// Decode QR code
decodeQR(img);
};
img.onerror = function() {
showLoading(false);
showError('Failed to load the image. Please try another file.');
};
img.src = e.target.result;
};
reader.readAsDataURL(file);
}
function decodeQR(img) {
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
canvas.width = img.width;
canvas.height = img.height;
ctx.drawImage(img, 0, 0);
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
const code = jsQR(imageData.data, imageData.width, imageData.height, {
inversionAttempts: "dontInvert",
});
showLoading(false);
if (code) {
displayResults(code.data);
} else {
// Try with inverted colors
const invertedCode = jsQR(imageData.data, imageData.width, imageData.height, {
inversionAttempts: "attemptBoth",
});
if (invertedCode) {
displayResults(invertedCode.data);
} else {
showError('No QR code found in the image. Please make sure the QR code is clear and visible.');
}
}
}
function displayResults(data) {
extractedDataValue = data;
// Check if it's a URL
const urlPattern = /^(https?:\/\/|www\.)[^\s]+/i;
isLink = urlPattern.test(data);
// Determine data type
let dataType = 'Text';
if (isLink) {
dataType = 'URL / Link';
} else if (data.startsWith('mailto:')) {
dataType = 'Email';
} else if (data.startsWith('tel:')) {
dataType = 'Phone Number';
} else if (data.startsWith('WIFI:')) {
dataType = 'WiFi Network';
} else if (data.startsWith('BEGIN:VCARD')) {
dataType = 'Contact Card';
} else if (data.startsWith('geo:')) {
dataType = 'Location';
}
document.getElementById('dataTypeBadge').textContent = dataType;
document.getElementById('extractedData').textContent = data;
if (isLink) {
const link = data.startsWith('http') ? data : 'https://' + data;
document.getElementById('extractedLink').href = link;
document.getElementById('extractedLink').textContent = data;
document.getElementById('linkSection').classList.remove('hidden');
document.getElementById('openLinkBtn').classList.remove('hidden');
document.getElementById('openLinkBtn').classList.add('flex');
} else {
document.getElementById('linkSection').classList.add('hidden');
document.getElementById('openLinkBtn').classList.add('hidden');
}
document.getElementById('resultsSection').classList.remove('hidden');
document.getElementById('errorSection').classList.add('hidden');
}
function showError(message) {
document.getElementById('errorMessage').textContent = message;
document.getElementById('errorSection').classList.remove('hidden');
document.getElementById('resultsSection').classList.add('hidden');
}
function hideResults() {
document.getElementById('resultsSection').classList.add('hidden');
document.getElementById('errorSection').classList.add('hidden');
}
function showLoading(show) {
document.getElementById('uploadContent').classList.toggle('hidden', show);
document.getElementById('loadingContent').classList.toggle('hidden', !show);
}
function clearAll() {
document.getElementById('fileInput').value = '';
document.getElementById('previewSection').classList.add('hidden');
hideResults();
showLoading(false);
extractedDataValue = '';
isLink = false;
}
function copyToClipboard() {
navigator.clipboard.writeText(extractedDataValue).then(() => {
showToast('Copied to clipboard! 📋');
}).catch(() => {
// Fallback
const textarea = document.createElement('textarea');
textarea.value = extractedDataValue;
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
showToast('Copied to clipboard! 📋');
});
}
function openLink() {
if (isLink) {
const link = extractedDataValue.startsWith('http') ? extractedDataValue : 'https://' + extractedDataValue;
window.open(link, '_blank');
}
}
function showToast(message) {
const toast = document.getElementById('toast');
document.getElementById('toastMessage').textContent = message;
toast.classList.remove('translate-y-20', 'opacity-0');
toast.classList.add('translate-y-0', 'opacity-100');
setTimeout(() => {
toast.classList.add('translate-y-20', 'opacity-0');
toast.classList.remove('translate-y-0', 'opacity-100');
}, 2500);
}
</script>
</body>
</html>