-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathindex.html
258 lines (222 loc) · 10.9 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en" data-theme="dark">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description"
content="Generate QR codes to transfer small files securely without uploading to any server.">
<title>ØR-Code Generator</title>
<link rel="stylesheet" href="style.css">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;600&display=swap" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/framer-motion/dist/framer-motion.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/qrcodejs/qrcode.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/jquery.qrcode.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
</head>
<body>
<nav class="navbar">
<div class="navbar-logo">
<img src="logo-dark.png" alt="Logo" id="logo">
</div>
</nav>
<button class="theme-toggle" id="themeToggle">🌙</button>
<canvas class="canvas-bg" id="bgCanvas"></canvas>
<div class="container">
<header>
<h1>QR Code File Transfer</h1>
<div class="info-text">
<p>
Use this tool to generate a QR code to transfer a small file (< 2kb). The file is encoded into the
QR code itself and <b>is not uploaded to any server</b>.
<br><br>The file's data never leaves your computer. (Though this site's server can technically
see the
file's name)
<br><br>for testing purpose you can download any small file from <a
href="https://drive.google.com/drive/folders/1EBLsp5UrM1KFNgGKQUEALKo6uOVpUlaU?usp=sharing">here</a>
<br><br>To generate one of these QR codes without needing to load this page from the internet,
you can
either:
<ul>
<li>save it to your computer (File -> Save As -> Webpage, Complete)</li>
<li>use the Python script in the <a
href="https://github.com/amanraox/share-bits-wirelessly">GitHub
repository</a></li>
</ul>
</p>
</div>
</header>
<div class="card input-section">
<div class="file-input-wrapper">
<input type="file" id="fileInput" accept="*">
<div class="upload-icon">📁</div>
<p>Drop your file here or click to browse</p>
</div>
<p id="fileNameDisplay" class="file-name-display"></p>
<button id="encodeButton" class="button">Generate QR Code</button>
</div>
<div class="card">
<div id="qrcode"></div>
<button id="downloadButton" class="button" style="display:none;">Download QR Code</button>
</div>
<footer class="card" style="grid-column: 1 / -1; margin-top: 2rem; text-align: center;">
<div class="footer-content">
<p>🚀 Want to contribute? Check out the project on <br>
<a href="https://github.com/amanraox/share-bits-wirelessly" target="_blank"
style="display: inline-flex; align-items: center; gap: 0.5rem;">
<svg height="24" width="24" viewBox="0 0 16 16" style="fill: currentColor;">
<path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"></path>
</svg>
GitHub
</a>
</p>
<p>© 2025 QR Code File Transfer | All rights reserved.</p>
</div>
</footer>
</div>
<script>
// Interactive Background
const canvas = document.getElementById('bgCanvas');
const renderer = new THREE.WebGLRenderer({ canvas, alpha: true });
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const themeToggle = document.getElementById('themeToggle');
const html = document.documentElement;
function toggleTheme() {
const currentTheme = html.getAttribute('data-theme');
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
html.setAttribute('data-theme', newTheme);
themeToggle.textContent = newTheme === 'dark' ? '🌙' : '☀️';
// Change the logo based on theme
const logo = document.getElementById('logo');
logo.src = newTheme === 'dark' ? 'logo-dark.png' : 'logo-light.png';
// Update QR code colors if it exists
const qrCode = document.getElementById('qrcode');
if (qrCode.firstChild) {
const file = document.getElementById('fileInput').files[0];
if (file) {
const reader = new FileReader();
reader.onload = (e) => onFileLoaded(file.name, e.target.result);
reader.readAsDataURL(file);
}
}
}
themeToggle.addEventListener('click', toggleTheme);
// Set canvas size
function resizeCanvas() {
renderer.setSize(window.innerWidth, window.innerHeight);
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
}
window.addEventListener('resize', resizeCanvas);
resizeCanvas();
// Create particles
const particlesGeometry = new THREE.BufferGeometry();
const particlesCount = 1000;
const positions = new Float32Array(particlesCount * 3);
for (let i = 0; i < particlesCount * 3; i++) {
positions[i] = (Math.random() - 0.5) * 10;
}
particlesGeometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
const particlesMaterial = new THREE.PointsMaterial({
size: 0.02,
color: 0x6366f1
});
const particles = new THREE.Points(particlesGeometry, particlesMaterial);
scene.add(particles);
camera.position.z = 5;
// Animation loop
function animate() {
requestAnimationFrame(animate);
particles.rotation.x += 0.0005;
particles.rotation.y += 0.0005;
renderer.render(scene, camera);
}
animate();
// File handling and QR generation
const WEB_URL_PREFIX = "https://amanraox.github.io/share-bits-wirelessly/dl.html";
document.getElementById('encodeButton').addEventListener('click', function () {
const fileInput = document.getElementById('fileInput');
const file = fileInput.files[0];
if (file) {
const reader = new FileReader();
reader.onload = (e) => onFileLoaded(file.name, e.target.result);
reader.readAsDataURL(file);
} else {
alert("Please select a file first.");
}
});
function onFileLoaded(filename, dataUrl) {
if (dataUrl.length + filename.length > 2000) {
alert(`File ${filename} is too large for QR code!`);
return;
}
const b64 = encodeURIComponent(dataUrl.split(',')[1]);
const url = `${WEB_URL_PREFIX}?f=${filename}#${b64}`;
document.getElementById('qrcode').innerHTML = '';
const isDarkTheme = html.getAttribute('data-theme') === 'dark';
new QRCode(document.getElementById('qrcode'), {
text: url,
width: 256,
height: 256,
colorDark: isDarkTheme ? "#ffffff" : "#000000",
colorLight: isDarkTheme ? "#000000" : "#ffffff",
});
const downloadButton = document.getElementById('downloadButton');
downloadButton.style.display = 'inline-block';
// Download functionality
downloadButton.addEventListener('click', function () {
const qrCanvas = document.querySelector('#qrcode canvas'); // Getting the canvas element
if (qrCanvas) {
const link = document.createElement('a');
link.href = qrCanvas.toDataURL();
link.download = `${filename}-qrcode.png`;
link.click();
} else {
alert("QR Code is not generated yet.");
}
});
}
// Drag and drop handling
const dropZone = document.querySelector('.file-input-wrapper');
['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, highlight, false);
});
['dragleave', 'drop'].forEach(eventName => {
dropZone.addEventListener(eventName, unhighlight, false);
});
function highlight(e) {
dropZone.style.border = '2px dashed #a855f7';
}
function unhighlight(e) {
dropZone.style.border = '2px dashed var(--primary-color)';
}
dropZone.addEventListener('drop', handleDrop, false);
const fileNameDisplay = document.getElementById('fileNameDisplay');
fileInput.addEventListener('change', updateFileNameDisplay);
function updateFileNameDisplay() {
const file = fileInput.files[0];
if (file) {
fileNameDisplay.textContent = `Uploaded: ${file.name}`;
} else {
fileNameDisplay.textContent = ''; // Clear if no file is selected
}
}
function handleDrop(e) {
const dt = e.dataTransfer;
const file = dt.files[0];
document.getElementById('fileInput').files = dt.files;
// adding
updateFileNameDisplay()
}
</script>
</body>
</html>