-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
47 lines (42 loc) · 1.46 KB
/
script.js
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
function playSound(button) {
const soundFile = button.dataset.sound;
const audio = new Audio(soundFile);
audio.play();
}
document.addEventListener('DOMContentLoaded', () => {
fetch('dictionary.json')
.then(response => response.json())
.then(data => {
const sortedWords = sortDictionary(data.words);
displayDictionary(sortedWords);
})
.catch(error => console.error('Error fetching dictionary:', error));
});
const specialOrder = "AaBbCcĈĉGgSsНнІiŢţØøKkЬьРрŘřХхУуŸÿÑñШшДδЕеΩωЫыQqЖжΨψMmПпƏəΛλΣςΞΞ";
function sortDictionary(words) {
return words.sort((a, b) => {
return customCompare(a.word, b.word);
});
}
function customCompare(word1, word2) {
const length = Math.min(word1.length, word2.length);
for (let i = 0; i < length; i++) {
const index1 = specialOrder.indexOf(word1[i]);
const index2 = specialOrder.indexOf(word2[i]);
if (index1 !== index2) {
return index1 - index2;
}
}
return word1.length - word2.length;
}
function displayDictionary(words) {
const dictionaryDiv = document.getElementById('dictionary');
words.forEach(entry => {
const wordElement = document.createElement('div');
wordElement.innerHTML = `
<div class="word-translate">${entry.word} (eng: ${entry.translate})</div>
<div class="definition">${entry.definition}</div>
`;
dictionaryDiv.appendChild(wordElement);
});
}