Null checks

This commit is contained in:
Jonathon Leight committed 2026-07-02 19:20:35 -04:00
1 parent f16db89b6c
commit 920bc80042
4 files changed
+23 -13

No files matched your search

+3 -2
View File
@@ -21,8 +21,9 @@
}
if (!("serial" in navigator)) {
document.getElementById("unsupported").hidden = false;
connectBtn.disabled = true;
const unsupportedEl = document.getElementById("unsupported");
if (unsupportedEl) unsupportedEl.hidden = false;
if (connectBtn) connectBtn.disabled = true;
return;
}
+13 -7
View File
@@ -13,6 +13,12 @@
"use strict";
var $ = function (id) { return document.getElementById(id); };
// on wires an event handler, skipping silently if the element is absent, so a
// trimmed-down template can omit controls without breaking setup.
var on = function (id, event, fn) {
var el = $(id);
if (el) el.addEventListener(event, fn);
};
var hex = function (bytes) {
return Array.prototype.map.call(bytes, function (b) {
return b.toString(16).padStart(2, "0");
@@ -339,15 +345,15 @@
document.querySelectorAll('input[name="keymode"]').forEach(function (el) {
el.addEventListener("change", refreshKeyMode);
});
$("regen").addEventListener("click", function () {
on("regen", "click", function () {
generateKeyPair().then(function (k) { setKeyState(k.privHex, k.pubHex); });
});
$("privkey").addEventListener("input", function () {
on("privkey", "input", function () {
if (selectedKeyMode() === "paste") applyPastedKey();
});
$("grind").addEventListener("click", grind);
$("grind-stop").addEventListener("click", function () { grinding = false; });
$("org").addEventListener("change", refreshOrg);
$("generate").addEventListener("click", generate);
$("run").addEventListener("click", run);
on("grind", "click", grind);
on("grind-stop", "click", function () { grinding = false; });
on("org", "change", refreshOrg);
on("generate", "click", generate);
on("run", "click", run);
})();
+3 -2
View File
@@ -18,8 +18,9 @@
}
if (!("serial" in navigator)) {
document.getElementById("unsupported").hidden = false;
connectBtn.disabled = true;
const unsupportedEl = document.getElementById("unsupported");
if (unsupportedEl) unsupportedEl.hidden = false;
if (connectBtn) connectBtn.disabled = true;
return;
}
+4 -2
View File
@@ -80,7 +80,8 @@ async function postJSON(url, body) {
}
async function passkeyRegister() {
const username = document.getElementById("username").value.trim();
const nameEl = document.getElementById("username");
const username = nameEl ? nameEl.value.trim() : "";
const dnEl = document.getElementById("displayName");
const displayName = dnEl ? dnEl.value.trim() : "";
try {
@@ -140,7 +141,8 @@ async function addPasskey() {
// passkeyLogin runs a username-scoped assertion (for credentials that aren't
// discoverable, where the server needs to know which account to challenge).
async function passkeyLogin() {
const username = document.getElementById("username").value.trim();
const nameEl = document.getElementById("username");
const username = nameEl ? nameEl.value.trim() : "";
try {
setStatus("Starting…");
const options = await postJSON("/api/login/begin", { username });