Spaces:
Running
Running
Download index.html from ReyDiablo/anycoder-cbdee29e: direct link, hf CLI and curl.
- Browser
- Download file 30.4 kB
-
https://huggingface.co/spaces/ReyDiablo/anycoder-cbdee29e/resolve/main/index.html
- Command line
-
hf download hf://spaces/ReyDiablo/anycoder-cbdee29e/index.html
-
curl -L -o index.html https://huggingface.co/spaces/ReyDiablo/anycoder-cbdee29e/resolve/main/index.html
30.4 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>NFC Data Transfer Hub - Mobile Ready</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--primary: #6366f1;
--primary-dark: #4f46e5;
--secondary: #22d3ee;
--success: #10b981;
--warning: #f59e0b;
--danger: #ef4444;
--dark: #1e293b;
--light: #f1f5f9;
--white: #ffffff;
--shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
--shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.15);
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
color: var(--dark);
position: relative;
overflow-x: hidden;
-webkit-tap-highlight-color: transparent;
}
.animated-bg {
position: fixed;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: -1;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.animated-bg::before {
content: '';
position: absolute;
width: 200%;
height: 200%;
top: -50%;
left: -50%;
background: radial-gradient(circle, rgba(255, 255, 255, 0.1) 1px, transparent 1px);
background-size: 50px 50px;
animation: bgMove 20s linear infinite;
}
@keyframes bgMove {
0% { transform: translate(0, 0); }
100% { transform: translate(50px, 50px); }
}
header {
background: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(10px);
padding: 1rem;
box-shadow: var(--shadow);
position: sticky;
top: 0;
z-index: 100;
}
.header-content {
max-width: 1400px;
margin: 0 auto;
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
gap: 1rem;
}
.logo {
display: flex;
align-items: center;
gap: 0.75rem;
}
.logo-icon {
width: 40px;
height: 40px;
background: linear-gradient(135deg, var(--primary), var(--secondary));
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
color: white;
font-weight: bold;
font-size: 1.2rem;
}
.logo h1 {
font-size: 1.3rem;
background: linear-gradient(135deg, var(--primary), var(--secondary));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.status-indicator {
display: flex;
align-items: center;
gap: 0.5rem;
padding: 0.5rem 1rem;
background: var(--light);
border-radius: 20px;
font-size: 0.85rem;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--success);
animation: pulse 2s infinite;
}
.status-dot.error {
background: var(--danger);
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
main {
max-width: 1400px;
margin: 1rem auto;
padding: 0 1rem;
}
.nfc-mode-toggle {
background: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(10px);
border-radius: 15px;
padding: 1rem;
margin-bottom: 1rem;
box-shadow: var(--shadow);
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: 1rem;
}
.toggle-switch {
display: flex;
align-items: center;
gap: 0.75rem;
}
.switch {
position: relative;
width: 60px;
height: 30px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
transition: .4s;
border-radius: 34px;
}
.slider:before {
position: absolute;
content: "";
height: 22px;
width: 22px;
left: 4px;
bottom: 4px;
background-color: white;
transition: .4s;
border-radius: 50%;
}
input:checked + .slider {
background-color: var(--primary);
}
input:checked + .slider:before {
transform: translateX(30px);
}
.app-container {
display: grid;
grid-template-columns: 1fr;
gap: 1rem;
margin-bottom: 1rem;
}
.panel {
background: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(10px);
border-radius: 20px;
padding: 1.5rem;
box-shadow: var(--shadow-lg);
transition: transform 0.3s, box-shadow 0.3s;
}
.panel:hover {
transform: translateY(-2px);
box-shadow: 0 25px 60px rgba(0, 0, 0, 0.2);
}
.panel-header {
display: flex;
align-items: center;
gap: 1rem;
margin-bottom: 1.5rem;
padding-bottom: 1rem;
border-bottom: 2px solid var(--light);
}
.panel-icon {
width: 40px;
height: 40px;
background: linear-gradient(135deg, var(--primary), var(--secondary));
border-radius: 10px;
display: flex;
align-items: center;
justify-content: center;
color: white;
}
.panel h2 {
font-size: 1.2rem;
color: var(--dark);
}
.nfc-simulator {
display: flex;
flex-direction: column;
align-items: center;
gap: 1.5rem;
}
.nfc-device {
width: 150px;
height: 150px;
background: linear-gradient(135deg, var(--primary), var(--primary-dark));
border-radius: 20px;
display: flex;
align-items: center;
justify-content: center;
position: relative;
cursor: pointer;
transition: all 0.3s;
box-shadow: 0 10px 30px rgba(99, 102, 241, 0.3);
}
.nfc-device:hover {
transform: scale(1.05);
box-shadow: 0 15px 40px rgba(99, 102, 241, 0.4);
}
.nfc-device.active {
animation: nfcPulse 1s infinite;
}
@keyframes nfcPulse {
0%, 100% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.7); }
50% { box-shadow: 0 0 0 20px rgba(99, 102, 241, 0); }
}
.nfc-symbol {
font-size: 3rem;
color: white;
}
.data-types {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 0.75rem;
width: 100%;
}
.data-type-btn {
padding: 0.75rem;
background: var(--light);
border: 2px solid transparent;
border-radius: 12px;
cursor: pointer;
transition: all 0.3s;
text-align: center;
}
.data-type-btn:hover {
background: white;
border-color: var(--primary);
transform: translateY(-2px);
}
.data-type-btn.active {
background: var(--primary);
color: white;
}
.data-type-icon {
font-size: 1.5rem;
margin-bottom: 0.25rem;
}
.data-type-text {
font-size: 0.85rem;
font-weight: 500;
}
.data-input-section {
margin-top: 1.5rem;
}
.input-group {
margin-bottom: 1rem;
}
.input-group label {
display: block;
margin-bottom: 0.5rem;
font-weight: 500;
color: var(--dark);
font-size: 0.9rem;
}
.input-group input,
.input-group textarea,
.input-group select {
width: 100%;
padding: 0.75rem;
border: 2px solid var(--light);
border-radius: 10px;
font-size: 1rem;
transition: all 0.3s;
-webkit-appearance: none;
}
.input-group input:focus,
.input-group textarea:focus,
.input-group select:focus {
outline: none;
border-color: var(--primary);
box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}
.input-group textarea {
resize: vertical;
min-height: 80px;
}
.btn {
padding: 0.75rem 1.5rem;
background: linear-gradient(135deg, var(--primary), var(--primary-dark));
color: white;
border: none;
border-radius: 10px;
font-size: 1rem;
font-weight: 500;
cursor: pointer;
transition: all 0.3s;
display: inline-flex;
align-items: center;
gap: 0.5rem;
width: 100%;
justify-content: center;
}
.btn:hover {
transform: translateY(-2px);
box-shadow: 0 10px 20px rgba(99, 102, 241, 0.3);
}
.btn:active {
transform: translateY(0);
}
.btn:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.btn-secondary {
background: var(--light);
color: var(--dark);
}
.btn-success {
background: linear-gradient(135deg, var(--success), #059669);
}
.btn-danger {
background: linear-gradient(135deg, var(--danger), #dc2626);
}
.action-buttons {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 0.75rem;
margin-top: 1.5rem;
}
.history-section {
background: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(10px);
border-radius: 20px;
padding: 1.5rem;
box-shadow: var(--shadow-lg);
}
.history-list {
display: flex;
flex-direction: column;
gap: 0.75rem;
max-height: 300px;
overflow-y: auto;
}
.history-item {
padding: 1rem;
background: var(--light);
border-radius: 12px;
display: flex;
justify-content: space-between;
align-items: center;
transition: all 0.3s;
}
.history-item:hover {
background: white;
transform: translateX(5px);
}
.history-info {
flex: 1;
min-width: 0;
}
.history-type {
font-weight: 600;
color: var(--primary);
margin-bottom: 0.25rem;
font-size: 0.9rem;
}
.history-time {
font-size: 0.75rem;
color: #64748b;
}
.history-actions {
display: flex;
gap: 0.25rem;
}
.icon-btn {
width: 32px;
height: 32px;
border-radius: 8px;
border: none;
background: white;
color: var(--primary);
cursor: pointer;
transition: all 0.3s;
display: flex;
align-items: center;
justify-content: center;
font-size: 0.9rem;
}
.icon-btn:hover {
background: var(--primary);
color: white;
}
.toast {
position: fixed;
bottom: 2rem;
right: 1rem;
left: 1rem;
padding: 1rem;
background: white;
border-radius: 12px;
box-shadow: var(--shadow-lg);
display: flex;
align-items: center;
gap: 1rem;
transform: translateY(100px);
transition: transform 0.3s;
z-index: 1000;
max-width: 400px;
margin: 0 auto;
}
.toast.show {
transform: translateY(0);
}
.toast-icon {
width: 30px;
height: 30px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.toast.success .toast-icon {
background: var(--success);
color: white;
}
.toast.error .toast-icon {
background: var(--danger);
color: white;
}
.toast.info .toast-icon {
background: var(--primary);
color: white;
}
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
backdrop-filter: blur(5px);
align-items: center;
justify-content: center;
z-index: 200;
padding: 1rem;
}
.modal.active {
display: flex;
}
.modal-content {
background: white;
border-radius: 20px;
padding: 1.5rem;
max-width: 500px;
width: 100%;
max-height: 80vh;
overflow-y: auto;
animation: modalSlideIn 0.3s;
}
@keyframes modalSlideIn {
from { transform: translateY(-50px); opacity: 0; }
to { transform: translateY(0); opacity: 1; }
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1.5rem;
}
.modal-close {
width: 30px;
height: 30px;
border-radius: 50%;
border: none;
background: var(--light);
cursor: pointer;
transition: all 0.3s;
}
.modal-close:hover {
background: var(--danger);
color: white;
}
.progress-bar {
width: 100%;
height: 6px;
background: var(--light);
border-radius: 3px;
overflow: hidden;
margin-top: 1rem;
}
.progress-fill {
height: 100%;
background: linear-gradient(90deg, var(--primary), var(--secondary));
border-radius: 3px;
width: 0;
transition: width 0.3s;
}
.format-options {
display: flex;
gap: 0.5rem;
margin-top: 1rem;
flex-wrap: wrap;
}
.format-chip {
padding: 0.5rem 0.75rem;
background: var(--light);
border: 2px solid transparent;
border-radius: 20px;
cursor: pointer;
transition: all 0.3s;
font-size: 0.85rem;
}
.format-chip:hover {
border-color: var(--primary);
}
.format-chip.active {
background: var(--primary);
color: white;
}
.scan-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.8);
display: none;
align-items: center;
justify-content: center;
z-index: 300;
}
.scan-overlay.active {
display: flex;
}
.scan-content {
text-align: center;
color: white;
}
.scan-animation {
width: 200px;
height: 200px;
border: 3px solid var(--primary);
border-radius: 20px;
margin: 0 auto 2rem;
position: relative;
animation: scanPulse 1.5s infinite;
}
@keyframes scanPulse {
0%, 100% { transform: scale(1); opacity: 1; }
50% { transform: scale(1.1); opacity: 0.8; }
}
.scan-animation::before {
content: '📱';
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 3rem;
}
@media (min-width: 768px) {
.app-container {
grid-template-columns: 1fr 1fr;
}
.data-types {
grid-template-columns: repeat(4, 1fr);
}
.action-buttons {
grid-template-columns: 1fr 1fr;
}
main {
padding: 0 2rem;
}
}
@media (min-width: 1024px) {
.toast {
left: auto;
right: 2rem;
}
}
</style>
</head>
<body>
<div class="animated-bg"></div>
<header>
<div class="header-content">
<div class="logo">
<div class="logo-icon">N</div>
<h1>NFC Hub</h1>
</div>
<div class="status-indicator" id="statusIndicator">
<span class="status-dot" id="statusDot"></span>
<span id="statusText">Checking NFC...</span>
</div>
<a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank"
style="color: var(--primary); text-decoration: none; font-weight: 500; font-size: 0.85rem;">
Built with anycoder
</a>
</div>
</header>
<main>
<div class="nfc-mode-toggle">
<div>
<strong>NFC Mode:</strong>
<span id="modeText">Real NFC</span>
</div>
<div class="toggle-switch">
<span>Simulator</span>
<label class="switch">
<input type="checkbox" id="modeToggle">
<span class="slider"></span>
</label>
<span>Real NFC</span>
</div>
</div>
<div class="app-container">
<!-- NFC Device Panel -->
<div class="panel">
<div class="panel-header">
<div class="panel-icon" id="deviceIcon">📡</div>
<h2 id="deviceTitle">NFC Device</h2>
</div>
<div class="nfc-simulator">
<div class="nfc-device" id="nfcDevice">
<div class="nfc-symbol">📱</div>
</div>
<div class="data-types">
<div class="data-type-btn active" data-type="text">
<div class="data-type-icon">📝</div>
<div class="data-type-text">Text</div>
</div>
<div class="data-type-btn" data-type="url">
<div class="data-type-icon">🔗</div>
<div class="data-type-text">URL</div>
</div>
<div class="data-type-btn" data-type="contact">
<div class="data-type-icon">👤</div>
<div class="data-type-text">Contact</div>
</div>
<div class="data-type-btn" data-type="wifi">
<div class="data-type-icon">📶</div>
<div class="data-type-text">WiFi</div>
</div>
</div>
<button class="btn btn-success" id="scanBtn" style="display: none;">
<span>🔍</span>
<span>Scan NFC Tag</span>
</button>
</div>
</div>
<!-- Data Input Panel -->
<div class="panel">
<div class="panel-header">
<div class="panel-icon">💾</div>
<h2>Data Input</h2>
</div>
<div class="data-input-section" id="dataInputSection">
<div class="input-group">
<label for="textInput">Text Message</label>
<textarea id="textInput" placeholder="Enter your text message here..." rows="3"></textarea>
</div>
<div class="format-options">
<div class="format-chip active" data-format="plain">Plain</div>
<div class="format-chip" data-format="json">JSON</div>
<div class="format-chip" data-format="base64">Base64</div>
<div class="format-chip" data-format="hex">Hex</div>
</div>
</div>
<div class="action-buttons">
<button class="btn btn-success" id="writeBtn">
<span>✍️</span>
<span>Write to NFC</span>
</button>
<button class="btn btn-secondary" id="clearBtn">
<span>🗑️</span>
<span>Clear</span>
</button>
</div>
<div class="progress-bar">
<div class="progress-fill" id="progressBar"></div>
</div>
</div>
</div>
<!-- History Section -->
<div class="history-section">
<div class="panel-header">
<div class="panel-icon">📋</div>
<h2>Transfer History</h2>
</div>
<div class="history-list" id="historyList">
<div class="history-item">
<div class="history-info">
<div class="history-type">📝 Welcome Message</div>
<div class="history-time">Just now</div>
</div>
<div class="history-actions">
<button class="icon-btn">👁️</button>
<button class="icon-btn">📋</button>
<button class="icon-btn">🔄</button>
</div>
</div>
</div>
</div>
</main>
<!-- Scan Overlay -->
<div class="scan-overlay" id="scanOverlay">
<div class="scan-content">
<div class="scan-animation"></div>
<h2>Hold your device near an NFC tag</h2>
<p id="scanStatus">Waiting for tag...</p>
<button class="btn btn-danger" id="cancelScan" style="margin-top: 2rem;">
Cancel Scan
</button>
</div>
</div>
<!-- Modal for viewing data -->
<div class="modal" id="viewModal">
<div class="modal-content">
<div class="modal-header">
<h2>View Data</h2>
<button class="modal-close" id="closeModal">✕</button>
</div>
<div id="modalBody"></div>
</div>
</div>
<!-- Toast Notification -->
<div class="toast" id="toast">
<div class="toast-icon">✓</div>
<div class="toast-message" id="toastMessage">Operation successful!</div>
</div>
<script>
// Global state
let currentDataType = 'text';
let currentFormat = 'plain';
let transferHistory = [];
let isTransferring = false;
let useRealNFC = false;
let nfcSupported = false;
let nfcPermission = false;
// DOM elements
const nfcDevice = document.getElementById('nfcDevice');
const dataInputSection = document.getElementById('dataInputSection');
const writeBtn = document.getElementById('writeBtn');
const scanBtn = document.getElementById('scanBtn');
const clearBtn = document.getElementById('clearBtn');
const progressBar = document.getElementById('progressBar');
const historyList = document.getElementById('historyList');
const toast = document.getElementById('toast');
const toastMessage = document.getElementById('toastMessage');
const viewModal = document.getElementById('viewModal');
const modalBody = document.getElementById('modalBody');
const closeModal = document.getElementById('closeModal');
const modeToggle = document.getElementById('modeToggle');
const modeText = document.getElementById('modeText');
const deviceTitle = document.getElementById('deviceTitle');
const deviceIcon = document.getElementById('deviceIcon');
const statusText = document.getElementById('statusText');
const statusDot = document.getElementById('statusDot');
const scanOverlay = document.getElementById('scanOverlay');
const cancelScan = document.getElementById('cancelScan');
const scanStatus = document.getElementById('scanStatus');
// Data type templates
const dataTemplates = {
text: `
<div class="input-group">
<label for="textInput">Text Message</label>
<textarea id="textInput" placeholder="Enter your text message here..." rows="3"></textarea>
</div>
`,
url: `
<div class="input-group">
<label for="urlInput">URL</label>
<input type="url" id="urlInput" placeholder="https://example.com">
</div>
<div class="input-group">
<label for="urlTitle">Title (Optional)</label>
<input type="text" id="urlTitle" placeholder="Website Title">
</div>
`,
contact: `
<div class="input-group">
<label for="contactName">Name</label>
<input type="text" id="contactName" placeholder="John Doe">
</div>
<div class="input-group">
<label for="contactPhone">Phone</label>
<input type="tel" id="contactPhone" placeholder="+1234567890">
</div>
<div class="input-group">
<label for="contactEmail">Email</label>
<input type="email" id="contactEmail" placeholder="john@example.com">
</div>
`,
wifi: `
<div class="input-group">
<label for="wifiSSID">Network Name (SSID)</label>
<input type="text" id="wifiSSID" placeholder="MyWiFi">
</div>
<div class="input-group">
<label for="wifiPassword">Password</label>
<input type="password" id="wifiPassword" placeholder="••••••••">
</div>
<div class="input-group">
<label for="wifiSecurity">Security Type</label>
<select id="wifiSecurity">
<option value="WPA">WPA/WPA2</option>
<option value="WEP">WEP</option>
<option value="nopass">Open Network</option>
</select>
</div>
`
};
// Initialize NFC support check
async function checkNFCSupport() {
if ('NDEFReader' in window) {
nfcSupported = true;
try {
const ndef = new NDEFReader();
await ndef.scan();
nfcPermission = true;
updateStatus('NFC Ready', true);
modeToggle.checked = true;
useRealNFC = true;
updateNFCMode(true);
} catch (error) {
if (error.name === 'NotAllowedError') {
updateStatus('NFC Permission Required', false);
showToast('NFC permission required. Please grant access.', 'info');
} else {
updateStatus('NFC Error', false);
}
}
} else {
nfcSupported = false;
updateStatus('NFC Not Supported', false);
modeToggle.checked = false;
useRealNFC = false;
updateNFCMode(false);
}
}
function updateStatus(text, success) {
statusText.textContent = text;
if (success) {
statusDot.classList.remove('error');
} else {
statusDot.classList.add('error');
}
}
function updateNFCMode(useReal) {
useRealNFC = useReal;
if (useReal) {
modeText.textContent = 'Real NFC';
deviceTitle.textContent = 'NFC Device';
deviceIcon.textContent = '📱';
scanBtn.style.display = 'block';
writeBtn.innerHTML = '<span>✍️</span><span>Write to NFC</span>';
} else {
modeText.textContent = 'Simulator';
deviceTitle.textContent = 'NFC Simulator';
deviceIcon.textContent = '📡';
scanBtn.style.display = 'none';
writeBtn.innerHTML = '<span>⚡</span><span>Transfer Data</span>';
}
}
// Event listeners
modeToggle.addEventListener('change', (e) => {
updateNFCMode(e.target.checked);
if (e.target.checked && !nfcSupported) {
showToast('NFC not supported on this device', 'error');
modeToggle.checked = false;
updateNFCMode(false);
}
});
document.querySelectorAll('.data-type-btn').forEach(btn => {
btn.addEventListener('click', function() {
document.querySelectorAll('.data-type-btn').forEach(b => b.classList.remove('active'));
this.classList.add('active');
currentDataType = this.dataset.type;
updateDataInput();
});
});
document.querySelectorAll('.format-chip').forEach(chip => {
chip.addEventListener('click', function() {
document.querySelectorAll('.format-chip').forEach(c => c.classList.remove('active'));
this.classList.add('active');
currentFormat = this.dataset.format;
});
});
nfcDevice.addEventListener('click', () => {
if (useRealNFC) {
requestNFCTap();
} else {
simulateTransfer();
}
});
writeBtn.addEventListener('click', () => {
if (useRealNFC) {
writeToNFC();
} else {
initiateTransfer();
}
});
clearBtn.addEventListener('click', clearData);
scanBtn.addEventListener('click', scanNFC);
cancelScan.addEventListener('click', () => {
scanOverlay.classList.remove('active');
});
closeModal.addEventListener('click', () => viewModal.classList.remove('active'));
function updateDataInput() {
dataInputSection.innerHTML = dataTemplates[currentDataType] + `
<div class="format-options">
<div class="format-chip ${currentFormat === 'plain' ? 'active' : ''}" data-format="plain">Plain</div>
<div class="format-chip ${currentFormat === 'json' ? 'active' : ''}" data-format="json">JSON</div>
<div class="format-chip ${currentFormat === 'base64' ? 'active' : ''}" data-format="base64">Base64</div>
<div class="format-chip ${currentFormat === 'hex' ? 'active' : ''}" data-format="hex">Hex</div>
</div>
`;
// Re-attach format chip listeners
document.querySelectorAll('.format-chip').forEach(chip => {
chip.addEventListener('click', function() {
document.querySelectorAll('.format-chip').forEach(c => c.classList.remove('active'));
this.classList.add('active');
currentFormat = this.dataset.format;
});
});
}
function simulateTransfer() {
if (isTransferring) return;
nfcDevice.classList.add('active');
setTimeout(() => {
nfcDevice.classList.remove('active');
}, 1000);
}
async function requestNFCTap() {
if (!nfcSupported || !nfcPermission) {
showToast('NFC not available or permission denied', 'error');
return;
}
showToast('Tap your phone on an NFC tag', 'info');
nfcDevice.classList.add('active');
setTimeout(() => {
nfcDevice.classList.remove('active');
}, 2000);
}
async function scanNFC() {
if (!nfcSupported) {
showToast('NFC not supported', 'error');
return;
}
try {
const ndef = new NDEFReader();
scanOverlay.classList.add('active');
scanStatus.textContent = 'Scanning for NFC tags...';
await ndef.scan();
showToast('Ready to scan', 'success');
ndef.addEventListener("reading", ({ message, serialNumber }) => {
scanOverlay.classList.remove('active');
handleNFCRead(message, serialNumber);
});
} catch (error) {
scanOverlay.classList.remove('active');
showToast('Failed to start NFC scan: ' + error.message, 'error');
}
}
function handleNFCRead(message, serialNumber) {
let data = {
type: 'text',
content: '',
serialNumber: serialNumber,
timestamp: new Date()
};
for (const record of message.records) {
if (record.recordType === "text") {
const textDecoder = new TextDecoder(record.encoding);
data.content = textDecoder.decode(record.data);
data.type = 'text';
} else if (record.recordType === "url") {
const textDecoder = new TextDecoder();
data.content = textDecoder.decode(record.data);
data.type = 'url';
}
}
const historyItem = {
id: Date.now(),
type: 'read',
data: data,
timestamp: new Date()
};
transferHistory.unshift(historyItem);
updateHistoryDisplay();
showToast('NFC data read successfully!', 'success');
}
async function writeToNFC() {
if (!nfcSupported) {
showToast('NFC not supported', 'error');
return;
}
const data = collectData();
if (!validateData(data)) {
showToast('Please fill in the required fields', 'error');
return;
}
try {
isTransferring = true;
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>NFC Data Transfer Hub - Mobile Ready</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--primary: #6366f1;
--primary-dark: #4f46e5;
--secondary: #22d3ee;
--success: #10b981;
--warning: #f59e0b;
--danger: #ef4444;
--dark: #1e293b;
--light: #f1f5f9;
--white: #ffffff;
--shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
--shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.15);
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
color: var(--dark);
position: relative;
overflow-x: hidden;
-webkit-tap-highlight-color: transparent;
}
.animated-bg {
position: fixed;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: -1;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.animated-bg::before {
content: '';
position: absolute;
width: 200%;
height: 200%;
top: -50%;
left: -50%;
background: radial-gradient(circle, rgba(255, 255, 255, 0.1) 1px, transparent 1px);
background-size: 50px 50px;
animation: bgMove 20s linear infinite;
}
@keyframes bgMove {
0% { transform: translate(0, 0); }
100% { transform: translate(50px, 50px); }
}
header {
background: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(10px);
padding: 1rem;
box-shadow: var(--shadow);
position: sticky;
top: 0;
z-index: 100;
}
.header-content {
max-width: 1400px;
margin: 0 auto;
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
gap: 1rem;
}
.logo {
display: flex;
align-items: center;
gap: 0.75rem;
}
.logo-icon {
width: 40px;
height: 40px;
background: linear-gradient(135deg, var(--primary), var(--secondary));
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
color: white;