-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDOM - NATO spell selection.js
More file actions
68 lines (68 loc) · 1.29 KB
/
DOM - NATO spell selection.js
File metadata and controls
68 lines (68 loc) · 1.29 KB
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
let selection;
const h = {
0: "Zero",
1: "One",
2: "Two",
3: "Three",
4: "Four",
5: "Five",
6: "Six",
7: "Seven",
8: "Eight",
9: "Nine",
A: "Alpha",
B: "Bravo",
C: "Charlie",
D: "Delta",
E: "Echo",
F: "Foxtrot",
G: "Golf",
H: "Hotel",
I: "India",
J: "Juliett",
K: "Kilo",
L: "Lima",
M: "Mike",
N: "November",
O: "Oscar",
P: "Papa",
Q: "Quebec",
R: "Romeo",
S: "Sierra",
T: "Tango",
U: "Uniform",
V: "Victor",
W: "Whiskey",
X: "X-ray",
Y: "Yankee",
Z: "Zulu",
};
if (window.getSelection) {
selection = window.getSelection().toString();
} else if (document.selection && document.selection.type !== "Control") {
selection = document.selection.createRange().text;
}
if (selection === undefined || selection.length === 0) {
window.alert("Select the desired text.");
} else {
selection = selection.trim();
let result = "";
let i, c, d, t;
for (i = 0; i < selection.length; i += 1) {
c = selection.charAt(i);
d = encodeURIComponent(c);
if (d === c) {
d = h[c];
}
if (d === undefined) {
t = h[c.toUpperCase()];
if (t === undefined) {
d = `%${c.codePointAt(0).toString(16).toUpperCase()}`;
} else {
d = t.toLowerCase();
}
}
result += `${d} `;
}
window.alert(result);
}