From 5aa9502e374a74496515e026758ac9837329ec6c Mon Sep 17 00:00:00 2001 From: Stanislaw Grams Date: Mon, 9 Feb 2026 22:14:22 +0100 Subject: [PATCH] [fix](trx-frontend-http): normalize ft8 locator spacing Co-authored-by: Codex Signed-off-by: Stanislaw Grams --- .../assets/web/plugins/ft8.js | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/trx-client/trx-frontend/trx-frontend-http/assets/web/plugins/ft8.js b/src/trx-client/trx-frontend/trx-frontend-http/assets/web/plugins/ft8.js index b9622ef..b2e72c7 100644 --- a/src/trx-client/trx-frontend/trx-frontend-http/assets/web/plugins/ft8.js +++ b/src/trx-client/trx-frontend/trx-frontend-http/assets/web/plugins/ft8.js @@ -29,30 +29,32 @@ function addFt8Message(msg) { } function renderFt8Message(message) { + const normalized = normalizeSpaces(message); const gridRegex = /[A-R]{2}\\d{2}(?:[A-X]{2})?/gi; let out = ""; let lastIdx = 0; - for (const match of message.matchAll(gridRegex)) { + for (const match of normalized.matchAll(gridRegex)) { const idx = match.index ?? 0; const grid = match[0].toUpperCase(); - const prev = idx > 0 ? message[idx - 1] : ""; - const next = idx + grid.length < message.length ? message[idx + grid.length] : ""; + const prev = idx > 0 ? normalized[idx - 1] : ""; + const next = idx + grid.length < normalized.length ? normalized[idx + grid.length] : ""; if (isAlphaNum(prev) || isAlphaNum(next)) continue; - out += escapeHtml(message.slice(lastIdx, idx)); + out += escapeHtml(normalized.slice(lastIdx, idx)); out += `[${grid}]`; lastIdx = idx + grid.length; } - out += escapeHtml(message.slice(lastIdx)); + out += escapeHtml(normalized.slice(lastIdx)); return out; } function extractFirstGrid(message) { + const normalized = normalizeSpaces(message); const gridRegex = /[A-R]{2}\\d{2}(?:[A-X]{2})?/gi; - for (const match of message.matchAll(gridRegex)) { + for (const match of normalized.matchAll(gridRegex)) { const idx = match.index ?? 0; const grid = match[0].toUpperCase(); - const prev = idx > 0 ? message[idx - 1] : ""; - const next = idx + grid.length < message.length ? message[idx + grid.length] : ""; + const prev = idx > 0 ? normalized[idx - 1] : ""; + const next = idx + grid.length < normalized.length ? normalized[idx + grid.length] : ""; if (isAlphaNum(prev) || isAlphaNum(next)) continue; return grid; } @@ -71,6 +73,10 @@ function isAlphaNum(ch) { return /[A-Za-z0-9]/.test(ch); } +function normalizeSpaces(input) { + return input.replace(/[\\u00A0\\u2000-\\u200B\\u202F\\u205F\\u3000]/g, " "); +} + document.getElementById("ft8-decode-toggle-btn").addEventListener("click", async () => { try { await postPath("/toggle_ft8_decode"); } catch (e) { console.error("FT8 toggle failed", e); } });