[fix](trx-frontend-http): normalize ft8 locator spacing

Co-authored-by: Codex <codex@openai.com>
Signed-off-by: Stanislaw Grams <stanislawgrams@gmail.com>
This commit is contained in:
2026-02-09 22:14:22 +01:00
parent dc376c9afb
commit 5aa9502e37
@@ -29,30 +29,32 @@ function addFt8Message(msg) {
} }
function renderFt8Message(message) { function renderFt8Message(message) {
const normalized = normalizeSpaces(message);
const gridRegex = /[A-R]{2}\\d{2}(?:[A-X]{2})?/gi; const gridRegex = /[A-R]{2}\\d{2}(?:[A-X]{2})?/gi;
let out = ""; let out = "";
let lastIdx = 0; let lastIdx = 0;
for (const match of message.matchAll(gridRegex)) { for (const match of normalized.matchAll(gridRegex)) {
const idx = match.index ?? 0; const idx = match.index ?? 0;
const grid = match[0].toUpperCase(); const grid = match[0].toUpperCase();
const prev = idx > 0 ? message[idx - 1] : ""; const prev = idx > 0 ? normalized[idx - 1] : "";
const next = idx + grid.length < message.length ? message[idx + grid.length] : ""; const next = idx + grid.length < normalized.length ? normalized[idx + grid.length] : "";
if (isAlphaNum(prev) || isAlphaNum(next)) continue; if (isAlphaNum(prev) || isAlphaNum(next)) continue;
out += escapeHtml(message.slice(lastIdx, idx)); out += escapeHtml(normalized.slice(lastIdx, idx));
out += `<span class="ft8-locator">[${grid}]</span>`; out += `<span class="ft8-locator">[${grid}]</span>`;
lastIdx = idx + grid.length; lastIdx = idx + grid.length;
} }
out += escapeHtml(message.slice(lastIdx)); out += escapeHtml(normalized.slice(lastIdx));
return out; return out;
} }
function extractFirstGrid(message) { function extractFirstGrid(message) {
const normalized = normalizeSpaces(message);
const gridRegex = /[A-R]{2}\\d{2}(?:[A-X]{2})?/gi; 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 idx = match.index ?? 0;
const grid = match[0].toUpperCase(); const grid = match[0].toUpperCase();
const prev = idx > 0 ? message[idx - 1] : ""; const prev = idx > 0 ? normalized[idx - 1] : "";
const next = idx + grid.length < message.length ? message[idx + grid.length] : ""; const next = idx + grid.length < normalized.length ? normalized[idx + grid.length] : "";
if (isAlphaNum(prev) || isAlphaNum(next)) continue; if (isAlphaNum(prev) || isAlphaNum(next)) continue;
return grid; return grid;
} }
@@ -71,6 +73,10 @@ function isAlphaNum(ch) {
return /[A-Za-z0-9]/.test(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 () => { document.getElementById("ft8-decode-toggle-btn").addEventListener("click", async () => {
try { await postPath("/toggle_ft8_decode"); } catch (e) { console.error("FT8 toggle failed", e); } try { await postPath("/toggle_ft8_decode"); } catch (e) { console.error("FT8 toggle failed", e); }
}); });