-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrockets.html
135 lines (128 loc) · 4.07 KB
/
rockets.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vandenberg SFB Launches</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
background-color: #f5f5f5;
display: flex;
flex-direction: column;
align-items: center;
}
.container {
flex: 1;
margin: 10px;
}
.result {
background-color: #fff;
padding: 15px;
margin: 10px 0;
border: 1px solid #ddd;
border-radius: 5px;
}
.highlight {
background-color: #ffffe0; /* Light yellow */
}
.results-wrapper {
display: flex;
width: 100%;
max-width: 1200px;
}
h1 {
text-align: center;
}
</style>
</head>
<body>
<h1>Vandenberg SFB Launches</h1>
<div class="results-wrapper">
<div class="container" id="previous-launches">
<h2>Previous Launches</h2>
<div id="previous-results-container"></div>
</div>
<div class="container" id="upcoming-launches">
<h2>Upcoming Launches</h2>
<div id="upcoming-results-container"></div>
</div>
</div>
<script>
function formatDate(dateString) {
const options = {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
hour12: false,
};
return new Date(dateString)
.toLocaleString("en-GB", options)
.replace(",", "");
}
async function fetchAndDisplayResults(
url,
containerId,
sortOrder,
isUpcoming
) {
try {
const response = await fetch(url);
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.detail);
}
const data = await response.json();
const sortedResults = data.results.sort((a, b) => {
const dateA = new Date(a.net);
const dateB = new Date(b.net);
return sortOrder === "desc" ? dateB - dateA : dateA - dateB;
});
const resultsContainer = document.getElementById(containerId);
const currentDate = new Date();
sortedResults.forEach((result) => {
const resultDate = new Date(result.net);
const timeDifference = Math.abs(currentDate - resultDate);
const dayDifference = timeDifference / (1000 * 3600 * 24);
const resultDiv = document.createElement("div");
resultDiv.className = "result";
if (dayDifference <= 3) {
resultDiv.classList.add("highlight");
}
resultDiv.innerHTML = `
<strong>Name:</strong> ${result.name}<br>
<strong>Date:</strong> ${formatDate(result.net)}<br>
${
isUpcoming
? `<strong>Window End:</strong> ${formatDate(
result.window_end
)}`
: `<strong>Status:</strong> ${result.status.name}`
}`;
resultsContainer.appendChild(resultDiv);
});
} catch (error) {
const resultsContainer = document.getElementById(containerId);
resultsContainer.innerHTML = `<div class="result">${error.message}</div>`;
}
}
// Fetch and display previous launches (sorted by 'net' descending)
fetchAndDisplayResults(
"https://ll.thespacedevs.com/2.2.0/launch/previous/?location__ids=11",
"previous-results-container",
"desc",
false
);
// Fetch and display upcoming launches (sorted by 'net' ascending)
fetchAndDisplayResults(
"https://ll.thespacedevs.com/2.2.0/launch/upcoming/?location__ids=11",
"upcoming-results-container",
"asc",
true
);
</script>
</body>
</html>