-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
153 lines (138 loc) Β· 5.47 KB
/
script.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
const wrapper = document.querySelector('.wrapper');
const h1 = document.querySelector('h1');
const p = document.querySelector('p');
const a = document.querySelector('a');
const button = document.querySelector('button');
alert('Proqram test merhelesindedir. Duzgun netice ucucn axtaris yerine max 1 ingilisce soz yazmaginiz teklif olunur. Proqram avtomatik xeberleri yenileyir.')
fetch('https://content.guardianapis.com/search?page=4&page-size=5&api-key=23be7ca1-3c45-4363-9d2f-9cc3d423b183')
.then((res) => res.json())
.then((data) => {
data.response.results.forEach((obj) => {
wrapper.innerHTML += `
<div class="news-card">
<h1>${obj.webTitle}</h1>
<div class="inline">
<p>${obj.sectionName}</p>
<a target="_blank" href=${obj.webUrl}>Direct Link π</a>
</div>
</div>`
})
})
// fetch('https://content.guardianapis.com/search?q=nature&api-key=23be7ca1-3c45-4363-9d2f-9cc3d423b183')
// .then((res) => res.json())
// .then((data) => {
// console.log(data.response.results)
// })
let pageNumber = 5
// const loadSomeNews = () => {
// const NEWS_URL = `https://content.guardianapis.com/search?page=${pageNumber}&page-size=5&api-key=23be7ca1-3c45-4363-9d2f-9cc3d423b183`;
// fetch(NEWS_URL)
// .then(res => res.json())
// .then((data) => {
// data.response.results.forEach((obj) => {
// wrapper.innerHTML += `
// <div class="news-card">
// <h1>${obj.webTitle}</h1>
// <div class="inline">
// <p>${obj.sectionName}</p>
// <a target="_blank" href=${obj.webUrl}>Direct Link π</a>
// </div>
// </div>`
// pageNumber++;
// })
// })
// }
// button.addEventListener('click', () => {
// pageNumber++;
// loadSomeNews();
// })
const searchBtn = document.querySelector('.search-icon')
const searchQuest = document.querySelector('.search')
// const questSearch = () => {
// const NEWS_URL = `https://content.guardianapis.com/search?q=${searchQuest}&page=${pageNumber}&page-size=5&api-key=23be7ca1-3c45-4363-9d2f-9cc3d423b183`;
// fetch(NEWS_URL)
// .then(res => res.json())
// .then((data) => {
// data.response.results.forEach((obj) => {
// wrapper.innerHTML += `
// <div class="news-card">
// <h1>${obj.webTitle}</h1>
// <div class="inline">
// <p>${obj.sectionName}</p>
// <a target="_blank" href=${obj.webUrl}>Direct Link π</a>
// </div>
// </div>`
// pageNumber++;
// })
// })
// }
searchBtn.addEventListener('click', () => {
console.log(searchQuest.value)
const questSearch = () => {
const NEWS_URL = `https://content.guardianapis.com/search?q=${searchQuest.value}&page=${pageNumber}&page-size=5&api-key=23be7ca1-3c45-4363-9d2f-9cc3d423b183`;
fetch(NEWS_URL)
.then(res => res.json())
.then((data) => {
data.response.results.forEach((obj) => {
wrapper.innerHTML += `
<div class="news-card">
<h1>${obj.webTitle}</h1>
<div class="inline">
<p>${obj.sectionName}</p>
<a target="_blank" href=${obj.webUrl}>Direct Link π</a>
</div>
</div>`
// pageNumber++;
})
})
.catch((err) => {
return err.message;
})
}
// const loadSomeQuestNews = () => {
// const NEWS_URL = `https://content.guardianapis.com/search?q=${searchQuest.value}&page=${pageNumber = 23}&page-size=5&api-key=23be7ca1-3c45-4363-9d2f-9cc3d423b183`;
// fetch(NEWS_URL)
// .then(res => res.json())
// .then((data) => {
// data.response.results.forEach((obj) => {
// wrapper.innerHTML += `
// <div class="news-card">
// <h1>${obj.webTitle}</h1>
// <div class="inline">
// <p>${obj.sectionName}</p>
// <a target="_blank" href=${obj.webUrl}>Direct Link π</a>
// </div>
// </div>`
// pageNumber++;
// })
// })
// }
questSearch();
// button.addEventListener('click',()=>{
// loadSomeQuestNews();
// pageNumber++;
// })
pageNumber++
})
const loadSomeQuestNews = () => {
const NEWS_URL = `https://content.guardianapis.com/search?q=${searchQuest.value}&page=${pageNumber}&page-size=5&api-key=23be7ca1-3c45-4363-9d2f-9cc3d423b183`;
fetch(NEWS_URL)
.then(res => res.json())
.then((data) => {
data.response.results.forEach((obj) => {
wrapper.innerHTML += `
<div class="news-card">
<h1>${obj.webTitle}</h1>
<div class="inline">
<p>${obj.sectionName}</p>
<a target="_blank" href=${obj.webUrl}>Direct Link π</a>
</div>
</div>`
pageNumber++;
})
})
}
button.addEventListener('click', () => {
loadSomeQuestNews();
pageNumber++;
})