[fix](trx-frontend-http): detect ft8 grids by scan
Co-authored-by: Codex <codex@openai.com> Signed-off-by: Stanislaw Grams <stanislawgrams@gmail.com>
This commit is contained in:
@@ -29,29 +29,32 @@ function addFt8Message(msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function renderFt8Message(message) {
|
function renderFt8Message(message) {
|
||||||
const parts = message.split(/(\\s+)/);
|
const gridRegex = /[A-R]{2}\\d{2}(?:[A-X]{2})?/gi;
|
||||||
return parts.map((part) => {
|
let out = "";
|
||||||
if (/^\\s+$/.test(part)) return part;
|
let lastIdx = 0;
|
||||||
const m = part.match(/^([^A-Za-z0-9]*)([A-Za-z0-9]+)([^A-Za-z0-9]*)$/);
|
for (const match of message.matchAll(gridRegex)) {
|
||||||
if (!m) return escapeHtml(part);
|
const idx = match.index ?? 0;
|
||||||
const [, lead, core, tail] = m;
|
const grid = match[0].toUpperCase();
|
||||||
const grid = core.toUpperCase();
|
const prev = idx > 0 ? message[idx - 1] : "";
|
||||||
if (/^[A-R]{2}\\d{2}(?:[A-X]{2})?$/.test(grid)) {
|
const next = idx + grid.length < message.length ? message[idx + grid.length] : "";
|
||||||
return `${escapeHtml(lead)}<span class="ft8-locator">[${grid}]</span>${escapeHtml(tail)}`;
|
if (isAlphaNum(prev) || isAlphaNum(next)) continue;
|
||||||
}
|
out += escapeHtml(message.slice(lastIdx, idx));
|
||||||
return escapeHtml(part);
|
out += `<span class="ft8-locator">[${grid}]</span>`;
|
||||||
}).join("");
|
lastIdx = idx + grid.length;
|
||||||
|
}
|
||||||
|
out += escapeHtml(message.slice(lastIdx));
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractFirstGrid(message) {
|
function extractFirstGrid(message) {
|
||||||
const parts = message.split(/\\s+/);
|
const gridRegex = /[A-R]{2}\\d{2}(?:[A-X]{2})?/gi;
|
||||||
for (const part of parts) {
|
for (const match of message.matchAll(gridRegex)) {
|
||||||
const m = part.match(/[A-Za-z0-9]+/);
|
const idx = match.index ?? 0;
|
||||||
if (!m) continue;
|
const grid = match[0].toUpperCase();
|
||||||
const grid = m[0].toUpperCase();
|
const prev = idx > 0 ? message[idx - 1] : "";
|
||||||
if (/^[A-R]{2}\\d{2}(?:[A-X]{2})?$/.test(grid)) {
|
const next = idx + grid.length < message.length ? message[idx + grid.length] : "";
|
||||||
return grid;
|
if (isAlphaNum(prev) || isAlphaNum(next)) continue;
|
||||||
}
|
return grid;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -64,6 +67,10 @@ function escapeHtml(input) {
|
|||||||
.replaceAll("\"", """);
|
.replaceAll("\"", """);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isAlphaNum(ch) {
|
||||||
|
return /[A-Za-z0-9]/.test(ch);
|
||||||
|
}
|
||||||
|
|
||||||
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); }
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user