morserino-abbreviations/morserino-abbr.html

105 lines
3 KiB
HTML
Raw Permalink Normal View History

2025-02-19 10:38:26 +01:00
<!-- SPDX-License-Identifier: Beerware -->
<!-- Copyright © 2025 Wolfgang Kroener -->
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Morserino abbreviations</title>
<style>
dl {
display: grid;
}
dt, dd {
margin-bottom: 1em;
margin-left: 0;
}
</style>
</head>
<body>
<p>
Look up morse abbreviations from <a id="abbr_url" href=""></a> (<span id="dict_info">0</span> entries loaded).<br>
See <a href="https://src.dm5wk.de/dm5wk/morserino-abbreviations">https://src.dm5wk.de/dm5wk/morserino-abbreviations</a> for more information.
</p>
<p>
Clear field with Enter.
</p>
<input type="text" id="abbr_input">
<dl id="abbr_result"></dl>
<script>
let abbr_list = [];
const url_blob = "https://github.com/oe1wkl/Morserino-32/blob/master/Documentation/User Manual/Version 6.x/m32_user-Manual_v6_de.adoc";
const appendix_match = new RegExp("\[\[appendix7\]\]");
2025-02-21 12:10:11 +01:00
const column_match = new RegExp(/::\s+/);
2025-02-19 10:38:26 +01:00
const url_raw = url_blob.replace("github.com", "raw.githubusercontent.com").replace("/blob/", "/")
document.getElementById("abbr_url").innerText = url_blob;
document.getElementById("abbr_url").href = url_blob;
// get user manual
fetch(url_raw)
.then(response => response.text())
.then((response) => {
let list_found = 0;
response.split('\n').forEach((line) => {
if (line.match(appendix_match)) {
// file is now at appendix with abbreviations
list_found = 1;
}
if ((list_found == 1) && (line.match(column_match))) {
// abbreviation found
abbr_list.push(line.split(column_match));
}
});
document.getElementById("dict_info").innerText = abbr_list.length;
// get largest abbreviation and set column width
let largest_abbr = 0;
abbr_list.forEach((line) => {
largest_abbr = Math.max(line[0].length, largest_abbr);
});
document.querySelector('dl').style.gridTemplateColumns = largest_abbr + "ch calc(100% - " + largest_abbr + "ch)";
});
// search as you type in input field, clear with enter
document.getElementById("abbr_input").addEventListener('keyup', (key) => {
if (key.key !== 'Enter') {
search();
} else {
// clear results and input field
document.getElementById("abbr_result").innerHTML = "";
document.getElementById("abbr_input").value = "";
}
});
// search for abbreviation from input field
function search() {
// clear results
document.getElementById("abbr_result").innerHTML = "";
const input = document.getElementById("abbr_input").value;
if (input.length == 0) {
return;
}
const regex = new RegExp(input);
abbr_list.forEach((line) => {
if (line[0].match(regex)) {
// abbreviation found, fill result
let dt = document.createElement("dt");
let dd = document.createElement("dd");
dt.innerText = line[0];
dd.innerText = line[1];
document.getElementById("abbr_result").appendChild(dt);
document.getElementById("abbr_result").appendChild(dd);
}
});
}
</script>
</body>
</html>