-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
136 lines (78 loc) · 3.22 KB
/
app.js
File metadata and controls
136 lines (78 loc) · 3.22 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
const apiUrl="https://api.dictionaryapi.dev/api/v2/entries/en/";
const input=document.querySelector(".search");
const search=document.querySelector(".glass");
const ul=document.querySelector(".ul");
const ul2=document.querySelector(".secondul");
search.addEventListener('click',()=>{
let word=input.value;
dictionary(word);
document.querySelector(".ul").innerHTML=" ";
ul2.innerHTML=" ";
document.querySelector(".secondpof").style.display="none";
})
//Triggering Enter Button...
input.addEventListener("keypress",(event)=>{
if(event.key==="Enter"){
search.click();
}
})
const container=document.querySelector(".container");
const body= document.querySelector(".body");
const toggle=document.querySelector(".slider");
toggle.addEventListener('click',()=>{
container.classList.toggle("container-darkk");
body.classList.toggle("dark");
input.classList.toggle("dark-searchbar");
// console.log(container.classList);
// document.querySelector(".fa-toggle-on").classList.toggle("fa-toggle-off");
})
async function dictionary(word){
let data;
const response=await fetch(apiUrl+word);
if(response.status==404){
data=await response.json();
console.log(data);
document.getElementById("word").innerHTML=data.title;
document.querySelector(".sorry").style.display="block";
document.querySelector(".pos1").innerHTML="";
document.querySelector(".secondpof").style.display="none";
}
data=await response.json();
document.querySelector(".sorry").style.display="none";
console.log(data);
document.querySelector(".pos1").innerHTML=data[0].meanings[0].partOfSpeech;
document.getElementById("word").innerHTML=data[0].word;
const array1=data[0].meanings[0].definitions;
for(element in array1){
if(element>=4){
break;
}else{
let li = document.createElement("li");
let node = document.createTextNode(array1[element].definition);
li.appendChild(node);
ul.appendChild(li);
}
}
document.querySelector(".audio").addEventListener('click',()=>{
let text= new SpeechSynthesisUtterance(document.getElementById("word").innerHTML);
speechSynthesis.speak(text);
})
if(data[0].meanings.length>1){
document.querySelector(".secondpof").style.display="block";
document.querySelector(".pos2").innerHTML=data[0].meanings[1].partOfSpeech;
const array2=data[0].meanings[1].definitions;
for(element in array2){
if(element>=2){
break;
}else{
let li = document.createElement("li");
let node = document.createTextNode(array2[element].definition);
li.appendChild(node);
ul2.appendChild(li);
}
}
}
}
// document.querySelector(".s2").innerHTML=data[0].meanings[0].synonyms;
// document.querySelector(".pos1").innerHTML=data[0].meanings[0].partOfSpeech;
// document.querySelector(".pos2").innerHTML=data[0].meanings[1].partOfSpeech;