187 lines
4.8 KiB
HTML
187 lines
4.8 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>QR Code</title>
|
|
<style>
|
|
body {
|
|
background: black;
|
|
color: lime;
|
|
font-family: sans-serif;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
flex-direction: column;
|
|
height: 100vh;
|
|
margin: 0;
|
|
}
|
|
.container {
|
|
text-align: center;
|
|
font-size: 4rem;
|
|
}
|
|
#input {
|
|
text-align: center;
|
|
min-width: 90vw;
|
|
min-height: 5rem;
|
|
font-size: 2rem;
|
|
padding: 1rem;
|
|
margin-bottom: 1rem;
|
|
color: lime;
|
|
background: transparent;
|
|
word-break: break-word;
|
|
border: none;
|
|
}
|
|
#qrcode {
|
|
width: min(90vw, 90vh);
|
|
height: min(90vw, 90vh);
|
|
margin-top: 1rem;
|
|
margin: auto;
|
|
}
|
|
.modal-overlay {
|
|
position: fixed;
|
|
top: 0; left: 0;
|
|
width: 100vw;
|
|
height: 100vh;
|
|
background: rgba(0, 0, 0, 0.75);
|
|
display: none;
|
|
justify-content: center;
|
|
align-items: center;
|
|
z-index: 1000;
|
|
}
|
|
.modal {
|
|
background: black;
|
|
border: 2px solid lime;
|
|
border-radius: 0.5rem;
|
|
padding: 2rem;
|
|
color: lime;
|
|
font-size: 1.5rem;
|
|
max-width: 90%;
|
|
}
|
|
.modal h2 {
|
|
color: #00ff00;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div id="qrcode"></div>
|
|
<textarea id="input" placeholder="Paste or type your text here..."></textarea>
|
|
</div>
|
|
|
|
<div id="modal-overlay" class="modal-overlay">
|
|
<div class="modal">
|
|
<h2>Help</h2>
|
|
<p>Type or paste your text and press <code>g</code> to generate a QR code.</p>
|
|
<ul>
|
|
<li><kbd>Ctrl</kbd> + <kbd>v</kbd> = Paste</li>
|
|
<li><kbd>Ctrl</kbd> + <kbd>c</kbd> = Copy</li>
|
|
<li><kbd>g</kbd> = Generate</li>
|
|
<li><kbd>?</kbd> = Help</li>
|
|
<li><kbd>Esc</kbd> = Exit input or close modal</li>
|
|
</ul>
|
|
<p>
|
|
Using query parameters:
|
|
</p>
|
|
<ul>
|
|
<li><code>https://qrcode.wayl.one?text=https://qrcode.wayl.one</code> - Text to generate QR code for</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/qrcode/build/qrcode.min.js"></script>
|
|
<script>
|
|
const inputEl = document.getElementById('input');
|
|
const qrContainer = document.getElementById('qrcode');
|
|
const overlay = document.getElementById('modal-overlay');
|
|
const params = new URLSearchParams(window.location.search);
|
|
|
|
if (params.has('text')) {
|
|
inputEl.value = params.get('text');
|
|
generateQR(inputEl.value);
|
|
}
|
|
|
|
if (params.has('color')) {
|
|
inputEl.style.color = `#${params.get('color')}`;
|
|
}
|
|
|
|
if (params.has('bg')) {
|
|
document.body.style.background = `#${params.get('bg')}`;
|
|
}
|
|
|
|
function toggleModal() {
|
|
overlay.style.display = overlay.style.display === 'flex' ? 'none' : 'flex';
|
|
}
|
|
|
|
function hideModal() {
|
|
overlay.style.display = 'none';
|
|
}
|
|
|
|
function generateQR(text) {
|
|
if (params.has('color')) {
|
|
color = `#${params.get('color')}`;
|
|
} else {
|
|
color = '#00FF00';
|
|
}
|
|
if (params.has('bg')) {
|
|
bg = `#${params.get('bg')}`;
|
|
} else {
|
|
bg = '#000000';
|
|
}
|
|
console.log(color, bg);
|
|
qrContainer.innerHTML = '';
|
|
if (text === '') return;
|
|
QRCode.toCanvas(text, {
|
|
width: Math.floor(Math.min(window.innerWidth, window.innerHeight) * 0.9),
|
|
color: { dark: color, light: bg }
|
|
}, (err, canvas) => {
|
|
if (err) return console.error(err);
|
|
qrContainer.appendChild(canvas);
|
|
});
|
|
}
|
|
|
|
async function getClipboardContents() {
|
|
try {
|
|
return await navigator.clipboard.readText();
|
|
} catch (err) {
|
|
console.error('Clipboard error:', err);
|
|
}
|
|
}
|
|
|
|
document.addEventListener('keydown', async (e) => {
|
|
if (overlay.style.display === 'flex' && e.key === 'Escape') return hideModal();
|
|
if (e.key === '?') return toggleModal();
|
|
|
|
if (e.ctrlKey && e.key === 'c') {
|
|
navigator.clipboard.writeText(inputEl.value);
|
|
} else if (e.ctrlKey && e.key === 'v') {
|
|
const contents = await getClipboardContents();
|
|
inputEl.value = contents;
|
|
} else if (e.key === 'Escape') {
|
|
inputEl.blur();
|
|
} else {
|
|
inputEl.focus();
|
|
}
|
|
});
|
|
|
|
document.addEventListener('keyup', async (e) => {
|
|
generateQR(inputEl.value);
|
|
const url = new URL(window.location.href);
|
|
url.searchParams.set('text', inputEl.value);
|
|
window.history.replaceState({}, '', url);
|
|
});
|
|
|
|
// generate on resize
|
|
window.addEventListener('resize', () => {
|
|
generateQR(inputEl.value);
|
|
});
|
|
|
|
|
|
|
|
overlay.addEventListener('click', e => {
|
|
if (e.target === overlay) hideModal();
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|
|
|