-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathschedule.html
208 lines (174 loc) · 7.44 KB
/
schedule.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Anime Daily Schedule </title>
<script src="https://cdn.tailwindcss.com"></script>
<style>
body {
background-color: #333;
color: #fff;
}
.underline {
height: 3px;
background-color: #f39c12;
width: 100%;
position: absolute;
bottom: 0;
left: 0;
transform: scaleX(0);
transform-origin: left;
transition: transform 0.3s ease-in-out;
}
.day-selector.active .underline {
transform: scaleX(1);
}
.day-selector {
position: relative;
cursor: pointer;
flex: 0 0 auto;
padding: 0 10px;
}
.day-selector.active {
font-weight: bold;
color: #f39c12;
}
/* Hide scrollbar for Webkit browsers */
.scrollable-days::-webkit-scrollbar {
display: none;
}
/* Hide scrollbar for IE, Edge and Firefox */
.scrollable-days {
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}
</style>
</head>
<body class="font-sans antialiased">
<div class="container mx-auto py-8">
<h1 class="text-4xl font-bold text-center mb-8">Anime Daily Schedule </h1>
<!-- Days of the Week Selector -->
<div class="scrollable-days flex justify-start space-x-6 mb-8 overflow-x-auto">
<div class="day-selector" data-day="sunday">
Sunday
<div class="underline"></div>
</div>
<div class="day-selector" data-day="monday">
Monday
<div class="underline"></div>
</div>
<div class="day-selector" data-day="tuesday">
Tuesday
<div class="underline"></div>
</div>
<div class="day-selector" data-day="wednesday">
Wednesday
<div class="underline"></div>
</div>
<div class="day-selector" data-day="thursday">
Thursday
<div class="underline"></div>
</div>
<div class="day-selector" data-day="friday">
Friday
<div class="underline"></div>
</div>
<div class="day-selector" data-day="saturday">
Saturday
<div class="underline"></div>
</div>
</div>
<!-- Schedule Grid -->
<div id="schedule" class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-8">
<!-- TV shows will be dynamically inserted here -->
</div>
</div>
<script>
async function fetchSchedule(day = 'monday') {
try {
const response = await fetch(`https://api.jikan.moe/v4/schedules?filter=${day}`);
const data = await response.json();
// Process and sort shows by local time
const processedShows = data.data.map(show => {
const localTime = convertToLocalTime(show.broadcast.string);
return { ...show, localTime };
});
processedShows.sort((a, b) => a.localTime.date - b.localTime.date);
displaySchedule(processedShows);
} catch (error) {
console.error('Error fetching data:', error);
}
}
// Function to convert JST time to the user's local time
function convertToLocalTime(broadcastString) {
const timeRegex = /(\d{2}:\d{2})/;
const match = broadcastString.match(timeRegex);
if (match) {
const timeInJST = match[0];
const [hours, minutes] = timeInJST.split(':');
// Create a date object for the time in JST
const jstDate = new Date();
jstDate.setUTCHours(parseInt(hours) - 9); // JST is UTC+9
jstDate.setUTCMinutes(parseInt(minutes));
// Convert to local time
const localDate = new Date(jstDate.toLocaleString("en-US", { timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone }));
// Format the local time
const localTimeString = localDate.toLocaleTimeString([], {
hour: '2-digit',
minute: '2-digit',
hour12: false,
timeZoneName: 'short'
});
return { time: localTimeString, date: localDate };
}
return { time: broadcastString, date: null };
}
// Function to display the sorted schedule
function displaySchedule(shows) {
const scheduleContainer = document.getElementById('schedule');
scheduleContainer.innerHTML = ''; // Clear previous content
shows.forEach(show => {
const showElement = document.createElement('div');
showElement.classList.add('bg-gray-800', 'p-4', 'rounded-lg', 'shadow-lg', 'hover:scale-105', 'transition-transform', 'duration-300');
showElement.innerHTML = `
<img src="${show.images.jpg.image_url}" alt="${show.title}" class="w-full h-48 object-cover rounded-lg mb-4">
<h2 class="text-xl font-semibold text-white">${show.titles[0].title}</h2>
<p class="text-gray-400">Airs on: ${show.localTime.time}</p>
<a href="${show.url}" target="_blank" class="text-yellow-500 hover:underline mt-2 inline-block">More Info</a>
`;
scheduleContainer.appendChild(showElement);
});
}
// Function to handle day selection
function handleDaySelection(event) {
const selectedDay = event.target.getAttribute('data-day');
// Remove active class from all day selectors
document.querySelectorAll('.day-selector').forEach(selector => {
selector.classList.remove('active');
});
// Add active class to the selected day
event.target.classList.add('active');
// Fetch and display the schedule for the selected day
fetchSchedule(selectedDay);
}
// Function to get the current day as a string
function getCurrentDay() {
const daysOfWeek = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
const currentDayIndex = new Date().getDay(); // 0 for Sunday, 1 for Monday, etc.
return daysOfWeek[currentDayIndex];
}
document.addEventListener('DOMContentLoaded', () => {
const currentDay = getCurrentDay();
// Find the corresponding day selector and trigger a click event
const currentDaySelector = document.querySelector(`.day-selector[data-day="${currentDay}"]`);
currentDaySelector.classList.add('active'); // Set the active class
fetchSchedule(currentDay);
});
// Event listeners for day selectors
document.querySelectorAll('.day-selector').forEach(selector => {
selector.addEventListener('click', handleDaySelection);
});
</script>
</body>
</html>