forked from DevSankalp1894/swank-meeting-7218
-
Notifications
You must be signed in to change notification settings - Fork 0
/
detail.js
130 lines (113 loc) · 3.66 KB
/
detail.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
import navbar from "./componets/navbar.js";
let nav = document.getElementById("navbar");
nav.innerHTML = navbar();
let data = JSON.parse(localStorage.getItem("Details"));
console.log(data);
//////////////////details appending here////////////////////////////////
const append = (data) => {
let gifdata = document.querySelector("#left_con1");
data.forEach((e) => {
let div = document.createElement("div");
div.setAttribute("class", "news_div");
let title = document.createElement("h2");
title.innerText = e.title;
let description = document.createElement("p");
description.innerText = e.description;
let date = document.createElement("p");
date.innerText = `Published - ${e.publishedAt}`;
let img = document.createElement("img");
img.src = e.urlToImage;
let content = document.createElement("h5");
content.innerText = e.content;
div.append(title, description, date, img, content);
gifdata.append(div);
});
};
append(data);
////////// Right side MOST POPULAR div//////////////////////////
let API = `dcd4020693f1415eabe0cdc3907fc499`;
async function mostPopular() {
try {
let res = await fetch(
`https://newsapi.org/v2/everything?q=athletes&apiKey=${API}`
);
let data = await res.json();
console.log(data.articles);
mostPopular_append(data.articles);
} catch (error) {
console.log("error", error);
}
}
mostPopular();
const mostPopular_append = async (data) => {
let gifdata = document.querySelector("#right_con_div");
data.forEach((e) => {
let div = document.createElement("div");
div.setAttribute("class", "news_div");
let div_text = document.createElement("div");
let img = document.createElement("img");
img.src = e.urlToImage;
img.style.cursor = "pointer";
let title = document.createElement("h4");
title.innerText = e.title;
title.style.cursor = "pointer";
title.addEventListener("click", () => {
let data = [];
data.push(e);
window.location.href = "detail.html";
localStorage.setItem("Details", JSON.stringify(data));
});
img.addEventListener("click", () => {
let data = [];
data.push(e);
window.location.href = "detail.html";
localStorage.setItem("Details", JSON.stringify(data));
});
div_text.append(title);
div.append(div_text, img);
gifdata.append(div);
});
};
// grids below video detail///////////////////////////////////
async function below_details() {
try {
let res = await fetch(
`https://newsapi.org/v2/everything?q=hollywood&apiKey=${API}`
);
let data = await res.json();
console.log(data.articles);
Grid_append(data.articles);
} catch (error) {
console.log("error", error);
}
}
below_details();
const Grid_append = async (data) => {
let gifdata = document.querySelector("#left_con2");
data.forEach((e) => {
let div = document.createElement("div");
div.setAttribute("class", "news_div");
let div_text = document.createElement("div");
let img = document.createElement("img");
img.src = e.urlToImage;
img.style.cursor = "pointer";
let title = document.createElement("h4");
title.innerText = e.title;
title.style.cursor = "pointer";
title.addEventListener("click", () => {
let data = [];
data.push(e);
window.location.href = "detail.html";
localStorage.setItem("Details", JSON.stringify(data));
});
img.addEventListener("click", () => {
let data = [];
data.push(e);
window.location.href = "detail.html";
localStorage.setItem("Details", JSON.stringify(data));
});
div_text.append(title);
div.append(div_text, img);
gifdata.append(div);
});
};