-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscience.js
272 lines (205 loc) · 8.81 KB
/
science.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
269
270
271
272
let rain = document.getElementsByClassName("bad")[0];
let dev = screen.width;
rain.innerHTML = `<h2 class="bad">
Catergory : <span class="badge badge-secondary">Science</span>
</h2>`
let para = document.getElementsByClassName('card')[0];
let card = document.createElement('div');
var coun = "in";
if (sessionStorage.getItem("cont") == "America") {
coun = "us";
} else if (sessionStorage.getItem("cont") == "India") {
coun = "in";
} else if (sessionStorage.getItem("cont") == "Argentina") {
coun = "ar";
} else if (sessionStorage.getItem("cont") == "Autralia") {
coun = "au";
} else if (sessionStorage.getItem("cont") == "Austria") {
coun = "at";
} else if (sessionStorage.getItem("cont") == "Belgium") {
coun = "be";
} else if (sessionStorage.getItem("cont") == "Brazil") {
coun = "br";
} else if (sessionStorage.getItem("cont") == "Bulgaria") {
coun = "bg";
} else if (sessionStorage.getItem("cont") == "Canada") {
coun = "ca";
} else if (sessionStorage.getItem("cont") == "China") {
coun = "cn"
} else if (sessionStorage.getItem("cont") == "Colombia") {
coun = "co";
} else if (sessionStorage.getItem("cont") == "Cuba") {
coun = "cu";
} else if (sessionStorage.getItem("cont") == "Czech Republic") {
coun = "cz";
} else if (sessionStorage.getItem("cont") == "Egypt") {
coun = "eg"
} else if (sessionStorage.getItem("cont") == "France") {
coun = "fr";
} else if (sessionStorage.getItem("cont") == "Germany") {
coun = "de";
} else if (sessionStorage.getItem("cont") == "Greece") {
coun = "gr";
} else if (sessionStorage.getItem("cont") == "Hong Kong") {
coun = "hk";
} else if (sessionStorage.getItem("cont") == "Hungary") {
coun = "hu";
} else if (sessionStorage.getItem("cont") == "Indonesia") {
coun = "id";
} else if (sessionStorage.getItem("cont") == "Ireland") {
coun = "ie";
} else if (sessionStorage.getItem("cont") == "Israel") {
coun = "il";
} else if (sessionStorage.getItem("cont") == "Italy") {
coun = "it";
} else if (sessionStorage.getItem("cont") == "Japan") {
coun = "jp";
} else if (sessionStorage.getItem("cont") == "Latvia") {
coun = "lv";
} else if (sessionStorage.getItem("cont") == "Lithuania") {
coun = "lt";
} else if (sessionStorage.getItem("cont") == "Malaysia") {
coun = "my";
} else if (sessionStorage.getItem("cont") == "Morocco") {
coun = "ma";
} else if (sessionStorage.getItem("cont") == "Netherland") {
coun = "nl";
} else if (sessionStorage.getItem("cont") == "New Zealand") {
coun = "nz";
} else if (sessionStorage.getItem("cont") == "Nigera") {
coun = "ng";
} else if (sessionStorage.getItem("cont") == "Norway") {
coun = "no";
} else if (sessionStorage.getItem("cont") == "Philippiness") {
coun = "ph";
} else if (sessionStorage.getItem("cont") == "Poland") {
coun = "pl";
} else if (sessionStorage.getItem("cont") == "Portugal") {
coun = "pt";
} else if (sessionStorage.getItem("cont") == "Romania") {
coun = "ro";
} else if (sessionStorage.getItem("cont") == "Russia") {
coun = "ru";
} else if (sessionStorage.getItem("cont") == "Saudi Arabia") {
coun = "sa";
} else if (sessionStorage.getItem("cont") == "Serbia") {
coun = "rs";
} else if (sessionStorage.getItem("cont") == "Singapore") {
coun = "sg";
} else if (sessionStorage.getItem("cont") == "Slovakia") {
coun = "si";
} else if (sessionStorage.getItem("cont") == "Slovenia") {
coun = "si";
} else if (sessionStorage.getItem("cont") == "South Africa") {
coun = "za";
} else if (sessionStorage.getItem("cont") == "South Korea") {
coun = "kr";
} else if (sessionStorage.getItem("cont") == "Sweden") {
coun = "se";
} else if (sessionStorage.getItem("cont") == "Switzerland") {
coun = "ch";
} else if (sessionStorage.getItem("cont") == "Taiwan") {
coun = "tw";
} else if (sessionStorage.getItem("cont") == "Thailand") {
coun = "th";
} else if (sessionStorage.getItem("cont") == "Turkey") {
coun = "tr";
} else if (sessionStorage.getItem("cont") == "UAE") {
coun = "ae";
} else if (sessionStorage.getItem("cont") == "Ukraine") {
coun = "ua";
} else if (sessionStorage.getItem("cont") == "United Kingdom") {
coun = "gb";
} else if (sessionStorage.getItem("cont") == "Venuzuela") {
coun = "ve";
} else {
coun = "in";
}
let par = document.getElementsByClassName("main")[0];
let api = "a9b14d5f5d3448558fafd022dc27043f";
let chi = document.createElement("div");
chi.setAttribute("class", "cad");
let xhr = new XMLHttpRequest();
xhr.open(
"GET",
`https://cors-anywhere.herokuapp.com/http://newsapi.org/v2/top-headlines?country=${coun}&category=science&apiKey=${api}`,
true
);
// This is Main Append Java Script
xhr.send();
let str = ``;
xhr.onreadystatechange = function() {
if (this.readyState == 4 && xhr.status == 200) {
let no = JSON.parse(this.responseText).articles.length;
for (let i = 0; i <= no - 1; i++) {
let na = JSON.parse(this.responseText).articles[i].name;
let rain = document.getElementsByClassName("rain")[0].children[0]
.innerText;
rain.innerText = `News Served By: ${na}`;
let auth = JSON.parse(this.responseText).articles[i].author;
let cont = JSON.parse(this.responseText).articles[i].title;
let desc = JSON.parse(this.responseText).articles[i].description;
let dat = JSON.parse(this.responseText).articles[0].publishedAt.slice(
0,
10
);
let iur = JSON.parse(this.responseText).articles[i].urlToImage;
let ur = JSON.parse(this.responseText).articles[i].url;
let news = ``;
if (dev < 400) {
news = `<div class="accordion" id="accordionExample"></div>
<div class="card" style="width: auto;">
<img src=${iur} class="card-img-top" alt="Fail To Load">
<div class="card-header" id="heading${i}">
<h2 class="mb-0">
<button class="btn btn-link btn-block text-left collapsed" type="button" data-toggle="collapse" data-target="#collapse${i}" aria-expanded="false" aria-controls="collapse${i}">
<strong>Breaking News ${i + 1} : </strong>
<br/>
<span>${cont}</span>
<br />
Publised At : ${dat}
</button>
</h2>
<a href="${ur}" class="btn btn-primary my-2" target="_blank">Go To Site</a>
</div>
<div id="collapse${i}" class="collapse" aria-labelledby="heading${i}" data-parent="#accordionExample">
<div class="card-body">
${desc}
</div>
</div>
</div>`
} else {
news = `<div class="card my-2">
<div class="card-header" id="heading${i}">
<div class="container">
<div class="row">
<div class="col" style="padding-right: 0px;">
<img src=${iur} alt="Fail To Load" class="img-thumbnail" style="height: 150px; width: 150%;" />
</div>
<div class="col-8">
<button class="btn btn-link collapsed text-sm-left" style="text-align:left" type="button" data-toggle="collapse" data-target="#collapse${i}" aria-expanded="false" aria-controls="collapse${i}" }>
<strong>Breaking News ${i + 1} : </strong>
<br/>
<span>${cont}</span>
<br />
Publised At : ${dat}
</button>
</div>
</div>
</div>
</div>
<div id="collapse${i}" class="collapse" aria-labelledby="heading${i}" data-parent="#accordionExample">
<div class="card-body">
${desc}
<br />
<a href="${ur}" target="_blank">Read More</a>
</div>
</div>
</div>`;
}
str = str + news;
chi.innerHTML = `${str}`;
par.appendChild(chi);
}
}
};