Repository navigation
Expand file tree
/
Copy pathdictionary.html
More file actions
180 lines (149 loc) · 4.89 KB
/
Copy pathdictionary.html
File metadata and controls
180 lines (149 loc) · 4.89 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>English Dictionary</title>
<link rel="stylesheet" href="dictionarystyle.css">
<style>
* {
margin: -1px;
padding: 0;
box-sizing: border-box;
font-family: sans-serif
}
body {
min-height: 100vh;
max-width: 100%;
justify-content: center;
align-items: center;
}
nav ul li {
display: inline;
width: 100%;
margin: 0px 0px;
padding: 0px 0px;
line-height: 60px;
font-weight: bold;
justify-items: center;
align-items: center;
display: fixed;
}
nav ul li a {
text-decoration: none;
color: none;
background-color: none;
width: 100%;
/* display: fixed; */
}
.container {
background-color: rgb(88, 37, 82);
padding: 28px;
border-radius: 7px;
box-shadow: 0 10px 10px rgba(0, 0, 0, .3);
width: 100%;
margin: 10px;
max-width: 400px;
text-align: center;
justify-content: center;
font-size: 18px;
font-weight: 500;
}
.heading {
font-size: 28px;
}
.input {
height: 53px;
width: 250px;
background-color: rgba(255, 255, 255, .6);
border-color: rgba(255, 255, 255, .4);
font-size: 16px;
padding: 0 42px;
border-radius: 5px;
}
.meaning-container {
display: none;
}
</style>
</head>
<body bgcolor="#f5f5f5">
<nav>
<!-- <input type="checkbox" id="check"> -->
<!-- <label for="check" class="checkbtn">
<i class="fas fa-bars"></i>
</label> -->
<ul>
<li class="home"><a href="./index.html">Home</a></li>
<li class="dictionary"><a href="./dictionary.html">Dictionary</a></li>
<li class="texttovoice"><a href="./texttovoice.html">Text to Voice</a></li>
<li class="definition"><a href="./definition.html">Definition</a></li>
<li class="singularplural"><a href="./singularplural.html">Singular Plural</a></li>
<li class="login"><a href="./login.html">Login</a></li>
<li class="signup"><a href="./signup.html">Sign Up</a></li>
<li class="contactus"><a href="./contactus.html">Contact Us</a></li>
</ul>
</nav>
<center><br><br><br><br>
<h1>Dictionary</h1>
<br><br><br><br>
<div class="container">
<h1 class="heading"> Dictionary in English </h1>
<br>
<input placeholder="Search a word" type="text" class="input" id="input" />
<br><br>
<p class="info-text" id="info-text">Type a word and press enter</p>
<br>
<div class="meaning-container" id="meaning-container">
<p>Word Title: <span class="title" id="title">___</span></p>
<p>Meaning: <span class="meaning" id="meaning">___</span></p>
<audio src="" controls id="audio"></audio>
</div>
</div>
<br><br><br>
<hr>
<div class="footer">
<br>
<center><h4>© 2024 DW Gadgets. All rights reserved.</h4>
<br>
<script>
const inputEl = document.getElementById("input");
const infoTextEl = document.getElementById("info-text");
const meaningContainerEl = document.getElementById("meaning-container");
const titleEl = document.getElementById("title");
const meaningEl = document.getElementById("meaning");
const audioEl = document.getElementById("audio");
async function fetchAPI(word) {
try {
infoTextEl.style.display = "block";
meaningContainerEl.style.display = "none";
infoTextEl.innerText = `Searching the meaning of "${word}"`;
const url = `https://api.dictionaryapi.dev/api/v2/entries/en/${word}`;
const result = await fetch(url).then((res) => res.json());
if (result.title) {
meaningContainerEl.style.display = "block";
infoTextEl.style.display = "none";
titleEl.innerText = word;
meaningEl.innerText = "N/A";
audioEl.style.display = "none";
} else {
infoTextEl.style.display = "none";
meaningContainerEl.style.display = "block";
audioEl.style.display = "inline-flex";
titleEl.innerText = result[0].word;
meaningEl.innerText = result[0].meanings[0].definitions[0].definition;
audioEl.src = result[0].phonetics[0].audio;
}
} catch (error) {
console.log(error);
infoTextEl.innerText = `an error happened, try again later`;
}
}
inputEl.addEventListener("keyup", (e) => {
if (e.target.value && e.key === "Enter") {
fetchAPI(e.target.value);
}
});
</script>
</body>
</html>