-
Notifications
You must be signed in to change notification settings - Fork 32
/
script1.js
73 lines (69 loc) · 2.1 KB
/
script1.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
var titles;
var body;
var text,dark,light;
var islight = 1;
function toggle (){
if(islight===1){
DarkMode();
islight = 0;
}
else{
lightMode();
islight = 1;
}
}
function DarkMode(){
light.style.display = 'none';
dark.style.display = 'block';
console.log(body);
titles.forEach(item => {
item.style.backgroundColor = "rgb(24, 26, 27)";
item.style.color = 'rgb(194, 189, 181)';
});
body.style.backgroundColor = 'rgb(30, 32, 33)';
text.forEach(item=>{
item.style.color = 'azure';
})
// document.getElementsByClassName('toggler-button').style.boxShadow=''
}
function lightMode(){
light.style.display = 'block';
dark.style.display = 'none';
console.log(body);
titles.forEach(item => {
item.style.backgroundColor = "azure";
item.style.color = 'rgb(24, 26, 27)';
});
body.style.backgroundColor = 'azure';
text.forEach(item=>{
item.style.color = 'rgb(24, 26, 27)';
})
}
async function getworld_news() {
dark = document.querySelector('.dark');
light = document.querySelector('.light');
dark.style.display = 'none';
let response2 = await fetch(
"https://gnews.io/api/v4/top-headlines?token=a175ac9bf19a19e7e95f50136ebffcbb&lang=en"
// "https://gnews.io/api/v4/top-headlines?token=a175ac9bf19a19e7e95f50136ebffcbb&country=" +
// 'india' +
// "&lang=" +
// 'english'
);
let data2 = await response2.json();
// console.log(data2);
for (var i = 0; i < data2.articles.length; i++) {
document.getElementById(
"world_news"
).innerHTML += `<a href='${data2.articles[i].url}'>
<div class='img darker'>
<img src=${data2.articles[i].image}>
<p class='title'>${data2.articles[i].title}</p>
</div>
</a>`;
}
body = document.querySelector('body');
titles = document.querySelectorAll(".darker");
text = document.querySelectorAll('.text');
}
getworld_news();