Spaces:
Running
Running
NFC Tag-Write Toolkit: static web UI (ndef.js byte-identical to tested Python builder)
7207e78 verified Download index.html from shivay00001/nfc-write-toolkit: direct link, hf CLI and curl.
- Browser
- Download file 14.1 kB
-
https://huggingface.co/spaces/shivay00001/nfc-write-toolkit/resolve/main/index.html
- Command line
-
hf download hf://spaces/shivay00001/nfc-write-toolkit/index.html
-
curl -L -o index.html https://huggingface.co/spaces/shivay00001/nfc-write-toolkit/resolve/main/index.html
14.1 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <title>NFC Tag-Write Toolkit — NTAG215</title> | |
| <style> | |
| :root { color-scheme: light; } | |
| body { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; max-width: 760px; margin: 0 auto; padding: 24px 16px 64px; color: #1a1a1a; line-height: 1.5; } | |
| h1 { font-size: 1.6em; margin-bottom: 0.2em; } | |
| h2 { font-size: 1.15em; margin-top: 1.4em; } | |
| .sub { color: #555; margin-top: 0; } | |
| .tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 18px 0; } | |
| .tabs button { padding: 8px 12px; border: 1px solid #999; background: #fff; border-radius: 8px; cursor: pointer; font-size: 0.95em; } | |
| .tabs button[aria-selected="true"] { background: #1a1a1a; color: #fff; border-color: #1a1a1a; } | |
| .panel { display: none; border: 1px solid #ddd; border-radius: 10px; padding: 16px; } | |
| .panel.active { display: block; } | |
| label { display: block; font-weight: 600; margin: 12px 0 4px; } | |
| input, select, textarea { width: 100%; box-sizing: border-box; padding: 9px 10px; font-size: 1em; border: 1px solid #999; border-radius: 6px; } | |
| .build { margin-top: 16px; padding: 10px 18px; font-size: 1em; background: #0b6e4f; color: #fff; border: none; border-radius: 8px; cursor: pointer; } | |
| .build:hover { background: #095c42; } | |
| .out { margin-top: 16px; } | |
| .out label { margin-top: 10px; } | |
| .out pre, .out textarea { background: #f6f6f6; border: 1px solid #ddd; border-radius: 6px; padding: 10px; white-space: pre-wrap; word-break: break-all; font-family: ui-monospace, monospace; font-size: 0.9em; } | |
| .out textarea { width: 100%; box-sizing: border-box; } | |
| .err { color: #b00020; font-weight: 600; } | |
| .ok-size { font-weight: 700; } | |
| .warn { background: #fff8e1; border: 1px solid #e6c200; border-radius: 8px; padding: 10px 12px; } | |
| .dl { display: inline-block; margin-top: 10px; padding: 8px 14px; background: #1a1a1a; color: #fff; border-radius: 8px; text-decoration: none; } | |
| .dl[hidden] { display: none; } | |
| footer { margin-top: 32px; color: #555; font-size: 0.92em; } | |
| code { background: #f0f0f0; padding: 1px 5px; border-radius: 4px; } | |
| </style> | |
| </head> | |
| <body> | |
| <h1>📶 NFC Tag-Write Toolkit — NTAG215</h1> | |
| <p class="sub">Build spec-correct NDEF payloads for blank NTAG215 tags (504 bytes of user memory). | |
| Build here, then write the tag with NFC Tools / NXP TagWriter on your phone, or with a USB reader. | |
| <strong>Never lock a tag before tap-testing it — locking is permanent.</strong></p> | |
| <p class="sub">Everything runs in your browser. No account, no cloud, nothing you type leaves this page.</p> | |
| <div class="tabs" role="tablist" id="tabs"></div> | |
| <!-- 1 · Google review card --> | |
| <section class="panel" id="panel-gmb" role="tabpanel"> | |
| <h2>Google review card</h2> | |
| <div class="warn"><strong>Honesty rule.</strong> This card opens <strong>only the shop's genuine Google review page</strong> — | |
| the link from its own Google Business Profile (<em>Get more reviews → Share review form</em>, e.g. | |
| <code>https://g.page/r/XXXX/review</code>). It must <strong>never</strong> contain prefilled review text, a pre-selected | |
| star rating, star-gating, or any direct-submit trick. The customer writes whatever they honestly want — including a bad review.</div> | |
| <label for="gmb-url">Genuine Google review link</label> | |
| <input id="gmb-url" type="url" placeholder="https://g.page/r/AbCdEfGhIjKlMn/review" autocomplete="off"> | |
| <button class="build" data-build="gmb">Build review-card payload</button> | |
| <div class="out" data-out="gmb"></div> | |
| </section> | |
| <!-- 2 · UPI --> | |
| <section class="panel" id="panel-upi" role="tabpanel"> | |
| <h2>UPI payment card</h2> | |
| <p>Tap opens the customer's UPI app with the shop's payment details filled in. <strong>Amount is left blank by default</strong> — | |
| the customer types it. Add a fixed amount only if the shop explicitly asks, and warn them a fixed amount can't be changed at tap time.</p> | |
| <p>⚠️ iPhone: UPI apps on iOS generally don't register the <code>upi://</code> scheme — sell payment cards as Android-first.</p> | |
| <label for="upi-pa">UPI ID (pa)</label> | |
| <input id="upi-pa" placeholder="shopname@okhdfc" autocomplete="off"> | |
| <label for="upi-pn">Payee name (pn)</label> | |
| <input id="upi-pn" placeholder="My Shop" autocomplete="off"> | |
| <label for="upi-am">Fixed amount ₹ (optional — leave blank for customer-entered amount)</label> | |
| <input id="upi-am" placeholder="499" inputmode="decimal" autocomplete="off"> | |
| <button class="build" data-build="upi">Build UPI payload</button> | |
| <div class="out" data-out="upi"></div> | |
| </section> | |
| <!-- 3 · URL --> | |
| <section class="panel" id="panel-url" role="tabpanel"> | |
| <h2>Website / menu / catalogue link</h2> | |
| <label for="url-input">URL</label> | |
| <input id="url-input" type="url" placeholder="https://www.myshop.example" autocomplete="off"> | |
| <button class="build" data-build="url">Build URL payload</button> | |
| <div class="out" data-out="url"></div> | |
| </section> | |
| <!-- 4 · Tel --> | |
| <section class="panel" id="panel-tel" role="tabpanel"> | |
| <h2>Tap to call</h2> | |
| <p>Tap opens the phone app with the number ready to call — nothing dials by itself.</p> | |
| <label for="tel-input">Phone number (with country code)</label> | |
| <input id="tel-input" type="tel" placeholder="+919876543210" autocomplete="off"> | |
| <button class="build" data-build="tel">Build call payload</button> | |
| <div class="out" data-out="tel"></div> | |
| </section> | |
| <!-- 5 · SMS --> | |
| <section class="panel" id="panel-sms" role="tabpanel"> | |
| <h2>Tap to text (SMS)</h2> | |
| <label for="sms-num">Phone number (with country code)</label> | |
| <input id="sms-num" type="tel" placeholder="+919876543210" autocomplete="off"> | |
| <label for="sms-body">Message (optional — keep it short)</label> | |
| <input id="sms-body" placeholder="Hi, I want to book an appointment" autocomplete="off"> | |
| <button class="build" data-build="sms">Build SMS payload</button> | |
| <div class="out" data-out="sms"></div> | |
| </section> | |
| <!-- 6 · Text --> | |
| <section class="panel" id="panel-text" role="tabpanel"> | |
| <h2>Plain text</h2> | |
| <p>Tap shows a short piece of text — today's offer, opening hours, an instruction. Max 489 characters fills the tag exactly.</p> | |
| <label for="text-input">Text</label> | |
| <textarea id="text-input" rows="3" placeholder="Welcome to My Shop! Tap for today's offers."></textarea> | |
| <button class="build" data-build="text">Build text payload</button> | |
| <div class="out" data-out="text"></div> | |
| </section> | |
| <!-- 7 · vCard --> | |
| <section class="panel" id="panel-vcard" role="tabpanel"> | |
| <h2>Contact card (vCard)</h2> | |
| <p>Tap offers to save the shop as a phone contact.</p> | |
| <label for="vc-name">Name (required)</label> | |
| <input id="vc-name" placeholder="Asha Sharma" autocomplete="off"> | |
| <label for="vc-phone">Phone</label> | |
| <input id="vc-phone" type="tel" placeholder="+919876543210" autocomplete="off"> | |
| <label for="vc-email">Email</label> | |
| <input id="vc-email" type="email" placeholder="asha@example.com" autocomplete="off"> | |
| <label for="vc-org">Organisation</label> | |
| <input id="vc-org" placeholder="Asha Salon" autocomplete="off"> | |
| <label for="vc-url">Website</label> | |
| <input id="vc-url" type="url" placeholder="https://www.example.com" autocomplete="off"> | |
| <button class="build" data-build="vcard">Build vCard payload</button> | |
| <div class="out" data-out="vcard"></div> | |
| </section> | |
| <!-- 8 · Wi-Fi --> | |
| <section class="panel" id="panel-wifi" role="tabpanel"> | |
| <h2>Wi-Fi network</h2> | |
| <p>Tap joins the phone to the shop's Wi-Fi (Android). ⚠️ iOS does not join Wi-Fi from NFC tags — Android-first, or print the password on the card for iPhone guests.</p> | |
| <label for="wifi-ssid">Network name (SSID)</label> | |
| <input id="wifi-ssid" placeholder="MyShop WiFi" autocomplete="off"> | |
| <label for="wifi-pw">Password (8–63 chars for secured networks)</label> | |
| <input id="wifi-pw" type="password" placeholder="correcthorsebatterystaple" autocomplete="off"> | |
| <label for="wifi-auth">Security</label> | |
| <select id="wifi-auth"><option>WPA2-PSK</option><option>WPA-PSK</option><option>open</option></select> | |
| <button class="build" data-build="wifi">Build Wi-Fi payload</button> | |
| <div class="out" data-out="wifi"></div> | |
| </section> | |
| <footer> | |
| <h2>How to write the tag</h2> | |
| <p><strong>Phone (no computer):</strong> open NFC Tools → Write → Add a record → paste the payload shown above | |
| (URL / URI / text) → Write → hold the phone to the tag. For the Wi-Fi and vCard tabs, use the matching record type in the app.</p> | |
| <p><strong>USB reader:</strong> download the <code>.bin</code> file and write it with <code>write_tag.py</code> from the repo, which reads back and compares.</p> | |
| <p><strong>Golden rule:</strong> write → tap-test on a phone → only then lock (if you lock at all). A locked tag can never be rewritten.</p> | |
| <p>Builder: a faithful JavaScript port of <code>ndef_builder.py</code> — NDEF + Type 2 Tag TLV framing with NTAG215 capacity | |
| enforcement. The Python original passes 27/27 unit tests; this page's JavaScript produces byte-identical output on all 43 verified cases | |
| (every usage, unicode, capacity boundary 489/490 chars, and every error path). No secrets, no tracking, no external resources.</p> | |
| </footer> | |
| <script src="ndef.js"></script> | |
| <script> | |
| (function () { | |
| "use strict"; | |
| var CAP = NDEF.NTAG215_CAPACITY; | |
| var TABS = [ | |
| ["gmb", "1 · Google review"], ["upi", "2 · UPI payment"], ["url", "3 · Website link"], | |
| ["tel", "4 · Tap to call"], ["sms", "5 · Tap to text"], ["text", "6 · Plain text"], | |
| ["vcard", "7 · Contact card"], ["wifi", "8 · Wi-Fi"] | |
| ]; | |
| /* Tabs */ | |
| var tabsEl = document.getElementById("tabs"); | |
| TABS.forEach(function (t, i) { | |
| var b = document.createElement("button"); | |
| b.textContent = t[1]; | |
| b.setAttribute("role", "tab"); | |
| b.setAttribute("aria-selected", i === 0 ? "true" : "false"); | |
| b.addEventListener("click", function () { show(t[0]); }); | |
| tabsEl.appendChild(b); | |
| }); | |
| function show(key) { | |
| TABS.forEach(function (t) { | |
| document.getElementById("panel-" + t[0]).classList.toggle("active", t[0] === key); | |
| }); | |
| Array.prototype.forEach.call(tabsEl.children, function (b, i) { | |
| b.setAttribute("aria-selected", TABS[i][0] === key ? "true" : "false"); | |
| }); | |
| } | |
| show("gmb"); | |
| function val(id) { return document.getElementById(id).value; } | |
| function render(outEl, usage, framed, displayText) { | |
| outEl.innerHTML = ""; | |
| var size = document.createElement("p"); | |
| size.innerHTML = ""; | |
| var sizeLabel = document.createElement("label"); | |
| sizeLabel.textContent = "Framed size (NTAG215 holds 504 bytes)"; | |
| var sizeVal = document.createElement("p"); | |
| sizeVal.className = "ok-size"; | |
| sizeVal.textContent = framed.length + " / " + CAP + " bytes (" + | |
| Math.round(100 * framed.length / CAP) + "% of the tag)"; | |
| var payLabel = document.createElement("label"); | |
| payLabel.textContent = "Payload that will go on the tag"; | |
| var payVal = document.createElement("pre"); | |
| payVal.textContent = displayText; | |
| var hexLabel = document.createElement("label"); | |
| hexLabel.textContent = "Framed bytes (hex — exactly what gets written)"; | |
| var hexVal = document.createElement("pre"); | |
| hexVal.textContent = Array.prototype.map.call(framed, function (b) { | |
| return ("0" + b.toString(16)).slice(-2).toUpperCase(); | |
| }).join(" "); | |
| var dl = document.createElement("a"); | |
| dl.className = "dl"; | |
| dl.textContent = "Download framed bytes (.bin)"; | |
| dl.download = "ntag215-" + usage + ".bin"; | |
| dl.href = URL.createObjectURL(new Blob([framed], { type: "application/octet-stream" })); | |
| outEl.append(sizeLabel, sizeVal, payLabel, payVal, hexLabel, hexVal, dl); | |
| } | |
| function renderError(outEl, err) { | |
| outEl.innerHTML = ""; | |
| var p = document.createElement("p"); | |
| p.className = "err"; | |
| p.textContent = "ERROR: " + err.message; | |
| outEl.appendChild(p); | |
| } | |
| var BUILDERS = { | |
| gmb: function () { | |
| var framed = NDEF.buildGmbReview(val("gmb-url").trim()); | |
| return [framed, "URI on tag: " + NDEF.decodeUri(NDEF.firstRecord(framed))]; | |
| }, | |
| upi: function () { | |
| var framed = NDEF.buildUpi(val("upi-pa").trim(), val("upi-pn").trim(), val("upi-am").trim()); | |
| return [framed, "UPI URI on tag: " + NDEF.decodeUri(NDEF.firstRecord(framed))]; | |
| }, | |
| url: function () { | |
| var framed = NDEF.buildUrl(val("url-input").trim()); | |
| return [framed, "URI on tag: " + NDEF.decodeUri(NDEF.firstRecord(framed))]; | |
| }, | |
| tel: function () { | |
| var framed = NDEF.buildTel(val("tel-input").trim()); | |
| return [framed, "URI on tag: " + NDEF.decodeUri(NDEF.firstRecord(framed))]; | |
| }, | |
| sms: function () { | |
| var framed = NDEF.buildSms(val("sms-num").trim(), val("sms-body")); | |
| return [framed, "URI on tag: " + NDEF.decodeUri(NDEF.firstRecord(framed))]; | |
| }, | |
| text: function () { | |
| var framed = NDEF.buildText(val("text-input")); | |
| return [framed, "Text on tag: " + NDEF.decodeText(NDEF.firstRecord(framed))]; | |
| }, | |
| vcard: function () { | |
| var framed = NDEF.buildVcard(val("vc-name").trim(), val("vc-phone").trim(), | |
| val("vc-email").trim(), val("vc-org").trim(), val("vc-url").trim()); | |
| return [framed, "vCard on tag:\n" + | |
| new TextDecoder().decode(NDEF.firstRecord(framed).payload)]; | |
| }, | |
| wifi: function () { | |
| var framed = NDEF.buildWifi(val("wifi-ssid").trim(), val("wifi-pw"), val("wifi-auth")); | |
| var w = NDEF.decodeWifi(NDEF.firstRecord(framed)); | |
| return [framed, "SSID: " + w.ssid + "\nAuth: " + w.auth + | |
| "\nPassword: " + (w.password ? "(hidden)" : "(none — open network)")]; | |
| } | |
| }; | |
| document.querySelectorAll("button.build").forEach(function (btn) { | |
| btn.addEventListener("click", function () { | |
| var usage = btn.getAttribute("data-build"); | |
| var outEl = document.querySelector('[data-out="' + usage + '"]'); | |
| try { | |
| var r = BUILDERS[usage](); | |
| render(outEl, usage, r[0], r[1]); | |
| } catch (e) { renderError(outEl, e); } | |
| }); | |
| }); | |
| })(); | |
| </script> | |
| </body> | |
| </html> | |