-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
155 lines (127 loc) · 5.05 KB
/
app.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
const openIposElement = document.querySelector(".openIPO-cards");
const emptyIpo = document.querySelector(".empty-ipo");
const closingTodayEle = document.querySelector("#closingToday");
const upcomingIposElement = document.querySelector(".upcomingIPO-cards");
const emptyUpcoming = document.querySelector(".empty-upcoming");
const companyName = document.querySelector(".company-name");
const openingDateElement = document.querySelector(".open-date");
const closingDateElement = document.querySelector(".close-date");
const issueDesc = document.querySelector(".issue-desc");
const loadingContainer = document.querySelector("#loading");
const displayLoading = () => {
document.querySelector(".container").style.visibility = "hidden";
loadingContainer.style.display = "block";
};
const hideLoading = () => {
loadingContainer.style.display = "none";
document.querySelector(".container").style.visibility = "visible";
};
const url = "https://www.onlinekhabar.com/smtm/home/ipo-corner-upcoming";
const today = new Date();
const fetchData = async () => {
displayLoading();
const req = await fetch(url);
const data = await req.json();
checkOpen(data.message);
hideLoading();
};
const checkOpen = (arr) => {
const closingToday = arr.filter((ipo) => {
return (
new Date(ipo.close_date).toLocaleDateString() ==
today.toLocaleDateString()
);
});
if (closingToday.length > 0) {
let closingTitle = document.createElement("h2");
closingTitle.innerHTML = "Issues Closing Today";
closingTodayEle.appendChild(closingTitle);
closingToday.map((ipo) => {
let closingToday = document.createElement("div");
closingToday.classList.add("closingToday");
let name = document.createElement("h3");
name.innerHTML = `${ipo.company_name} (${ipo.ticker})`;
closingToday.appendChild(name);
let description = document.createElement("p");
description.innerHTML = `<strong>Description: </strong> ${ipo.details}`;
closingToday.appendChild(description);
let openDate = document.createElement("p");
openDate.innerHTML = `<strong>Open Date: </strong> ${new Date(
ipo.openDate
).toDateString()}`;
closingToday.appendChild(openDate);
document.body.appendChild(closingToday);
let closeDate = document.createElement("p");
closeDate.innerHTML = `<strong>Close Date:</strong> ${new Date(
ipo.close_date
).toDateString()}`;
closingToday.appendChild(closeDate);
closingTodayEle.appendChild(closingToday);
});
}
const upcomingIPOs = arr.filter((item) => {
let openDate = new Date(item.open_date);
let closeDate = new Date(item.closeDate);
return closeDate > today && openDate > today;
});
if (upcomingIPOs.length < 1) {
upcomingIposElement.style.display = "none";
emptyUpcoming.innerHTML = "No Upcoming IPOs/FPOs at the moment.";
} else {
upcomingIPOs.map((ipo) => {
let ipoCard = document.createElement("div");
ipoCard.classList.add("open");
let name = document.createElement("h3");
name.innerHTML = `${ipo.company_name} (${ipo.ticker})`;
ipoCard.appendChild(name);
let description = document.createElement("p");
description.innerHTML = `<strong>Description: </strong> ${ipo.details}`;
ipoCard.appendChild(description);
let openDate = document.createElement("p");
openDate.innerHTML = `<strong>Open Date: </strong> ${new Date(
ipo.openDate
).toDateString()}`;
ipoCard.appendChild(openDate);
document.body.appendChild(ipoCard);
let closeDate = document.createElement("p");
closeDate.innerHTML = `<strong>Close Date:</strong> ${new Date(
ipo.close_date
).toDateString()}`;
ipoCard.appendChild(closeDate);
upcomingIposElement.appendChild(ipoCard);
});
}
const openIPOs = arr.filter((item) => {
let openDate = new Date(item.openDate);
let closeDate = new Date(item.closeDate);
return openDate <= today && closeDate >= today;
});
if (openIPOs.length < 1) {
openIposElement.style.display = "none";
emptyIpo.innerHTML = "No Open IPOs/FPOs at the moment.";
} else {
openIPOs.map((ipo) => {
let ipoCard = document.createElement("div");
ipoCard.classList.add("open");
let name = document.createElement("h3");
name.innerHTML = `${ipo.company_name} (${ipo.ticker})`;
ipoCard.appendChild(name);
let description = document.createElement("p");
description.innerHTML = `<strong>Description: </strong> ${ipo.details}`;
ipoCard.appendChild(description);
let openDate = document.createElement("p");
openDate.innerHTML = `<strong>Open Date: </strong> ${new Date(
ipo.openDate
).toDateString()}`;
ipoCard.appendChild(openDate);
document.body.appendChild(ipoCard);
let closeDate = document.createElement("p");
closeDate.innerHTML = `<strong>Close Date:</strong> ${new Date(
ipo.close_date
).toDateString()}`;
ipoCard.appendChild(closeDate);
openIposElement.appendChild(ipoCard);
});
}
};
fetchData();