-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
153 lines (146 loc) · 3.67 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
<!DOCTYPE html>
<html>
<head>
<title>Encode text</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<link href="https://fonts.googleapis.com/css2?family=Josefin+Sans:ital,wght@1,500&display=swap" rel="stylesheet">
</head>
<body background="images/image.jpg">
<div>
<h1>Text to Morse code</h1>
</br>
<textarea id="text" cols="50" rows="6"></textarea>
</br>
<textarea id="morse" cols="50" rows="6"></textarea>
</br>
<button onclick="encode()">Encode</button>
</br>
<a href="decode.html">Decode morse code to plain text</a>
</div>
<script>
const encode = () => {
// morseEncode function
const morseEncode = (e) => {
switch (e) {
case '0' :
return "-----";
case '1' :
return ".----";
case '2' :
return "..---";
case '3' :
return "...--";
case '4' :
return "....-";
case '5' :
return ".....";
case '6' :
return "-....";
case '7' :
return "--...";
case '8' :
return "---..";
case '9' :
return "----.";
break;
case 'a': case 'A' :
return ".-";
break;
case 'b': case 'B' :
return "-...";
break;
case 'c': case 'C' :
return "-.-.";
case 'd': case 'D' :
return "-..";
break;
case 'e': case 'E' :
return ".";
break;
case 'f': case 'F' :
return "..-.";
break;
case 'g': case 'G' :
return "--.";
break;
case 'h': case 'H' :
return "....";
break;
case 'i': case 'I' :
return "..";
break;
case 'j': case 'J' :
return ".---";
break;
case 'k': case 'K' :
return "-.-";
break;
case 'l': case 'L' :
return ".-..";
break;
case 'm': case 'M' :
return "--";
break;
case 'n': case 'N' :
return "-.";
break;
case 'o': case 'O' :
return "---";
break;
case 'p': case 'P' :
return ".--.";
break;
case 'q': case 'Q' :
return "--.-";
break;
case 'r': case 'R' :
return ".-.";
break;
case 's': case 'S' :
return "...";
break;
case 't': case 'T' :
return "-";
break;
case 'u': case 'U' :
return "..-";
break;
case 'v': case 'V' :
return "...-";
break;
case 'w': case 'W' :
return ".--";
break;
case 'x': case 'X' :
return "-..-";
break;
case 'y': case 'Y' :
return "-.--";
break;
// for space
case ' ' :
return " ";
break;
case 'z': case 'Z' :
return "--..";
case '!' :
return "-.-.--";
case '.' :
return ".-.-.-";
case ',' :
return "--..--";
}
}
let holder = document.getElementById("morse");
// print function for print output in textarea
const print = (data) => {
for(i = 0; data[i]; i++) {
holder.innerHTML += morseEncode(data[i]) + " ";
}
}
let input = document.getElementById('text').value;
print(input);
}
</script>
</body>
</html>