-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
149 lines (132 loc) · 3.79 KB
/
script.js
File metadata and controls
149 lines (132 loc) · 3.79 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
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
const alphabets = {
en: {
'A': 'Alpha',
'B': 'Bravo',
'C': 'Charlie',
'D': 'Delta',
'E': 'Echo',
'F': 'Foxtrot',
'G': 'Golf',
'H': 'Hotel',
'I': 'India',
'J': 'Juliet',
'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'
},
es: {
'A': 'Alicante',
'B': 'Barcelona',
'C': 'Cádiz',
'D': 'Dinamarca',
'E': 'España',
'F': 'Francia',
'G': 'Granada',
'H': 'Huelva',
'I': 'Italia',
'J': 'Jaén',
'K': 'Kilo',
'L': 'León',
'M': 'Madrid',
'N': 'Navarra',
'O': 'Oviedo',
'P': 'Pamplona',
'Q': 'Queso',
'R': 'Roma',
'S': 'Sevilla',
'T': 'Tarragona',
'U': 'Uva',
'V': 'Valencia',
'W': 'Washington',
'X': 'Xilófono',
'Y': 'Yeso',
'Z': 'Zaragoza'
}
};
const translations = {
en: {
title: 'NATO Speller',
placeholder: 'Type a word or phrase...',
asIn: 'as in',
notInAlphabet: '(not in NATO alphabet)'
},
es: {
title: 'Alfabeto Fonético',
placeholder: 'Escribe una palabra o frase...',
asIn: 'como en',
notInAlphabet: '(no está en el alfabeto fonético)'
}
};
let currentLang = 'en';
function spellWord(word) {
const output = document.getElementById('output');
output.innerHTML = '';
if (word.trim() === '') {
return;
}
const table = document.createElement('table');
table.className = 'output-table';
const letters = word.toUpperCase().split('');
letters.forEach(letter => {
const alphabet = alphabets[currentLang];
const row = document.createElement('tr');
if (alphabet[letter]) {
row.innerHTML = `
<td class="letter-col"><strong>${letter}</strong></td>
<td class="as-in-col"><span class="as-in">${translations[currentLang].asIn}</span></td>
<td class="word-col">${alphabet[letter]}</td>
`;
} else if (letter === ' ') {
row.innerHTML = '<td colspan="3"> </td>';
} else {
row.innerHTML = `
<td class="letter-col"><strong>${letter}</strong></td>
<td colspan="2" class="as-in-col"><span class="as-in">${translations[currentLang].notInAlphabet}</span></td>
`;
}
table.appendChild(row);
});
output.appendChild(table);
}
function updateUI() {
document.querySelector('h1').textContent = translations[currentLang].title;
document.getElementById('textInput').placeholder = translations[currentLang].placeholder;
// Update flag states
document.querySelectorAll('.flag').forEach(flag => {
flag.classList.toggle('active', flag.dataset.lang === currentLang);
});
// Re-spell current word
const currentWord = document.getElementById('textInput').value;
if (currentWord) {
spellWord(currentWord);
}
}
function switchLanguage(lang) {
currentLang = lang;
updateUI();
}
document.getElementById('textInput').addEventListener('input', function() {
spellWord(this.value);
});
// Add click handlers for language flags
document.querySelectorAll('.flag').forEach(flag => {
flag.addEventListener('click', function() {
switchLanguage(this.dataset.lang);
});
});
// Initialize
updateUI();
document.getElementById('textInput').focus();