-
Notifications
You must be signed in to change notification settings - Fork 1
/
education.js
268 lines (216 loc) · 7.03 KB
/
education.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
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
// e1d001bb4e184ec5b1cabd0da5447752
import { navbar } from "./components/navbar.js";
document.getElementById("navbar").innerHTML = navbar();
import { newsSlider } from "./components/navbar.js";
document.getElementById("news_slider").innerHTML = newsSlider();
import { sidebar } from "./components/navbar.js";
document.getElementById("sidebar").innerHTML = sidebar();
import { rightSidebar } from "./components/navbar.js";
document.getElementById("right_sidebar").innerHTML = rightSidebar();
import { footer } from "./components/navbar.js";
document.getElementById("footer").innerHTML = footer();
let query = document.getElementById("query");
query.disabled = true;
let searchbtn = document.getElementById("SearchButton");
searchbtn.disabled = true;
searchbtn.style.backgroundColor = "#ffde2f";
searchbtn.style.border = "none";
searchbtn.innerText = "";
// Adding some style and enabling the button and search input
document.querySelector("#searchNews").addEventListener("click", () => {
query.disabled = false;
query.style.backgroundColor = "White";
query.placeholder = "Search News Here";
query.style.padding = "15px";
document.getElementById("SearchButton").style.padding = "12px";
document.querySelector("#searchNews").disabled = true;
searchbtn.innerText = "Search";
searchbtn.disabled = false;
searchbtn.style.border = "black";
searchbtn.style.cursor = "pointer";
});
// adding event to search button to fetch the data from api
let Search = document.getElementById("SearchButton");
Search.addEventListener("click", () => {
SearchNews();
});
// fetching data from api but works only for two keyWords "tesla" and "twitter"
const SearchNews = async () => {
let query = document.getElementById("query").value;
try {
let res = await fetch(`https://masai-api.herokuapp.com/news?q=${query}`);
let data = await res.json();
console.log(data.articles);
displayData(data.articles);
} catch (error) {
console.log(error);
}
};
// Showing Fetch data to container div you can append data to your respective div
const displayData = (data) => {
data.forEach((ele) => {
let container = document.getElementById("details");
let div = document.createElement("div");
let image = document.createElement("img");
image.src = ele.urlToImage;
let title = document.createElement("h4");
title.innerText = ele.title;
div.append(image, title);
container.append(div);
});
};
let poster = [
"Three new credit card rules coming into effect from Oct.",
"Ankita Bhandari murder case to be tried in fast-track court; Uttarakhand CM announces Rs 25 lakh compensation for family",
"Gandhis still keen on Gehlot contesting party prez poll...",
"Amid F-16 strain, US talks of India-Pakistan dialogue",
"Centre bans PFI for 5 years under anti-terror law UAPA ...",
];
let id;
function Start() {
let container = document.getElementById("breaking_news");
let i = 0;
let p = document.createElement("p");
let id = setInterval(function () {
if (i === 5) {
i = 0;
}
p.innerText = poster[i];
container.append(p);
i++;
}, 2000);
}
function Stop() {
clearInterval(id);
}
Start();
const arr = [
{
url: "https://cdn.dnaindia.com/sites/default/files/styles/half/public/2022/09/06/2536435-edu-main.jpg",
title: "From NTA NEET UG 2022 Result to CBSE Compartment Result 2022...",
id: 1,
},
{
url: "https://cdn.dnaindia.com/sites/default/files/styles/half/public/2022/09/05/2536104-teach.jpg",
title:
"Teacher's day: 5 teachers who transformed education scenario in India",
id: 2,
},
{
url: "https://cdn.dnaindia.com/sites/default/files/styles/half/public/2022/09/08/2537096-neet-result.jpg",
title: "Here are 5 courses Biology students can opt for after Class...",
id: 3,
},
{
url: " https://cdn.dnaindia.com/sites/default/files/styles/half/public/2022/08/24/2532826-nirish-rajput-tb.jpg",
title: "Meet IAS officer Nirish Rajput, who sold newspapers, studied...",
id: 4,
},
{
url: "https://cdn.dnaindia.com/sites/default/files/styles/half/public/2022/08/21/2531871-students-4-1.jpg",
title: "Are you a college student? These 5 part-time...",
id: 5,
},
];
const slideShow = () => {
let count = 0;
let div = document.getElementById("1");
let img = document.createElement("img");
img.src = arr[0].url;
let p = document.createElement("p");
p.innerText = arr[0].title;
div.onclick = function () {
window.location.href = "./photo.html";
};
div.append(img, p);
count = count + 1;
setInterval(function () {
if (count == 4) {
count = 0;
}
img.src = arr[count].url;
p.innerText = arr[count].title;
count++;
div.append(img, p);
}, 4000);
};
slideShow();
const slideShow2 = () => {
let count = 1;
let div = document.getElementById("2");
let img = document.createElement("img");
img.src = arr[1].url;
let p = document.createElement("p");
p.innerText = arr[1].title;
div.append(img, p);
count = count + 1;
setInterval(function () {
if (count == 5) {
count = 1;
}
img.src = arr[count].url;
p.innerText = arr[count].title;
count++;
div.append(img, p);
}, 4000);
};
slideShow2();
const videos = [
{
url: "https://cdn.dnaindia.com/sites/default/files/styles/half/public/2022/09/20/2540227-20thumbnail1801486.jpeg",
title:
"Delhi University Entrance Test (DUET) to be held in second week of October, watch for more details",
},
{
url: "https://cdn.dnaindia.com/sites/default/files/styles/half/public/2022/09/13/2538333-13thumbnail1801314.jpeg",
title:
"DU Admissions 2022 starts via CUET: Know DU’s new admission process",
link: "https://www.dnaindia.com/india/video-dna-russia-announces-absorption-of-4-occupied-ukrainian-regions-2989384",
},
{
url: "https://cdn.dnaindia.com/sites/default/files/styles/half/public/2022/09/10/2537437-10thumbnail1801266.jpg",
title:
"DNA | What is IAMC? Know how its spreading propaganda against India",
link: "https://www.dnaindia.com/india/video-dna-what-is-iamc-know-how-its-spreading-propaganda-against-india-2989382",
},
];
const slideShow3 = () => {
let count = 0;
let div = document.getElementById("3");
let img = document.createElement("img");
img.src = videos[0].url;
let p = document.createElement("p");
p.innerText = videos[0].title;
div.append(img, p);
count = count + 1;
setInterval(function () {
if (count == 1) {
count = 0;
}
img.src = videos[count].url;
p.innerText = videos[count].title;
count++;
div.append(img, p);
}, 4000);
};
slideShow3();
const slideShow4 = () => {
let count = 1;
let div = document.getElementById("4");
let img = document.createElement("img");
img.src = videos[1].url;
let p = document.createElement("p");
p.innerText = videos[1].title;
div.append(img, p);
count = count + 1;
setInterval(function () {
if (count == 2) {
count = 1;
}
img.src = videos[count].url;
p.innerText = videos[count].title;
count++;
div.append(img, p);
}, 4000);
};
slideShow4();