-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmorse.html
151 lines (143 loc) · 5.17 KB
/
morse.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Morse Module - Keep Talking</title>
</head>
<body>
<h3>Morse</h3>
<input type="text" id="txtCode"><br>
<span id="out"></span>
<script>
var ALL_CHARS_MUST_BE_IN_SEQUENCE = false; // weather or not to match the order of chars
var txtCode = document.getElementById("txtCode");
var out = document.getElementById("out")
txtCode.addEventListener("keyup", codeUpdate);
function codeUpdate(e) {
var code = txtCode.value;
var letter = "";
var word = "";
for (var i = 0; i < code.length; i++) {
var c = code.charAt(i);
if (c != "." && c != "-" && c != " ") {
word += c;
} else {
if (c == " ") {
var letterChar = codeToLetter(letter);
if (letterChar != undefined) {
word += letterChar;
}
letter = "";
} else {
letter += c;
}
}
}
var letterChar = codeToLetter(letter);
if (letterChar != undefined) {
word += letterChar;
}
letter = "";
out.innerText = "Word: " + word + "\n Frequencies:\n";
var matchWord = word;
var lastChar = code.charAt(code.length - 1);
if (lastChar == "." || lastChar == "-") {
matchWord = matchWord.substr(0, matchWord.length - 1)
}
for (w in freq) {
var lettersInWord = true;
var charSeqInWord = true;
var wordPos = -2;
for (var i = 0; i < matchWord.length; i++) {
var nextPos = w.indexOf(matchWord.charAt(i), nextPos+1);
if (nextPos < 0) {
nextPos = w.indexOf(matchWord.charAt(i));
}
if (nextPos < 0) {
lettersInWord = false;
}
if (wordPos == -2) {
wordPos = nextPos;
} else {
if (nextPos == ((wordPos + 1) % w.length)) {
wordPos = nextPos;
} else {
wordPos = -1;
charSeqInWord = false;
}
}
}
if (ALL_CHARS_MUST_BE_IN_SEQUENCE) {
if (charSeqInWord) {
out.innerText += "\t" + w + ": " + freq[w] + "\n";
}
} else {
if (lettersInWord) {
out.innerText += "\t" + w + ": " + freq[w] + "\n";
}
}
}
}
function codeToLetter(code) {
switch (code) {
case ".-": return "a";
case "-...": return "b";
case "-.-.": return "c";
case "-..": return "d";
case ".": return "e";
case "..-.": return "f";
case "--.": return "g";
case "....": return "h";
case "..": return "i";
case ".---": return "j";
case "-.-": return "k";
case ".-..": return "l";
case "--": return "m";
case "-.": return "n";
case "---": return "o";
case ".--.": return "p";
case "--.-": return "q";
case ".-.": return "r";
case "...": return "s";
case "-": return "t";
case "..-": return "u";
case "...-": return "v";
case ".--": return "w";
case "-..-": return "x";
case "-.--": return "y";
case "--..": return "z";
case "-----": return "0";
case ".----": return "1";
case "..---": return "2";
case "...--": return "3";
case "....-": return "4";
case ".....": return "5";
case "-....": return "6";
case "--...": return "7";
case "---..": return "8";
case "----.": return "9";
}
}
var freq = {
"shell": "3.505MHz",
"halls": "3.515MHz",
"slick": "3.522MHz",
"trick": "3.532MHz",
"boxes": "3.535MHz",
"leaks": "3.542MHz",
"strobe": "3.545MHz",
"bistro": "3.552MHz",
"flick": "3.555MHz",
"bombs": "3.565MHz",
"break": "3.572MHz",
"brick": "3.575MHz",
"steak": "3.582MHz",
"sting": "3.592MHz",
"vector": "3.595MHz",
"beats": "3.600MHz"
}
</script>
</body>
</html>