-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathepisodes.html
83 lines (73 loc) · 3.24 KB
/
episodes.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Episodes</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-gray-900 text-white">
<div class="container mx-auto py-8">
<h5 class="text-lg font-bold mb-4">Episodes</h5>
<div id="episodes-container" class="space-y-4">
<!-- Episodes will be dynamically inserted here -->
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const episodesContainer = document.getElementById('episodes-container');
const urlParams = new URLSearchParams(window.location.search);
const id = urlParams.get('id');
function fetchEpisodes() {
episodesContainer.innerHTML = ''; // Clear the container before fetching new data
const loader = document.createElement('div');
loader.classList.add('loader');
episodesContainer.appendChild(loader);
const apiUrl = `https://api-p1xr.vercel.app/api/v1/episode/${id}`; // Construct the API URL
console.log(apiUrl); // Log the full API URL to the console
fetch(apiUrl)
.then(response => response.json())
.then(data => {
loader.remove();
data.episodes.forEach(episode => {
const episodeCard = document.createElement('div');
episodeCard.classList.add('flex', 'bg-gray-800', 'rounded-lg', 'overflow-hidden', 'p-4');
episodeCard.innerHTML = `
<a href="watch.html?id=${episode.id}" class="block w-full">
<div>
<h2 class="text-lg font-bold">${episode.title}</h2>
<p class="text-gray-400">Episode ID: ${episode.id}</p>
</div>
</a>
`;
episodesContainer.appendChild(episodeCard);
});
})
.catch(error => {
console.error('Error fetching data:', error);
loader.remove();
episodesContainer.innerHTML = '<p class="text-white">Failed to load episodes. Please try again later.</p>';
});
}
fetchEpisodes(); // Initial fetch
});
</script>
<style>
/* Loading spinner styling */
.loader {
border: 4px solid #f3f3f3;
border-top: 4px solid #3498db;
border-radius: 50%;
width: 40px;
height: 40px;
background-color: #333; /* Updated background color */
animation: spin 1s linear infinite;
margin: auto;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
</style>
</body>
</html>