-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
372 lines (341 loc) · 14.2 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Morse Code Translator</title>
<meta property="og:title" content="Morse Code Translator" />
<meta name="author" content="Salif Mehmed" />
<meta name="robots" content="index, follow" />
<meta name="description"
content="Morse Code encoder, decoder, converter for Latin, Cyrillic, Greek, Hebrew, Arabic, Persian, Japanese, Korean, Thai" />
<meta property="og:description"
content="Morse Code encoder, decoder, converter for Latin, Cyrillic, Greek, Hebrew, Arabic, Persian, Japanese, Korean, Thai" />
<link rel="canonical" href="https://salif.github.io/morse-code-translator/" />
<meta property="og:url" content="https://salif.github.io/morse-code-translator/" />
<meta property="og:site_name" content="Morse Code Translator" />
<meta property="og:image" content="https://salif.github.io/morse-code-translator/icon.png" />
<meta property="og:type" content="website" />
<meta name="twitter:card" content="summary_large_image" />
<meta property="twitter:image" content="https://salif.github.io/morse-code-translator/icon.png" />
<meta property="twitter:title" content="Morse Code Translator" />
<link rel="icon" type="image/png" sizes="695x872" href="./icon.png" />
<style>
/* beautify ignore:start */
:root {color-scheme: light dark;} body {padding: 20px 10px;}
/* beautify ignore:end */
</style>
<link rel="stylesheet" href="https://unpkg.com/simpledotcss@2.3.2/simple.min.css" />
<style>
#main_table {
margin: auto;
max-width: 1024px;
}
#main_table tr:nth-child(even) {
background-color: unset;
}
#main_table td {
border: unset;
padding: 0.1rem;
}
#main_table label {
display: unset;
}
#main_table .row label {
font-weight: bold;
margin-right: 4px;
}
#main_table .row textarea {
width: 100%;
margin-bottom: unset;
}
#add_row_div .disabled {
background-color: var(--disabled);
color: var(--text-light);
}
#add_row_div input {
width: 32px;
display: inline-block;
}
.d-none {
display: none;
}
.w-100 {
width: 100%;
}
</style>
</head>
<body>
<noscript><b>This page requires JavaScript to work properly.</b></noscript>
<table id="main_table" class="d-none">
<tr>
<td><span></span></td>
<td class="w-100">
<div id="add_row_div" class="d-none">
<label><b>dot:</b> <input type="text" id="inp_dot" />
</label> <label><b>dash:</b> <input type="text" id="inp_dash" />
</label> <label><b>space:</b> <input type="text" id="inp_space" value="/"
class="disabled" />
</label> <label><b>separator:</b> <input type="text" id="inp_sep" value=" "
class="disabled" />
</label>
</div>
<input type="button" value="add row" id="btn_add_row"
data-lo='{"type": 3, "en": "add row", "ru": "добавить строку", "bg": "добавяне на ред"}' />
<label for="select_writing_system"
data-lo='{"type": 1, "en": "writing system:", "ru": "письмо:", "bg": "писменост:"}'>writing
system:</label>
<select id="select_writing_system">
<option value="1" data-lo='{"type": 2, "en": "Latin", "ru": "Латиница", "bg": "Латиница"}'> Latin
</option>
<option value="4"
data-lo='{"type": 2, "en": "Latin Extended", "ru": "Латиница расширенная", "bg": "Разширена латиница"}'>
Latin Extended</option>
<option value="5" data-lo='{"type": 2, "en": "Cyrillic", "ru": "Кириллица", "bg": "Кирилица"}'>
Cyrillic</option>
<option value="6" data-lo='{"type": 2, "en": "Greek", "ru": "Греческий", "bg": "Гръцка"}'> Greek
</option>
<option value="7" data-lo='{"type": 2, "en": "Hebrew", "ru": "Еврейское", "bg": "Еврейска"}'> Hebrew
</option>
<option value="8" data-lo='{"type": 2, "en": "Arabic", "ru": "Арабское", "bg": "Арабска"}'> Arabic
</option>
<option value="9" data-lo='{"type": 2, "en": "Persian", "ru": "Персидское", "bg": "Персийска"}'>
Persian</option>
<option value="10" data-lo='{"type": 2, "en": "Japanese", "ru": "Японская", "bg": "Японска"}'>
Japanese</option>
<option value="11" data-lo='{"type": 2, "en": "Korean", "ru": "Корейский", "bg": "Корейска"}'>
Korean</option>
<option value="12" data-lo='{"type": 2, "en": "Thai", "ru": "Тайское", "bg": "Тайска"}'> Thai
</option>
</select> <input type="button" value="info" id="btn_info"
data-lo='{"type": 3, "en": "info", "ru": "информация", "bg": "инфо"}'> <input type="button"
value="comments" id="btn_comments"
data-lo='{"type": 3, "en": "comments", "ru": "комментарии", "bg": "коментари"}' />
<div id="info_div" class="notice d-none">
<a href="https://codeberg.org/salif/morse-code-translator" target="_blank"
data-lo='{"type": 1, "en": "source code", "ru": "исходный код", "bg": "програмен код"}'>source
code</a>
</div>
</td>
</tr>
</table>
<section id="comments_container" class="d-none"></section>
<script>
"use strict";
(function () {
window.mct = {}
function set_element_language(d, dlo, lang) {
try {
const dp = JSON.parse(dlo)
if (!dp.hasOwnProperty(lang)) {
lang = "en"
}
switch (dp.type) {
case 0: window.document.title = dp[lang]; break;
case 1: d.textContent = dp[lang]; break;
case 2: d.textContent = dp[lang]; break;
case 3: d.value = dp[lang]; break;
case 4: d.placeholder = dp[lang]; break;
default: console.warn(dp); break;
}
} catch (err) {
console.error(err)
}
}
window.mct.set_page_language = function (lang) {
if (lang === "") { return }
document.documentElement.lang = lang
document.querySelectorAll("[data-lo]").forEach(d => {
set_element_language(d, d.dataset.lo, lang)
})
set_element_language(null, '{"type": 0, "en": "Morse Code Translator", "ru": "Переводчик Азбуки Морзе", "bg": "Преводач на морзова азбука"}', lang)
}
function main_table_add_row(main_table, options) {
const new_row = main_table.insertRow(0)
new_row.classList.add("row")
const new_row_id = "enter_" + main_table.rows.length
const new_row_label = document.createElement("label")
new_row_label.textContent = options.str_dot + options.str_dash
new_row_label.htmlFor = new_row_id
new_row.insertCell(0).appendChild(new_row_label)
const new_cell = new_row.insertCell(1)
new_cell.classList.add("w-100")
const el_text_area = document.createElement("textarea")
el_text_area.id = new_row_id
el_text_area.rows = "5"
el_text_area.dataset.lo = '{"type": 4, "en": "enter code", "ru": "введите код", "bg": "въведете код"}'
options.el = el_text_area
el_text_area.oninput = function () {
if (typeof window.mct.oninp === "function") {
window.mct.oninp(options)
} else {
// modules are not loaded yet
const old_value = this.value
window.setTimeout(function () {
if (old_value === el_text_area.value) {
window.mct.oninp(options)
}
}, 1000)
}
}
new_cell.appendChild(el_text_area)
if (options.str_dot === "abc" || options.str_dash === "") {
new_row_label.dataset.lo = '{"type": 1, "en": "abc", "ru": "абв", "bg": "абв"}'
el_text_area.dataset.lo = '{"type": 4, "en": "enter text", "ru": "введите текст", "bg": "въведете текст"}'
window.mct.input_abc = options
} else {
window.mct.inputs.push(options)
}
set_element_language(el_text_area, el_text_area.dataset.lo, document.documentElement.lang)
}
window.mct.inputs = []
window.mct.input_abc = {}
window.disqus_config = function () {
this.page.url = document.querySelector("link[rel='canonical']").getAttribute("href");
this.page.identifier = "/";
};
const el_main_table = document.getElementById("main_table")
main_table_add_row(el_main_table, { str_dot: "•", str_dash: "−", str_sp: "/", str_sep: " " })
main_table_add_row(el_main_table, { str_dot: ".", str_dash: "-", str_sp: "/", str_sep: " " })
main_table_add_row(el_main_table, { str_dot: "abc", str_dash: "", str_sp: "/", str_sep: " " })
switch (navigator.language || navigator.userLanguage) {
case "ru": window.mct.set_page_language("ru"); break;
case "bg": window.mct.set_page_language("bg"); break;
}
el_main_table.classList.remove("d-none")
function add_row(main_table, add_row_div, dot, dash, sp, sep) {
add_row_div.classList.remove("d-none")
if (dot.value.length === 0) { dot.focus(); return; }
if (dash.value.length === 0) { dash.focus(); return; }
if (sp.value.length === 0) { sp.focus(); return; }
if (sep.value.length === 0) { sep.focus(); return; }
main_table_add_row(main_table, {
str_dot: dot.value, str_dash: dash.value, str_sp: sp.value, str_sep: sep.value
})
dot.value = ""
dash.value = ""
sp.value = "/"
sep.value = " "
add_row_div.classList.add("d-none")
}
window.mct.scroll_to = function (el) {
const dom_rect = el.getBoundingClientRect()
const num_view_height = Math.max(document.documentElement.clientHeight, window.innerHeight)
const is_not_visible = dom_rect.bottom < 0 || dom_rect.top - num_view_height >= 0
if (is_not_visible) {
el.scrollIntoView(true)
}
}
document.getElementById("btn_add_row").addEventListener("click", function () {
add_row(
document.getElementById("main_table"), document.getElementById("add_row_div"),
document.getElementById("inp_dot"), document.getElementById("inp_dash"),
document.getElementById("inp_space"), document.getElementById("inp_sep")
)
})
document.getElementById("select_writing_system").addEventListener("change", function () {
window.mct.set_writing_system(this.value || this.options[this.selectedIndex].value)
})
document.getElementById("btn_comments").addEventListener("click", function () {
const container = document.getElementById("comments_container")
container.classList.remove("d-none")
const el_thread = document.createElement("div")
el_thread.setAttribute("id", "disqus_thread")
el_thread.style.all = "initial"
const el_script = document.createElement("script")
el_script.setAttribute("src", "https://morse-code-translator.disqus.com/embed.js")
el_script.setAttribute("data-timestamp", +new Date())
container.appendChild(el_thread)
container.appendChild(el_script)
this.classList.add("d-none")
window.mct.scroll_to(el_thread)
})
document.getElementById("btn_info").addEventListener("click", function () {
document.getElementById("info_div").classList.toggle("d-none")
window.mct.scroll_to(document.getElementById("info_div"))
})
// not used
function escapeHtml(unsafe) {
return unsafe.replaceAll("&", "&").replaceAll("<", "<").replaceAll(
">", ">").replaceAll('"', """).replaceAll("'", "'")
}
if (window.location.hostname === "salif.github.io") {
window.addEventListener("load", function () {
(function (c_, o_, u_, n_, t_, e_, r_) {
e_ = c_.createElement('script'), r_ = c_.getElementsByTagName(o_)[0]; e_.async = 1;
e_.setAttribute(n_, t_); e_.src = u_; r_.parentNode.insertBefore(e_, r_);
})(document, 'script', 'https://gc.zgo.at/count.js', 'data-goatcounter', 'https://sgi.goatcounter.com/count');
})
}
})();
</script>
<script type="module">
import * as morse_code from "./build/dev/javascript/morse_code_translator/morse_code_translator.mjs"
import * as option from "./build/dev/javascript/gleam_stdlib/gleam/option.mjs"
window.mct.characters_list = new option.Some(morse_code.morse_code_list)
window.mct.mc_lang = morse_code.language_latin
// textarea.oninput
window.mct.oninp = function (this_inp, skip_abc) {
// if abc textarea
if (this_inp.str_dot === "abc" && this_inp.str_dash === "") {
// first non abc textarea
const t_inp = window.mct.inputs[0]
const result = morse_code.encode(this_inp.el.value, new morse_code.EncodeOptions(
new option.Some(t_inp.str_dot), new option.Some(t_inp.str_dash),
new option.Some(t_inp.str_sp), new option.Some(t_inp.str_sep),
new option.Some(false), new option.Some(window.mct.mc_lang)),
window.mct.characters_list)
// TODO: improve
if (result.isOk()) {
t_inp.el.value = result["0"]
} else {
window.mct.inputs.forEach(inp => {
inp.el.value = result["0"].msg
})
return
}
// only convert
window.mct.oninp(window.mct.inputs[0], true)
} else {
// skip because abc is input
if (!skip_abc) {
const result = morse_code.decode(
this_inp.el.value, new morse_code.DecodeOptions(
new option.Some(this_inp.str_dot), new option.Some(this_inp.str_dash),
new option.Some(this_inp.str_sp), new option.Some(this_inp.str_sep),
new option.Some(false), new option.Some(window.mct.mc_lang), new option.Some(true)),
window.mct.characters_list)
if (result.isOk()) {
window.mct.input_abc.el.value = result["0"]
} else {
window.mct.input_abc.el.value = result["0"].msg
}
}
window.mct.inputs.forEach(inp => {
// skip input object
if (!(this_inp.str_dot === inp.str_dot && this_inp.str_dash === inp.str_dash &&
this_inp.str_sp === inp.str_sp && this_inp.str_sep === inp.str_sep)) {
const result = morse_code.convert(this_inp.el.value,
new morse_code.ConvertOptions(
this_inp.str_dot, inp.str_dot,
this_inp.str_dash, inp.str_dash,
this_inp.str_sp, inp.str_sp,
this_inp.str_sep, inp.str_sep))
if (result.isOk()) {
inp.el.value = result["0"]
} else {
inp.el.value = result["0"].msg
}
}
})
}
}
window.mct.set_writing_system = function (mc_lang) {
window.mct.mc_lang = new morse_code.Language(mc_lang)
window.mct.oninp(window.mct.inputs[0])
}
// focus first textarea
window.mct.input_abc.el.focus()
</script>
</body>
</html>