File size: 4,768 Bytes
e593efa 1287df7 e593efa 1287df7 e593efa f28f280 e593efa 1287df7 f28f280 e593efa f28f280 e593efa f28f280 1287df7 e593efa 1287df7 f28f280 e593efa 1287df7 | 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 |
document.addEventListener('DOMContentLoaded', () => {
// Add upcoming movies highlight animation
highlightUpcomingMovies();
// Handle search functionality
setupSearch();
// Handle movie card clicks
setupMoviePlayback();
});
function setupMoviePlayback() {
document.addEventListener('click', async (e) => {
const movieCard = e.target.closest('.movie-poster');
if (movieCard) {
const movieId = movieCard.dataset.movieId;
if (movieId) {
try {
// Fetch movie details
const response = await fetch(`https://api.themoviedb.org/3/movie/${movieId}?api_key=8f2b224acadeeebc64ef32b4c04919de&append_to_response=videos`);
const movieData = await response.json();
// Create video player
createVideoPlayer(movieData);
} catch (error) {
console.error('Error fetching movie details:', error);
}
}
}
// Close player when clicking outside
const player = document.querySelector('.video-player');
if (player && !e.target.closest('.video-player') && !e.target.closest('.movie-poster')) {
player.remove();
}
});
}
async function createVideoPlayer(movieData) {
// Remove existing player if any
const existingPlayer = document.querySelector('.video-player');
if (existingPlayer) existingPlayer.remove();
// Show loading state
const player = document.createElement('div');
player.className = 'video-player';
player.innerHTML = `
<div class="player-overlay"></div>
<div class="player-content">
<button class="close-player">×</button>
<h3>${movieData.title || movieData.name}</h3>
<p>${movieData.overview}</p>
<div class="loading-spinner">
<div></div><div></div><div></div><div></div>
</div>
<p class="loading-text">Preparing your stream...</p>
</div>
`;
document.body.appendChild(player);
// Fetch streaming URL (simulated)
try {
await new Promise(resolve => setTimeout(resolve, 2000)); // Simulate loading
// Find trailer video
const trailer = movieData.videos?.results?.find(v => v.type === 'Trailer');
const videoUrl = trailer
? `https://www.youtube.com/embed/${trailer.key}?autoplay=1`
: '';
player.innerHTML = `
<div class="player-overlay"></div>
<div class="player-content">
<button class="close-player">×</button>
<h3>${movieData.title || movieData.name}</h3>
<p>${movieData.overview}</p>
${videoUrl ? `
<iframe
width="100%"
height="500"
src="${videoUrl}"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen>
</iframe>
` : '<p>No trailer available</p>'}
<div class="stream-options">
<button class="quality-btn active">HD</button>
<button class="quality-btn">Full HD</button>
<button class="quality-btn">4K</button>
</div>
</div>
`;
document.body.appendChild(player);
// Close button event
player.querySelector('.close-player').addEventListener('click', () => {
player.remove();
});
}
function highlightUpcomingMovies() {
// Find all upcoming movie cards and add pulse animation
setTimeout(() => {
const upcomingRows = document.querySelectorAll('movie-row[title="Upcoming Movies"]');
upcomingRows.forEach(row => {
const cards = row.shadowRoot.querySelectorAll('.movie-card');
if (cards.length > 0) {
// Highlight the first 3 upcoming movies
for (let i = 0; i < Math.min(3, cards.length); i++) {
cards[i].classList.add('upcoming-highlight');
}
}
});
}, 1000); // Wait for movies to load
}
function setupSearch() {
// This would be connected to the navbar search functionality
document.addEventListener('keypress', (e) => {
if (e.target.classList.contains('search-input') && e.key === 'Enter') {
const query = e.target.value.trim();
if (query) {
console.log(`Searching for: ${query}`);
// Here you would typically redirect to search results or fetch them
// window.location.href = `/search.html?q=${encodeURIComponent(query)}`;
}
}
});
}
// Handle theme toggle
document.addEventListener('themeToggle', (e) => {
document.body.classList.toggle('dark');
localStorage.setItem('theme', document.body.classList.contains('dark') ? 'dark' : 'light');
});
// Check for saved theme preference
if (localStorage.getItem('theme') === 'dark') {
document.body.classList.add('dark');
} else if (localStorage.getItem('theme') === 'light') {
document.body.classList.add('light');
} |