From 83a8e1634235aad0d4967d226e38608c9eb5e248 Mon Sep 17 00:00:00 2001 From: Son Nguyen Date: Wed, 13 Nov 2024 22:20:11 -0500 Subject: [PATCH 1/2] Final: Enhanced app frontend --- MovieVerse-Frontend/css/style.css | 1 - MovieVerse-Frontend/js/favorites.js | 244 ++--- .../assets/www/MovieVerse-Frontend/README.md | 2 +- .../www/MovieVerse-Frontend/css/style.css | 1 - .../www/MovieVerse-Frontend/js/favorites.js | 244 ++--- .../app/src/main/assets/www/index.html | 30 +- .../android/app/src/main/assets/www/index.js | 869 ++++++++---------- .../app/src/main/assets/www/sitemap.xml | 62 +- .../ios/www/MovieVerse-Frontend/css/style.css | 1 - .../www/MovieVerse-Frontend/js/favorites.js | 244 ++--- .../platforms/ios/www/index.html | 30 +- MovieVerse-Mobile/platforms/ios/www/index.js | 869 ++++++++---------- .../platforms/ios/www/sitemap.xml | 62 +- .../www/MovieVerse-Frontend/css/style.css | 1 - .../www/MovieVerse-Frontend/js/favorites.js | 244 ++--- MovieVerse-Mobile/www/index.html | 30 +- MovieVerse-Mobile/www/index.js | 869 ++++++++---------- MovieVerse-Mobile/www/sitemap.xml | 62 +- index.js | 869 ++++++++---------- sitemap.xml | 54 +- 20 files changed, 1928 insertions(+), 2860 deletions(-) diff --git a/MovieVerse-Frontend/css/style.css b/MovieVerse-Frontend/css/style.css index d6261880..f2377a4f 100644 --- a/MovieVerse-Frontend/css/style.css +++ b/MovieVerse-Frontend/css/style.css @@ -1928,7 +1928,6 @@ strong { } #favorite-btn:hover::after { - content: 'Favorite / Unfavorite'; position: absolute; top: -45px; left: 50%; diff --git a/MovieVerse-Frontend/js/favorites.js b/MovieVerse-Frontend/js/favorites.js index d3841f0a..6e4206e5 100644 --- a/MovieVerse-Frontend/js/favorites.js +++ b/MovieVerse-Frontend/js/favorites.js @@ -1369,18 +1369,19 @@ function getClassByRate(vote) { const searchForm = document.getElementById('form'); -searchForm.addEventListener('submit', e => { - e.preventDefault(); - const searchQuery = document.getElementById('search').value; - localStorage.setItem('searchQuery', searchQuery); - window.location.href = 'search.html'; -}); +// searchForm.addEventListener('submit', e => { +// e.preventDefault(); +// const searchQuery = document.getElementById('search').value; +// localStorage.setItem('searchQuery', searchQuery); +// window.location.href = 'search.html'; +// }); function handleSearch() { const searchQuery = document.getElementById('search').value; localStorage.setItem('searchQuery', searchQuery); window.location.href = 'search.html'; } + async function loadWatchLists() { const displaySection = document.getElementById('watchlists-display-section'); @@ -1391,17 +1392,23 @@ async function loadWatchLists() { let watchlists = []; if (currentUserEmail) { - const cachedWatchlists = JSON.parse(localStorage.getItem('cachedWatchlists_' + currentUserEmail)) || []; - if (cachedWatchlists.length > 0) { - watchlists = cachedWatchlists; - } else { + try { + // Attempt to fetch from Firebase first const q = query(collection(db, 'watchlists'), where('userEmail', '==', currentUserEmail)); const querySnapshot = await getDocs(q); watchlists = querySnapshot.docs.map(doc => ({ id: doc.id, ...doc.data(), })); + + // Cache the results if successful localStorage.setItem('cachedWatchlists_' + currentUserEmail, JSON.stringify(watchlists)); + } catch (firebaseError) { + console.warn('Firebase fetch failed, loading from cache:', firebaseError); + + // If Firebase fails, load from cache + const cachedWatchlists = JSON.parse(localStorage.getItem('cachedWatchlists_' + currentUserEmail)) || []; + watchlists = cachedWatchlists; } if (watchlists.length === 0) { @@ -1414,8 +1421,11 @@ async function loadWatchLists() { e.preventDefault(); document.getElementById('watchlist-header').scrollIntoView({ behavior: 'smooth' }); }); + + // Sort by order and pinned status watchlists.sort((a, b) => a.order - b.order); watchlists.sort((a, b) => (b.pinned === a.pinned ? 0 : b.pinned ? 1 : -1)); + for (const watchlist of watchlists) { const watchlistDiv = await createWatchListDiv(watchlist); if (watchlist.pinned) { @@ -1425,6 +1435,7 @@ async function loadWatchLists() { } } } else { + // Handle the case where there is no signed-in user (local watchlists) let localWatchlists = JSON.parse(localStorage.getItem('localWatchlists')) || []; if (localWatchlists.length === 0) { displaySection.innerHTML = '

No watch lists found. Start by adding movies to your watchlist.

'; @@ -1445,193 +1456,80 @@ async function loadWatchLists() { let favorites = []; let favoritesTVSeries = []; + // Load favorites and favoritesTVSeries, first attempting from Firebase and then cache if needed if (currentUserEmail) { - const cachedFavorites = JSON.parse(localStorage.getItem('cachedFavorites_' + currentUserEmail)) || {}; - favorites = cachedFavorites.favorites || []; - favoritesTVSeries = cachedFavorites.favoritesTVSeries || []; - - if (favorites.length === 0 || favoritesTVSeries.length === 0) { + try { + // Attempt to fetch favorites from Firebase const usersRef = query(collection(db, 'MovieVerseUsers'), where('email', '==', currentUserEmail)); const userSnapshot = await getDocs(usersRef); if (!userSnapshot.empty) { const userData = userSnapshot.docs[0].data(); favorites = userData.favoritesMovies || []; favoritesTVSeries = userData.favoritesTVSeries || []; + + // Cache the results if successful localStorage.setItem('cachedFavorites_' + currentUserEmail, JSON.stringify({ favorites, favoritesTVSeries })); } + } catch (firebaseError) { + console.warn('Firebase favorites fetch failed, loading from cache:', firebaseError); + + // If Firebase fails, load from cache + const cachedFavorites = JSON.parse(localStorage.getItem('cachedFavorites_' + currentUserEmail)) || {}; + favorites = cachedFavorites.favorites || []; + favoritesTVSeries = cachedFavorites.favoritesTVSeries || []; } } else { favorites = JSON.parse(localStorage.getItem('moviesFavorited')) || []; favoritesTVSeries = JSON.parse(localStorage.getItem('favoritesTVSeries')) || []; } - if (favorites.length > 0) { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-movies'; - - const title = document.createElement('h3'); - title.textContent = 'Favorite Movies'; - title.className = 'watchlist-title'; - title.style.cursor = 'pointer'; - title.addEventListener('click', () => { - favoritesDiv.scrollIntoView({ behavior: 'smooth' }); - }); - - const description = document.createElement('p'); - description.textContent = 'A collection of your favorite movies.'; - description.className = 'watchlist-description'; - - favoritesDiv.appendChild(title); - favoritesDiv.appendChild(description); - - const moviesContainer = document.createElement('div'); - moviesContainer.className = 'movies-container'; - - const movieCards = await Promise.all(favorites.map(fetchMovieDetails)); - movieCards.forEach(movieCard => moviesContainer.appendChild(movieCard)); - - favoritesDiv.appendChild(moviesContainer); - displaySection.appendChild(favoritesDiv); - } else { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-movies'; - favoritesDiv.innerHTML = - '

Favorite Movies

No favorite movies added yet.

'; - displaySection.appendChild(favoritesDiv); - } - - if (favoritesTVSeries.length > 0) { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-tv-series'; - - const title = document.createElement('h3'); - title.textContent = 'Favorite TV Series'; - title.className = 'watchlist-title'; - title.style.cursor = 'pointer'; - title.addEventListener('click', () => { - favoritesDiv.scrollIntoView({ behavior: 'smooth' }); - }); - - const description = document.createElement('p'); - description.textContent = 'A collection of your favorite TV series.'; - description.className = 'watchlist-description'; - - favoritesDiv.appendChild(title); - favoritesDiv.appendChild(description); - - const moviesContainer = document.createElement('div'); - moviesContainer.className = 'movies-container'; - - const tvSeriesCards = await Promise.all(favoritesTVSeries.map(fetchTVSeriesDetails)); - tvSeriesCards.forEach(tvSeriesCard => moviesContainer.appendChild(tvSeriesCard)); - - favoritesDiv.appendChild(moviesContainer); - displaySection.appendChild(favoritesDiv); - } else { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-tv-series'; - favoritesDiv.innerHTML = - '

Favorite TV Series

No favorite TV series added yet.

'; - displaySection.appendChild(favoritesDiv); - } + // Display Favorites Movies and TV Series sections + displayFavoritesSection('Favorite Movies', favorites, displaySection); + displayFavoritesSection('Favorite TV Series', favoritesTVSeries, displaySection); hideSpinner(); } catch (error) { - if (error.code === 'resource-exhausted') { - let localWatchlists = JSON.parse(localStorage.getItem('localWatchlists')) || []; - if (localWatchlists.length === 0) { - displaySection.innerHTML = '

No watch lists found. Start by adding movies to your watchlist.

'; - } else { - displaySection.innerHTML = ''; - displaySection.innerHTML += '

Your Watch Lists

'; - localWatchlists.sort((a, b) => (b.pinned === a.pinned ? 0 : b.pinned ? 1 : -1)); - for (const watchlist of localWatchlists) { - const watchlistDiv = await createWatchListDiv(watchlist); - if (watchlist.pinned) { - watchlistDiv.classList.add('pinned'); - } - displaySection.appendChild(watchlistDiv); - } - } - - let favorites = JSON.parse(localStorage.getItem('moviesFavorited')) || []; - let favoritesTVSeries = JSON.parse(localStorage.getItem('favoritesTVSeries')) || []; - - if (favorites.length > 0) { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-movies'; - - const title = document.createElement('h3'); - title.textContent = 'Favorite Movies'; - title.className = 'watchlist-title'; - - const description = document.createElement('p'); - description.textContent = 'A collection of your favorite movies.'; - description.className = 'watchlist-description'; - - favoritesDiv.appendChild(title); - favoritesDiv.appendChild(description); - - const moviesContainer = document.createElement('div'); - moviesContainer.className = 'movies-container'; - - const movieCards = await Promise.all(favorites.map(fetchMovieDetails)); - movieCards.forEach(movieCard => moviesContainer.appendChild(movieCard)); - - favoritesDiv.appendChild(moviesContainer); - displaySection.appendChild(favoritesDiv); - } else { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-movies'; - favoritesDiv.innerHTML = - '

Favorite Movies

No favorite movies added yet.

'; - displaySection.appendChild(favoritesDiv); - } - - if (favoritesTVSeries.length > 0) { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-tv-series'; + console.error('An unexpected error occurred:', error); + hideSpinner(); + } +} - const title = document.createElement('h3'); - title.textContent = 'Favorite TV Series'; - title.className = 'watchlist-title'; +// Helper function to display favorite movies/TV series sections +async function displayFavoritesSection(titleText, items, displaySection) { + if (items.length > 0) { + const favoritesDiv = document.createElement('div'); + favoritesDiv.className = 'watchlist'; + favoritesDiv.id = titleText.toLowerCase().replace(' ', '-'); + + const title = document.createElement('h3'); + title.textContent = titleText; + title.className = 'watchlist-title'; + title.style.cursor = 'pointer'; + title.addEventListener('click', () => { + favoritesDiv.scrollIntoView({ behavior: 'smooth' }); + }); - const description = document.createElement('p'); - description.textContent = 'A collection of your favorite TV series.'; - description.className = 'watchlist-description'; + const description = document.createElement('p'); + description.textContent = `A collection of your ${titleText.toLowerCase()}.`; + description.className = 'watchlist-description'; - favoritesDiv.appendChild(title); - favoritesDiv.appendChild(description); + favoritesDiv.appendChild(title); + favoritesDiv.appendChild(description); - const moviesContainer = document.createElement('div'); - moviesContainer.className = 'movies-container'; + const container = document.createElement('div'); + container.className = 'movies-container'; - const tvSeriesCards = await Promise.all(favoritesTVSeries.map(fetchTVSeriesDetails)); - tvSeriesCards.forEach(tvSeriesCard => moviesContainer.appendChild(tvSeriesCard)); + const cards = await Promise.all(items.map(titleText === 'Favorite Movies' ? fetchMovieDetails : fetchTVSeriesDetails)); + cards.forEach(card => container.appendChild(card)); - favoritesDiv.appendChild(moviesContainer); - displaySection.appendChild(favoritesDiv); - hideSpinner(); - } else { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-tv-series'; - favoritesDiv.innerHTML = - '

Favorite TV Series

No favorite TV series added yet.

'; - displaySection.appendChild(favoritesDiv); - hideSpinner(); - } - } else { - console.error('An error occurred:', error); - hideSpinner(); - } + favoritesDiv.appendChild(container); + displaySection.appendChild(favoritesDiv); + } else { + const favoritesDiv = document.createElement('div'); + favoritesDiv.className = 'watchlist'; + favoritesDiv.id = titleText.toLowerCase().replace(' ', '-'); + favoritesDiv.innerHTML = `

${titleText}

No ${titleText.toLowerCase()} added yet.

`; + displaySection.appendChild(favoritesDiv); } } diff --git a/MovieVerse-Mobile/platforms/android/app/src/main/assets/www/MovieVerse-Frontend/README.md b/MovieVerse-Mobile/platforms/android/app/src/main/assets/www/MovieVerse-Frontend/README.md index 1a216e41..0fcbf3e5 100644 --- a/MovieVerse-Mobile/platforms/android/app/src/main/assets/www/MovieVerse-Frontend/README.md +++ b/MovieVerse-Mobile/platforms/android/app/src/main/assets/www/MovieVerse-Frontend/README.md @@ -158,7 +158,7 @@ Contributions to MovieVerse are always welcome. Whether it's bug reports, featur ## License -This project is licensed under MIT license. Refer to the `LICENSE` file in each subdirectory for more information. +This project is licensed under CC BY-NC 4.0 license. Refer to the [LICENSE](LICENSE.md) file for more information. --- diff --git a/MovieVerse-Mobile/platforms/android/app/src/main/assets/www/MovieVerse-Frontend/css/style.css b/MovieVerse-Mobile/platforms/android/app/src/main/assets/www/MovieVerse-Frontend/css/style.css index d6261880..f2377a4f 100644 --- a/MovieVerse-Mobile/platforms/android/app/src/main/assets/www/MovieVerse-Frontend/css/style.css +++ b/MovieVerse-Mobile/platforms/android/app/src/main/assets/www/MovieVerse-Frontend/css/style.css @@ -1928,7 +1928,6 @@ strong { } #favorite-btn:hover::after { - content: 'Favorite / Unfavorite'; position: absolute; top: -45px; left: 50%; diff --git a/MovieVerse-Mobile/platforms/android/app/src/main/assets/www/MovieVerse-Frontend/js/favorites.js b/MovieVerse-Mobile/platforms/android/app/src/main/assets/www/MovieVerse-Frontend/js/favorites.js index d3841f0a..6e4206e5 100644 --- a/MovieVerse-Mobile/platforms/android/app/src/main/assets/www/MovieVerse-Frontend/js/favorites.js +++ b/MovieVerse-Mobile/platforms/android/app/src/main/assets/www/MovieVerse-Frontend/js/favorites.js @@ -1369,18 +1369,19 @@ function getClassByRate(vote) { const searchForm = document.getElementById('form'); -searchForm.addEventListener('submit', e => { - e.preventDefault(); - const searchQuery = document.getElementById('search').value; - localStorage.setItem('searchQuery', searchQuery); - window.location.href = 'search.html'; -}); +// searchForm.addEventListener('submit', e => { +// e.preventDefault(); +// const searchQuery = document.getElementById('search').value; +// localStorage.setItem('searchQuery', searchQuery); +// window.location.href = 'search.html'; +// }); function handleSearch() { const searchQuery = document.getElementById('search').value; localStorage.setItem('searchQuery', searchQuery); window.location.href = 'search.html'; } + async function loadWatchLists() { const displaySection = document.getElementById('watchlists-display-section'); @@ -1391,17 +1392,23 @@ async function loadWatchLists() { let watchlists = []; if (currentUserEmail) { - const cachedWatchlists = JSON.parse(localStorage.getItem('cachedWatchlists_' + currentUserEmail)) || []; - if (cachedWatchlists.length > 0) { - watchlists = cachedWatchlists; - } else { + try { + // Attempt to fetch from Firebase first const q = query(collection(db, 'watchlists'), where('userEmail', '==', currentUserEmail)); const querySnapshot = await getDocs(q); watchlists = querySnapshot.docs.map(doc => ({ id: doc.id, ...doc.data(), })); + + // Cache the results if successful localStorage.setItem('cachedWatchlists_' + currentUserEmail, JSON.stringify(watchlists)); + } catch (firebaseError) { + console.warn('Firebase fetch failed, loading from cache:', firebaseError); + + // If Firebase fails, load from cache + const cachedWatchlists = JSON.parse(localStorage.getItem('cachedWatchlists_' + currentUserEmail)) || []; + watchlists = cachedWatchlists; } if (watchlists.length === 0) { @@ -1414,8 +1421,11 @@ async function loadWatchLists() { e.preventDefault(); document.getElementById('watchlist-header').scrollIntoView({ behavior: 'smooth' }); }); + + // Sort by order and pinned status watchlists.sort((a, b) => a.order - b.order); watchlists.sort((a, b) => (b.pinned === a.pinned ? 0 : b.pinned ? 1 : -1)); + for (const watchlist of watchlists) { const watchlistDiv = await createWatchListDiv(watchlist); if (watchlist.pinned) { @@ -1425,6 +1435,7 @@ async function loadWatchLists() { } } } else { + // Handle the case where there is no signed-in user (local watchlists) let localWatchlists = JSON.parse(localStorage.getItem('localWatchlists')) || []; if (localWatchlists.length === 0) { displaySection.innerHTML = '

No watch lists found. Start by adding movies to your watchlist.

'; @@ -1445,193 +1456,80 @@ async function loadWatchLists() { let favorites = []; let favoritesTVSeries = []; + // Load favorites and favoritesTVSeries, first attempting from Firebase and then cache if needed if (currentUserEmail) { - const cachedFavorites = JSON.parse(localStorage.getItem('cachedFavorites_' + currentUserEmail)) || {}; - favorites = cachedFavorites.favorites || []; - favoritesTVSeries = cachedFavorites.favoritesTVSeries || []; - - if (favorites.length === 0 || favoritesTVSeries.length === 0) { + try { + // Attempt to fetch favorites from Firebase const usersRef = query(collection(db, 'MovieVerseUsers'), where('email', '==', currentUserEmail)); const userSnapshot = await getDocs(usersRef); if (!userSnapshot.empty) { const userData = userSnapshot.docs[0].data(); favorites = userData.favoritesMovies || []; favoritesTVSeries = userData.favoritesTVSeries || []; + + // Cache the results if successful localStorage.setItem('cachedFavorites_' + currentUserEmail, JSON.stringify({ favorites, favoritesTVSeries })); } + } catch (firebaseError) { + console.warn('Firebase favorites fetch failed, loading from cache:', firebaseError); + + // If Firebase fails, load from cache + const cachedFavorites = JSON.parse(localStorage.getItem('cachedFavorites_' + currentUserEmail)) || {}; + favorites = cachedFavorites.favorites || []; + favoritesTVSeries = cachedFavorites.favoritesTVSeries || []; } } else { favorites = JSON.parse(localStorage.getItem('moviesFavorited')) || []; favoritesTVSeries = JSON.parse(localStorage.getItem('favoritesTVSeries')) || []; } - if (favorites.length > 0) { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-movies'; - - const title = document.createElement('h3'); - title.textContent = 'Favorite Movies'; - title.className = 'watchlist-title'; - title.style.cursor = 'pointer'; - title.addEventListener('click', () => { - favoritesDiv.scrollIntoView({ behavior: 'smooth' }); - }); - - const description = document.createElement('p'); - description.textContent = 'A collection of your favorite movies.'; - description.className = 'watchlist-description'; - - favoritesDiv.appendChild(title); - favoritesDiv.appendChild(description); - - const moviesContainer = document.createElement('div'); - moviesContainer.className = 'movies-container'; - - const movieCards = await Promise.all(favorites.map(fetchMovieDetails)); - movieCards.forEach(movieCard => moviesContainer.appendChild(movieCard)); - - favoritesDiv.appendChild(moviesContainer); - displaySection.appendChild(favoritesDiv); - } else { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-movies'; - favoritesDiv.innerHTML = - '

Favorite Movies

No favorite movies added yet.

'; - displaySection.appendChild(favoritesDiv); - } - - if (favoritesTVSeries.length > 0) { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-tv-series'; - - const title = document.createElement('h3'); - title.textContent = 'Favorite TV Series'; - title.className = 'watchlist-title'; - title.style.cursor = 'pointer'; - title.addEventListener('click', () => { - favoritesDiv.scrollIntoView({ behavior: 'smooth' }); - }); - - const description = document.createElement('p'); - description.textContent = 'A collection of your favorite TV series.'; - description.className = 'watchlist-description'; - - favoritesDiv.appendChild(title); - favoritesDiv.appendChild(description); - - const moviesContainer = document.createElement('div'); - moviesContainer.className = 'movies-container'; - - const tvSeriesCards = await Promise.all(favoritesTVSeries.map(fetchTVSeriesDetails)); - tvSeriesCards.forEach(tvSeriesCard => moviesContainer.appendChild(tvSeriesCard)); - - favoritesDiv.appendChild(moviesContainer); - displaySection.appendChild(favoritesDiv); - } else { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-tv-series'; - favoritesDiv.innerHTML = - '

Favorite TV Series

No favorite TV series added yet.

'; - displaySection.appendChild(favoritesDiv); - } + // Display Favorites Movies and TV Series sections + displayFavoritesSection('Favorite Movies', favorites, displaySection); + displayFavoritesSection('Favorite TV Series', favoritesTVSeries, displaySection); hideSpinner(); } catch (error) { - if (error.code === 'resource-exhausted') { - let localWatchlists = JSON.parse(localStorage.getItem('localWatchlists')) || []; - if (localWatchlists.length === 0) { - displaySection.innerHTML = '

No watch lists found. Start by adding movies to your watchlist.

'; - } else { - displaySection.innerHTML = ''; - displaySection.innerHTML += '

Your Watch Lists

'; - localWatchlists.sort((a, b) => (b.pinned === a.pinned ? 0 : b.pinned ? 1 : -1)); - for (const watchlist of localWatchlists) { - const watchlistDiv = await createWatchListDiv(watchlist); - if (watchlist.pinned) { - watchlistDiv.classList.add('pinned'); - } - displaySection.appendChild(watchlistDiv); - } - } - - let favorites = JSON.parse(localStorage.getItem('moviesFavorited')) || []; - let favoritesTVSeries = JSON.parse(localStorage.getItem('favoritesTVSeries')) || []; - - if (favorites.length > 0) { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-movies'; - - const title = document.createElement('h3'); - title.textContent = 'Favorite Movies'; - title.className = 'watchlist-title'; - - const description = document.createElement('p'); - description.textContent = 'A collection of your favorite movies.'; - description.className = 'watchlist-description'; - - favoritesDiv.appendChild(title); - favoritesDiv.appendChild(description); - - const moviesContainer = document.createElement('div'); - moviesContainer.className = 'movies-container'; - - const movieCards = await Promise.all(favorites.map(fetchMovieDetails)); - movieCards.forEach(movieCard => moviesContainer.appendChild(movieCard)); - - favoritesDiv.appendChild(moviesContainer); - displaySection.appendChild(favoritesDiv); - } else { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-movies'; - favoritesDiv.innerHTML = - '

Favorite Movies

No favorite movies added yet.

'; - displaySection.appendChild(favoritesDiv); - } - - if (favoritesTVSeries.length > 0) { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-tv-series'; + console.error('An unexpected error occurred:', error); + hideSpinner(); + } +} - const title = document.createElement('h3'); - title.textContent = 'Favorite TV Series'; - title.className = 'watchlist-title'; +// Helper function to display favorite movies/TV series sections +async function displayFavoritesSection(titleText, items, displaySection) { + if (items.length > 0) { + const favoritesDiv = document.createElement('div'); + favoritesDiv.className = 'watchlist'; + favoritesDiv.id = titleText.toLowerCase().replace(' ', '-'); + + const title = document.createElement('h3'); + title.textContent = titleText; + title.className = 'watchlist-title'; + title.style.cursor = 'pointer'; + title.addEventListener('click', () => { + favoritesDiv.scrollIntoView({ behavior: 'smooth' }); + }); - const description = document.createElement('p'); - description.textContent = 'A collection of your favorite TV series.'; - description.className = 'watchlist-description'; + const description = document.createElement('p'); + description.textContent = `A collection of your ${titleText.toLowerCase()}.`; + description.className = 'watchlist-description'; - favoritesDiv.appendChild(title); - favoritesDiv.appendChild(description); + favoritesDiv.appendChild(title); + favoritesDiv.appendChild(description); - const moviesContainer = document.createElement('div'); - moviesContainer.className = 'movies-container'; + const container = document.createElement('div'); + container.className = 'movies-container'; - const tvSeriesCards = await Promise.all(favoritesTVSeries.map(fetchTVSeriesDetails)); - tvSeriesCards.forEach(tvSeriesCard => moviesContainer.appendChild(tvSeriesCard)); + const cards = await Promise.all(items.map(titleText === 'Favorite Movies' ? fetchMovieDetails : fetchTVSeriesDetails)); + cards.forEach(card => container.appendChild(card)); - favoritesDiv.appendChild(moviesContainer); - displaySection.appendChild(favoritesDiv); - hideSpinner(); - } else { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-tv-series'; - favoritesDiv.innerHTML = - '

Favorite TV Series

No favorite TV series added yet.

'; - displaySection.appendChild(favoritesDiv); - hideSpinner(); - } - } else { - console.error('An error occurred:', error); - hideSpinner(); - } + favoritesDiv.appendChild(container); + displaySection.appendChild(favoritesDiv); + } else { + const favoritesDiv = document.createElement('div'); + favoritesDiv.className = 'watchlist'; + favoritesDiv.id = titleText.toLowerCase().replace(' ', '-'); + favoritesDiv.innerHTML = `

${titleText}

No ${titleText.toLowerCase()} added yet.

`; + displaySection.appendChild(favoritesDiv); } } diff --git a/MovieVerse-Mobile/platforms/android/app/src/main/assets/www/index.html b/MovieVerse-Mobile/platforms/android/app/src/main/assets/www/index.html index 16f205ea..74a10688 100644 --- a/MovieVerse-Mobile/platforms/android/app/src/main/assets/www/index.html +++ b/MovieVerse-Mobile/platforms/android/app/src/main/assets/www/index.html @@ -19,7 +19,7 @@ name="keywords" content="movies, movies verse, film guide, directors, actors, movie genres, cinema, film reviews, tv shows, movie verse, moviesverse, movieverse, moviesvers, film, movie, movieverse.in" /> - + @@ -56,7 +56,6 @@ - - diff --git a/MovieVerse-Mobile/platforms/android/app/src/main/assets/www/index.js b/MovieVerse-Mobile/platforms/android/app/src/main/assets/www/index.js index 68445014..f433a1cb 100644 --- a/MovieVerse-Mobile/platforms/android/app/src/main/assets/www/index.js +++ b/MovieVerse-Mobile/platforms/android/app/src/main/assets/www/index.js @@ -1,22 +1,22 @@ -const director_main = document.getElementById("director-spotlight"); -const form = document.getElementById("form"); -const search = document.getElementById("search"); -const searchButton = document.getElementById("button-search"); -const searchTitle = document.getElementById("search-title"); -const otherTitle = document.getElementById("other1"); +const director_main = document.getElementById('director-spotlight'); +const form = document.getElementById('form'); +const search = document.getElementById('search'); +const searchButton = document.getElementById('button-search'); +const searchTitle = document.getElementById('search-title'); +const otherTitle = document.getElementById('other1'); function showSpinner() { - document.getElementById("myModal").classList.add("modal-visible"); + document.getElementById('myModal').classList.add('modal-visible'); } function hideSpinner() { - document.getElementById("myModal").classList.remove("modal-visible"); + document.getElementById('myModal').classList.remove('modal-visible'); } -document.addEventListener("DOMContentLoaded", function () { - const pagination = document.getElementById("most-popular-pagination"); - const genresContainer = document.querySelector(".genres"); - const mainContainer = document.getElementById("most-popular"); +document.addEventListener('DOMContentLoaded', function () { + const pagination = document.getElementById('most-popular-pagination'); + const genresContainer = document.querySelector('.genres'); + const mainContainer = document.getElementById('most-popular'); function movePagination() { if (window.innerWidth <= 767) { @@ -27,16 +27,14 @@ document.addEventListener("DOMContentLoaded", function () { } movePagination(); - window.addEventListener("resize", movePagination); + window.addEventListener('resize', movePagination); }); -document.addEventListener("DOMContentLoaded", function () { +document.addEventListener('DOMContentLoaded', function () { let currentPageMostPopular = 1; const totalPages = 320; - const mostPopularMain = document.getElementById("most-popular"); - const paginationContainer = document.getElementById( - "most-popular-pagination", - ); + const mostPopularMain = document.getElementById('most-popular'); + const paginationContainer = document.getElementById('most-popular-pagination'); const fetchAndUpdateMostPopular = () => { const mostPopularUrl = `https://${getMovieVerseData()}/3/movie/popular?${generateMovieNames()}${getMovieCode()}`; @@ -45,16 +43,12 @@ document.addEventListener("DOMContentLoaded", function () { }; const updatePaginationDisplay = () => { - paginationContainer.innerHTML = ""; + paginationContainer.innerHTML = ''; - const prevButton = createNavigationButton( - "<", - currentPageMostPopular > 1, - () => { - currentPageMostPopular--; - fetchAndUpdateMostPopular(); - }, - ); + const prevButton = createNavigationButton('<', currentPageMostPopular > 1, () => { + currentPageMostPopular--; + fetchAndUpdateMostPopular(); + }); paginationContainer.appendChild(prevButton); let startPage = Math.max(currentPageMostPopular - 2, 1); @@ -64,8 +58,7 @@ document.addEventListener("DOMContentLoaded", function () { if (startPage > 1) { paginationContainer.appendChild(createPageButton(1)); - if (startPage > 2) - paginationContainer.appendChild(createPageButton("...")); + if (startPage > 2) paginationContainer.appendChild(createPageButton('...')); } for (let i = startPage; i <= endPage; i++) { @@ -73,27 +66,22 @@ document.addEventListener("DOMContentLoaded", function () { } if (endPage < totalPages) { - if (endPage < totalPages - 1) - paginationContainer.appendChild(createPageButton("...")); + if (endPage < totalPages - 1) paginationContainer.appendChild(createPageButton('...')); paginationContainer.appendChild(createPageButton(totalPages)); } - const nextButton = createNavigationButton( - ">", - currentPageMostPopular < totalPages, - () => { - currentPageMostPopular++; - fetchAndUpdateMostPopular(); - }, - ); + const nextButton = createNavigationButton('>', currentPageMostPopular < totalPages, () => { + currentPageMostPopular++; + fetchAndUpdateMostPopular(); + }); paginationContainer.appendChild(nextButton); }; const createNavigationButton = (text, enabled, clickHandler) => { - const button = document.createElement("button"); + const button = document.createElement('button'); button.innerHTML = text; button.disabled = !enabled; - button.className = "nav-button"; + button.className = 'nav-button'; if (enabled) { button.onclick = clickHandler; @@ -102,12 +90,12 @@ document.addEventListener("DOMContentLoaded", function () { return button; }; - const createPageButton = (pageNum) => { - const button = document.createElement("button"); + const createPageButton = pageNum => { + const button = document.createElement('button'); button.textContent = pageNum; - button.className = "page-button"; + button.className = 'page-button'; - if (pageNum === "...") { + if (pageNum === '...') { button.disabled = true; } else { button.onclick = function () { @@ -116,7 +104,7 @@ document.addEventListener("DOMContentLoaded", function () { }; if (pageNum === currentPageMostPopular) { - button.classList.add("active"); + button.classList.add('active'); } } return button; @@ -125,12 +113,7 @@ document.addEventListener("DOMContentLoaded", function () { fetchAndUpdateMostPopular(); }); -function setupPagination( - mainElementId, - paginationContainerId, - genresContainerId, - baseUrl, -) { +function setupPagination(mainElementId, paginationContainerId, genresContainerId, baseUrl) { let currentPage = 1; let totalPages = 10; @@ -185,7 +168,7 @@ function setupPagination( mainElement.innerHTML = `

No movies found on this page.

`; } } catch (error) { - console.log("Error fetching data: ", error); + console.log('Error fetching data: ', error); mainElement.innerHTML = `

No movies found on this page.

`; } finally { hideSpinner(); @@ -194,9 +177,9 @@ function setupPagination( } const updatePaginationDisplay = () => { - paginationContainer.innerHTML = ""; + paginationContainer.innerHTML = ''; - const prevButton = createNavigationButton("<", currentPage > 1, () => { + const prevButton = createNavigationButton('<', currentPage > 1, () => { currentPage--; fetchAndUpdate(); }); @@ -211,8 +194,7 @@ function setupPagination( if (startPage > 1) { paginationContainer.appendChild(createPageButton(1)); - if (startPage > 2) - paginationContainer.appendChild(createPageButton("...")); + if (startPage > 2) paginationContainer.appendChild(createPageButton('...')); } for (let i = startPage; i <= endPage; i++) { @@ -220,50 +202,45 @@ function setupPagination( } if (endPage < totalPages) { - if (endPage < totalPages - 1) - paginationContainer.appendChild(createPageButton("...")); + if (endPage < totalPages - 1) paginationContainer.appendChild(createPageButton('...')); paginationContainer.appendChild(createPageButton(totalPages)); } - const nextButton = createNavigationButton( - ">", - currentPage < totalPages, - () => { - currentPage++; - fetchAndUpdate(); - }, - ); + const nextButton = createNavigationButton('>', currentPage < totalPages, () => { + currentPage++; + fetchAndUpdate(); + }); paginationContainer.appendChild(nextButton); }; function createNavigationButton(text, enabled, clickHandler) { - const button = document.createElement("button"); + const button = document.createElement('button'); button.textContent = text; button.disabled = !enabled; - button.className = "nav-button"; + button.className = 'nav-button'; if (enabled) { - button.addEventListener("click", clickHandler); + button.addEventListener('click', clickHandler); } return button; } function createPageButton(pageNum) { - const button = document.createElement("button"); + const button = document.createElement('button'); button.textContent = pageNum; - button.className = "page-button"; + button.className = 'page-button'; - if (pageNum === "...") { + if (pageNum === '...') { button.disabled = true; } else { - button.addEventListener("click", () => { - currentPage = typeof pageNum === "number" ? pageNum : currentPage; + button.addEventListener('click', () => { + currentPage = typeof pageNum === 'number' ? pageNum : currentPage; fetchAndUpdate(); }); if (pageNum === currentPage) { - button.classList.add("active"); + button.classList.add('active'); } } return button; @@ -273,7 +250,7 @@ function setupPagination( fetchAndUpdate(); let resizeTimer; - window.addEventListener("resize", () => { + window.addEventListener('resize', () => { clearTimeout(resizeTimer); resizeTimer = setTimeout(movePagination, 250); }); @@ -288,21 +265,16 @@ async function fetchAndDisplayMovies(url, count, mainElement) { showMovies(movies, mainElement); } -document.addEventListener("DOMContentLoaded", async () => { +document.addEventListener('DOMContentLoaded', async () => { let currentPageRecommended = 1; const totalPagesRecommended = 60; - const recommendedMain = document.getElementById("recommended"); - const paginationContainerRecommended = document.getElementById( - "recommended-pagination", - ); - const genresContainer = document.getElementById("recommendedDIV"); + const recommendedMain = document.getElementById('recommended'); + const paginationContainerRecommended = document.getElementById('recommended-pagination'); + const genresContainer = document.getElementById('recommendedDIV'); function movePagination() { if (window.innerWidth <= 767) { - recommendedMain.parentNode.insertBefore( - paginationContainerRecommended, - recommendedMain, - ); + recommendedMain.parentNode.insertBefore(paginationContainerRecommended, recommendedMain); } else { genresContainer.appendChild(paginationContainerRecommended); } @@ -315,7 +287,7 @@ document.addEventListener("DOMContentLoaded", async () => { const mostCommonGenre = getMostCommonGenre(); const mostVisitedMovieGenre = await getMostVisitedMovieGenre(); - recommendedMain.innerHTML = ""; + recommendedMain.innerHTML = ''; if (!mostVisitedMovieGenre || !mostCommonGenre) { recommendedMain.innerHTML = `
@@ -330,29 +302,17 @@ document.addEventListener("DOMContentLoaded", async () => { const commonGenreUrl = `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=${mostCommonGenre}&sort_by=popularity.desc&vote_count.gte=10&page=${currentPageRecommended}`; const visitedGenreUrl = `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=${mostVisitedMovieGenre}&sort_by=popularity.desc&vote_count.gte=10&page=${currentPageRecommended}`; - await fetchAndDisplayMovies( - commonGenreUrl, - totalMoviesToDisplay, - recommendedMain, - ); - await fetchAndDisplayMovies( - visitedGenreUrl, - totalMoviesToDisplay, - recommendedMain, - ); + await fetchAndDisplayMovies(commonGenreUrl, totalMoviesToDisplay, recommendedMain); + await fetchAndDisplayMovies(visitedGenreUrl, totalMoviesToDisplay, recommendedMain); updatePaginationDisplayRecommended(); hideSpinner(); } function updatePaginationDisplayRecommended() { - paginationContainerRecommended.innerHTML = ""; + paginationContainerRecommended.innerHTML = ''; - const prevButton = createNavigationButton( - "<", - currentPageRecommended > 1, - () => generateRecommendations(currentPageRecommended - 1), - ); + const prevButton = createNavigationButton('<', currentPageRecommended > 1, () => generateRecommendations(currentPageRecommended - 1)); paginationContainerRecommended.appendChild(prevButton); let startPage = Math.max(currentPageRecommended - 2, 1); @@ -361,57 +321,43 @@ document.addEventListener("DOMContentLoaded", async () => { if (endPage === totalPagesRecommended) startPage = Math.max(endPage - 4, 1); if (startPage > 1) { - paginationContainerRecommended.appendChild( - createPageButton(1, generateRecommendations), - ); - if (startPage > 2) - paginationContainerRecommended.appendChild(createPageButton("...")); + paginationContainerRecommended.appendChild(createPageButton(1, generateRecommendations)); + if (startPage > 2) paginationContainerRecommended.appendChild(createPageButton('...')); } for (let i = startPage; i <= endPage; i++) { - paginationContainerRecommended.appendChild( - createPageButton( - i, - generateRecommendations, - i === currentPageRecommended, - ), - ); + paginationContainerRecommended.appendChild(createPageButton(i, generateRecommendations, i === currentPageRecommended)); } if (endPage < totalPagesRecommended) { - if (endPage < totalPagesRecommended - 1) - paginationContainerRecommended.appendChild(createPageButton("...")); - paginationContainerRecommended.appendChild( - createPageButton(totalPagesRecommended, generateRecommendations), - ); + if (endPage < totalPagesRecommended - 1) paginationContainerRecommended.appendChild(createPageButton('...')); + paginationContainerRecommended.appendChild(createPageButton(totalPagesRecommended, generateRecommendations)); } - const nextButton = createNavigationButton( - ">", - currentPageRecommended < totalPagesRecommended, - () => generateRecommendations(currentPageRecommended + 1), + const nextButton = createNavigationButton('>', currentPageRecommended < totalPagesRecommended, () => + generateRecommendations(currentPageRecommended + 1) ); paginationContainerRecommended.appendChild(nextButton); } function createNavigationButton(text, enabled, clickHandler) { - const button = document.createElement("button"); + const button = document.createElement('button'); button.innerHTML = text; button.disabled = !enabled; - button.className = "nav-button"; + button.className = 'nav-button'; if (enabled) { - button.addEventListener("click", clickHandler); + button.addEventListener('click', clickHandler); } return button; } function createPageButton(pageNum, fetchFunction, isActive) { - const button = document.createElement("button"); + const button = document.createElement('button'); button.textContent = pageNum; - button.className = "page-button" + (isActive ? " active" : ""); + button.className = 'page-button' + (isActive ? ' active' : ''); - if (pageNum !== "...") { - button.addEventListener("click", () => fetchFunction(pageNum)); + if (pageNum !== '...') { + button.addEventListener('click', () => fetchFunction(pageNum)); } else { button.disabled = true; } @@ -421,7 +367,7 @@ document.addEventListener("DOMContentLoaded", async () => { movePagination(); await generateRecommendations(); - window.addEventListener("resize", movePagination); + window.addEventListener('resize', movePagination); }); async function getMovies(url, mainElement, page = 1) { @@ -452,37 +398,33 @@ async function getMovies(url, mainElement, page = 1) { } async function getAdditionalPosters(movieId) { - const response = await fetch( - `https://${getMovieVerseData()}/3/movie/${movieId}/images?${generateMovieNames()}${getMovieCode()}`, - ); + const response = await fetch(`https://${getMovieVerseData()}/3/movie/${movieId}/images?${generateMovieNames()}${getMovieCode()}`); const data = await response.json(); - return data.posters.map((poster) => poster.file_path); + return data.posters.map(poster => poster.file_path); } function rotateImages(imageElements, interval = 3000) { - const uniqueImageElements = Array.from(imageElements).filter( - (el, index, self) => index === self.findIndex((e) => e.src === el.src), - ); + const uniqueImageElements = Array.from(imageElements).filter((el, index, self) => index === self.findIndex(e => e.src === el.src)); if (uniqueImageElements.length <= 1) return; let currentIndex = 0; - uniqueImageElements[currentIndex].style.opacity = "1"; + uniqueImageElements[currentIndex].style.opacity = '1'; setTimeout(() => { setInterval(() => { - uniqueImageElements[currentIndex].style.opacity = "0"; + uniqueImageElements[currentIndex].style.opacity = '0'; currentIndex = (currentIndex + 1) % uniqueImageElements.length; - uniqueImageElements[currentIndex].style.opacity = "1"; + uniqueImageElements[currentIndex].style.opacity = '1'; }, interval); }, 0); } async function showMovies(movies, mainElement) { - mainElement.innerHTML = ""; + mainElement.innerHTML = ''; // Inject CSS for the sliding-up animation effect with delay support - const style = document.createElement("style"); + const style = document.createElement('style'); style.innerHTML = ` .movie { opacity: 0; @@ -498,23 +440,23 @@ async function showMovies(movies, mainElement) { // Observer to trigger the slide-up animation with a staggered delay const slideObserver = new IntersectionObserver( - (entries) => { + entries => { entries.forEach((entry, index) => { if (entry.isIntersecting) { const movieEl = entry.target; // Apply a staggered delay based on the card's index movieEl.style.transitionDelay = `${index * 100}ms`; // Adjust delay as needed - movieEl.classList.add("visible"); + movieEl.classList.add('visible'); slideObserver.unobserve(movieEl); } }); }, { - rootMargin: "50px 0px", + rootMargin: '50px 0px', threshold: 0.1, - }, + } ); // Observer for background image loading and rotation setup @@ -528,7 +470,7 @@ async function showMovies(movies, mainElement) { // Fetch additional posters and set up rotation in the background const additionalPosters = await getAdditionalPosters(movieId); let allPosters = [movieEl.dataset.posterPath, ...additionalPosters]; - const movieImageContainer = movieEl.querySelector(".movie-images"); + const movieImageContainer = movieEl.querySelector('.movie-images'); allPosters = allPosters.sort(() => 0.5 - Math.random()).slice(0, 10); @@ -536,20 +478,20 @@ async function showMovies(movies, mainElement) { allPosters.forEach((poster, index) => { const img = new Image(); img.src = `${IMGPATH + poster}`; - img.loading = index === 0 ? "eager" : "lazy"; + img.loading = index === 0 ? 'eager' : 'lazy'; img.alt = `${movieEl.dataset.title} poster ${index + 1}`; img.width = 300; img.height = 435; - img.style.position = "absolute"; + img.style.position = 'absolute'; img.style.top = 0; img.style.left = 0; - img.style.transition = "opacity 1s ease-in-out"; - img.style.opacity = "0"; - img.classList.add("poster-img"); + img.style.transition = 'opacity 1s ease-in-out'; + img.style.opacity = '0'; + img.classList.add('poster-img'); movieImageContainer.appendChild(img); img.onload = () => { - if (index === 0) img.style.opacity = "1"; // Show the first image + if (index === 0) img.style.opacity = '1'; // Show the first image }; }); @@ -560,41 +502,32 @@ async function showMovies(movies, mainElement) { } }, { - rootMargin: "50px 0px", + rootMargin: '50px 0px', threshold: 0.1, - }, + } ); movies.forEach((movie, index) => { - let { - id, - poster_path, - title, - vote_average, - vote_count, - overview, - genre_ids, - } = movie; - - const movieEl = document.createElement("div"); - movieEl.style.zIndex = "1000"; - movieEl.classList.add("movie"); + let { id, poster_path, title, vote_average, vote_count, overview, genre_ids } = movie; + + const movieEl = document.createElement('div'); + movieEl.style.zIndex = '1000'; + movieEl.classList.add('movie'); movieEl.dataset.id = id; movieEl.dataset.posterPath = poster_path; movieEl.dataset.title = title; - const words = title.split(" "); + const words = title.split(' '); if (words.length >= 8) { - words[7] = "..."; - title = words.slice(0, 8).join(" "); + words[7] = '...'; + title = words.slice(0, 8).join(' '); } - const voteAvg = vote_count === 0 ? "Unrated" : vote_average.toFixed(1); - const ratingClass = - vote_count === 0 ? "unrated" : getClassByRate(vote_average); + const voteAvg = vote_count === 0 ? 'Unrated' : vote_average.toFixed(1); + const ratingClass = vote_count === 0 ? 'unrated' : getClassByRate(vote_average); - if (overview === "") { - overview = "No overview available."; + if (overview === '') { + overview = 'No overview available.'; } movieEl.innerHTML = ` @@ -612,12 +545,12 @@ async function showMovies(movies, mainElement) { ${overview}
`; - movieEl.addEventListener("click", () => { - localStorage.setItem("selectedMovieId", id); + movieEl.addEventListener('click', () => { + localStorage.setItem('selectedMovieId', id); updateUniqueMoviesViewed(id); updateFavoriteGenre(genre_ids); updateMovieVisitCount(id, title); - window.location.href = "MovieVerse-Frontend/html/movie-details.html"; + window.location.href = 'MovieVerse-Frontend/html/movie-details.html'; }); mainElement.appendChild(movieEl); @@ -632,24 +565,22 @@ async function showMovies(movies, mainElement) { function updateFavoriteGenre(genre_ids) { if (genre_ids && genre_ids.length > 0) { - const favoriteGenres = - JSON.parse(localStorage.getItem("favoriteGenres")) || []; + const favoriteGenres = JSON.parse(localStorage.getItem('favoriteGenres')) || []; favoriteGenres.push(genre_ids[0]); - localStorage.setItem("favoriteGenres", JSON.stringify(favoriteGenres)); + localStorage.setItem('favoriteGenres', JSON.stringify(favoriteGenres)); } } function updateUniqueMoviesViewed(movieId) { - let viewedMovies = - JSON.parse(localStorage.getItem("uniqueMoviesViewed")) || []; + let viewedMovies = JSON.parse(localStorage.getItem('uniqueMoviesViewed')) || []; if (!viewedMovies.includes(movieId)) { viewedMovies.push(movieId); - localStorage.setItem("uniqueMoviesViewed", JSON.stringify(viewedMovies)); + localStorage.setItem('uniqueMoviesViewed', JSON.stringify(viewedMovies)); } } async function ensureGenreMapIsAvailable() { - if (!localStorage.getItem("genreMap")) { + if (!localStorage.getItem('genreMap')) { await fetchGenreMap(); } } @@ -664,9 +595,9 @@ async function fetchGenreMap() { map[genre.id] = genre.name; return map; }, {}); - localStorage.setItem("genreMap", JSON.stringify(genreMap)); + localStorage.setItem('genreMap', JSON.stringify(genreMap)); } catch (error) { - console.log("Error fetching genre map:", error); + console.log('Error fetching genre map:', error); } } @@ -675,51 +606,49 @@ async function rotateUserStats() { const stats = [ { - label: "Your Current Time", + label: 'Your Current Time', getValue: () => { const now = new Date(); let hours = now.getHours(); let minutes = now.getMinutes(); - hours = hours < 10 ? "0" + hours : hours; - minutes = minutes < 10 ? "0" + minutes : minutes; + hours = hours < 10 ? '0' + hours : hours; + minutes = minutes < 10 ? '0' + minutes : minutes; return `${hours}:${minutes}`; }, }, - { label: "Most Visited Movie", getValue: getMostVisitedMovie }, - { label: "Most Visited Director", getValue: getMostVisitedDirector }, - { label: "Most Visited Actor", getValue: getMostVisitedActor }, + { label: 'Most Visited Movie', getValue: getMostVisitedMovie }, + { label: 'Most Visited Director', getValue: getMostVisitedDirector }, + { label: 'Most Visited Actor', getValue: getMostVisitedActor }, { - label: "Movies Discovered", + label: 'Movies Discovered', getValue: () => { - const viewedMovies = - JSON.parse(localStorage.getItem("uniqueMoviesViewed")) || []; + const viewedMovies = JSON.parse(localStorage.getItem('uniqueMoviesViewed')) || []; return viewedMovies.length; }, }, { - label: "Favorite Movies", + label: 'Favorite Movies', getValue: () => { - const favoritedMovies = - JSON.parse(localStorage.getItem("moviesFavorited")) || []; + const favoritedMovies = JSON.parse(localStorage.getItem('moviesFavorited')) || []; return favoritedMovies.length; }, }, { - label: "Favorite Genre", + label: 'Favorite Genre', getValue: () => { const mostCommonGenreCode = getMostCommonGenre(); - const genreMapString = localStorage.getItem("genreMap"); + const genreMapString = localStorage.getItem('genreMap'); if (!genreMapString) { - console.log("No genre map found in localStorage."); - return "Not Available"; + console.log('No genre map found in localStorage.'); + return 'Not Available'; } let genreMap; try { genreMap = JSON.parse(genreMapString); } catch (e) { - console.log("Error parsing genre map:", e); - return "Not Available"; + console.log('Error parsing genre map:', e); + return 'Not Available'; } let genreObject; @@ -728,81 +657,74 @@ async function rotateUserStats() { acc[genre.id] = genre.name; return acc; }, {}); - } else if (typeof genreMap === "object" && genreMap !== null) { + } else if (typeof genreMap === 'object' && genreMap !== null) { genreObject = genreMap; } else { - console.log( - "genreMap is neither an array nor a proper object:", - genreMap, - ); - return "Not Available"; + console.log('genreMap is neither an array nor a proper object:', genreMap); + return 'Not Available'; } - return genreObject[mostCommonGenreCode] || "Not Available"; + return genreObject[mostCommonGenreCode] || 'Not Available'; }, }, { - label: "Watchlists Created", - getValue: () => localStorage.getItem("watchlistsCreated") || 0, + label: 'Watchlists Created', + getValue: () => localStorage.getItem('watchlistsCreated') || 0, }, { - label: "Average Movie Rating", - getValue: () => localStorage.getItem("averageMovieRating") || "Not Rated", + label: 'Average Movie Rating', + getValue: () => localStorage.getItem('averageMovieRating') || 'Not Rated', }, { - label: "Directors Discovered", + label: 'Directors Discovered', getValue: () => { - const viewedDirectors = - JSON.parse(localStorage.getItem("uniqueDirectorsViewed")) || []; + const viewedDirectors = JSON.parse(localStorage.getItem('uniqueDirectorsViewed')) || []; return viewedDirectors.length; }, }, { - label: "Actors Discovered", + label: 'Actors Discovered', getValue: () => { - const viewedActors = - JSON.parse(localStorage.getItem("uniqueActorsViewed")) || []; + const viewedActors = JSON.parse(localStorage.getItem('uniqueActorsViewed')) || []; return viewedActors.length; }, }, - { label: "Your Trivia Accuracy", getValue: getTriviaAccuracy }, + { label: 'Your Trivia Accuracy', getValue: getTriviaAccuracy }, ]; let currentStatIndex = 0; function updateStatDisplay() { const currentStat = stats[currentStatIndex]; - document.getElementById("stats-label").textContent = - currentStat.label + ":"; - document.getElementById("stats-display").textContent = - currentStat.getValue(); + document.getElementById('stats-label').textContent = currentStat.label + ':'; + document.getElementById('stats-display').textContent = currentStat.getValue(); currentStatIndex = (currentStatIndex + 1) % stats.length; } updateStatDisplay(); - const localTimeDiv = document.getElementById("local-time"); + const localTimeDiv = document.getElementById('local-time'); let statRotationInterval = setInterval(updateStatDisplay, 3000); - localTimeDiv.addEventListener("click", () => { + localTimeDiv.addEventListener('click', () => { clearInterval(statRotationInterval); updateStatDisplay(); statRotationInterval = setInterval(updateStatDisplay, 3000); - localTimeDiv.scrollIntoView({ behavior: "smooth" }); + localTimeDiv.scrollIntoView({ behavior: 'smooth' }); }); } function updateMovieVisitCount(movieId, movieTitle) { - let movieVisits = JSON.parse(localStorage.getItem("movieVisits")) || {}; + let movieVisits = JSON.parse(localStorage.getItem('movieVisits')) || {}; if (!movieVisits[movieId]) { movieVisits[movieId] = { count: 0, title: movieTitle }; } movieVisits[movieId].count += 1; - localStorage.setItem("movieVisits", JSON.stringify(movieVisits)); + localStorage.setItem('movieVisits', JSON.stringify(movieVisits)); } function getMostVisitedMovie() { - const movieVisits = JSON.parse(localStorage.getItem("movieVisits")) || {}; - let mostVisitedMovie = ""; + const movieVisits = JSON.parse(localStorage.getItem('movieVisits')) || {}; + let mostVisitedMovie = ''; let maxVisits = 0; for (const movieId in movieVisits) { @@ -812,11 +734,11 @@ function getMostVisitedMovie() { } } - return mostVisitedMovie || "Not Available"; + return mostVisitedMovie || 'Not Available'; } async function getMostVisitedMovieGenre() { - const movieVisits = JSON.parse(localStorage.getItem("movieVisits")) || {}; + const movieVisits = JSON.parse(localStorage.getItem('movieVisits')) || {}; let mostVisitedGenre = null; let maxVisits = 0; @@ -839,8 +761,8 @@ async function fetchGenreForMovie(movieId) { } function getMostVisitedActor() { - const actorVisits = JSON.parse(localStorage.getItem("actorVisits")) || {}; - let mostVisitedActor = ""; + const actorVisits = JSON.parse(localStorage.getItem('actorVisits')) || {}; + let mostVisitedActor = ''; let maxVisits = 0; for (const actorId in actorVisits) { @@ -850,13 +772,12 @@ function getMostVisitedActor() { } } - return mostVisitedActor || "Not Available"; + return mostVisitedActor || 'Not Available'; } function getMostVisitedDirector() { - const directorVisits = - JSON.parse(localStorage.getItem("directorVisits")) || {}; - let mostVisitedDirector = ""; + const directorVisits = JSON.parse(localStorage.getItem('directorVisits')) || {}; + let mostVisitedDirector = ''; let maxVisits = 0; for (const directorId in directorVisits) { @@ -865,16 +786,16 @@ function getMostVisitedDirector() { maxVisits = directorVisits[directorId].count; } } - return mostVisitedDirector || "Not Available"; + return mostVisitedDirector || 'Not Available'; } function getTriviaAccuracy() { - let triviaStats = JSON.parse(localStorage.getItem("triviaStats")) || { + let triviaStats = JSON.parse(localStorage.getItem('triviaStats')) || { totalCorrect: 0, totalAttempted: 0, }; if (triviaStats.totalAttempted === 0) { - return "No trivia attempted"; + return 'No trivia attempted'; } let accuracy = (triviaStats.totalCorrect / triviaStats.totalAttempted) * 100; @@ -882,14 +803,13 @@ function getTriviaAccuracy() { } function getMostCommonGenre() { - const favoriteGenresArray = - JSON.parse(localStorage.getItem("favoriteGenres")) || []; + const favoriteGenresArray = JSON.parse(localStorage.getItem('favoriteGenres')) || []; const genreCounts = favoriteGenresArray.reduce((acc, genre) => { acc[genre] = (acc[genre] || 0) + 1; return acc; }, {}); - let mostCommonGenre = ""; + let mostCommonGenre = ''; let maxCount = 0; for (const genre in genreCounts) { @@ -899,16 +819,16 @@ function getMostCommonGenre() { } } - return mostCommonGenre || "Not Available"; + return mostCommonGenre || 'Not Available'; } const movieCode = { - part1: "YzVhMjBjODY=", - part2: "MWFjZjdiYjg=", - part3: "ZDllOTg3ZGNjN2YxYjU1OA==", + part1: 'YzVhMjBjODY=', + part2: 'MWFjZjdiYjg=', + part3: 'ZDllOTg3ZGNjN2YxYjU1OA==', }; -document.addEventListener("DOMContentLoaded", rotateUserStats); +document.addEventListener('DOMContentLoaded', rotateUserStats); async function showMovieOfTheDay() { const year = new Date().getFullYear(); @@ -921,28 +841,26 @@ async function showMovieOfTheDay() { if (movies.length > 0) { const randomMovie = movies[Math.floor(Math.random() * movies.length)]; - localStorage.setItem("selectedMovieId", randomMovie.id); - window.location.href = "MovieVerse-Frontend/html/movie-details.html"; + localStorage.setItem('selectedMovieId', randomMovie.id); + window.location.href = 'MovieVerse-Frontend/html/movie-details.html'; } else { fallbackMovieSelection(); } } catch (error) { - console.log("Error fetching movie:", error); + console.log('Error fetching movie:', error); fallbackMovieSelection(); } } function fallbackMovieSelection() { const fallbackMovies = [ - 432413, 299534, 1726, 562, 118340, 455207, 493922, 447332, 22970, 530385, - 27205, 264660, 120467, 603, 577922, 76341, 539, 419704, 515001, 118340, 424, - 98, + 432413, 299534, 1726, 562, 118340, 455207, 493922, 447332, 22970, 530385, 27205, 264660, 120467, 603, 577922, 76341, 539, 419704, 515001, 118340, + 424, 98, ]; - const randomFallbackMovie = - fallbackMovies[Math.floor(Math.random() * fallbackMovies.length)]; + const randomFallbackMovie = fallbackMovies[Math.floor(Math.random() * fallbackMovies.length)]; - localStorage.setItem("selectedMovieId", randomFallbackMovie); - window.location.href = "MovieVerse-Frontend/html/movie-details.html"; + localStorage.setItem('selectedMovieId', randomFallbackMovie); + window.location.href = 'MovieVerse-Frontend/html/movie-details.html'; } function calculateMoviesToDisplay() { @@ -976,75 +894,71 @@ function calculateMoviesToDisplay() { function getClassByRate(vote) { if (vote >= 8) { - return "green"; + return 'green'; } else if (vote >= 5) { - return "orange"; + return 'orange'; } else { - return "red"; + return 'red'; } } -form.addEventListener("submit", (e) => { +form.addEventListener('submit', e => { e.preventDefault(); - const searchQuery = document.getElementById("search").value; + const searchQuery = document.getElementById('search').value; - localStorage.setItem("searchQuery", searchQuery); - window.location.href = "MovieVerse-Frontend/html/search.html"; + localStorage.setItem('searchQuery', searchQuery); + window.location.href = 'MovieVerse-Frontend/html/search.html'; }); function toggleNav() { - const sideNav = document.getElementById("side-nav"); + const sideNav = document.getElementById('side-nav'); - sideNav.classList.toggle("manual-toggle"); + sideNav.classList.toggle('manual-toggle'); adjustNavBar(); } function removeNavBar() { - const sideNav = document.getElementById("side-nav"); + const sideNav = document.getElementById('side-nav'); - if (sideNav.classList.contains("manual-toggle")) { - sideNav.classList.remove("manual-toggle"); + if (sideNav.classList.contains('manual-toggle')) { + sideNav.classList.remove('manual-toggle'); } adjustNavBar(); } function adjustNavBar() { - const sideNav = document.getElementById("side-nav"); + const sideNav = document.getElementById('side-nav'); - if (sideNav.classList.contains("manual-toggle")) { - sideNav.style.left = "0px"; + if (sideNav.classList.contains('manual-toggle')) { + sideNav.style.left = '0px'; } else { - sideNav.style.left = "-250px"; + sideNav.style.left = '-250px'; } } -document.addEventListener("mousemove", function (event) { - const sideNav = document.getElementById("side-nav"); +document.addEventListener('mousemove', function (event) { + const sideNav = document.getElementById('side-nav'); - if (event.clientX < 10 && !sideNav.classList.contains("manual-toggle")) { - sideNav.style.left = "0"; + if (event.clientX < 10 && !sideNav.classList.contains('manual-toggle')) { + sideNav.style.left = '0'; } }); -document.addEventListener("click", function (event) { - const sideNav = document.getElementById("side-nav"); - const navToggle = document.getElementById("nav-toggle"); +document.addEventListener('click', function (event) { + const sideNav = document.getElementById('side-nav'); + const navToggle = document.getElementById('nav-toggle'); - if ( - !sideNav.contains(event.target) && - !navToggle.contains(event.target) && - sideNav.classList.contains("manual-toggle") - ) { - sideNav.classList.remove("manual-toggle"); + if (!sideNav.contains(event.target) && !navToggle.contains(event.target) && sideNav.classList.contains('manual-toggle')) { + sideNav.classList.remove('manual-toggle'); adjustNavBar(); } }); -document.getElementById("side-nav").addEventListener("mouseleave", function () { - const sideNav = document.getElementById("side-nav"); +document.getElementById('side-nav').addEventListener('mouseleave', function () { + const sideNav = document.getElementById('side-nav'); - if (!sideNav.classList.contains("manual-toggle")) { - sideNav.style.left = "-250px"; + if (!sideNav.classList.contains('manual-toggle')) { + sideNav.style.left = '-250px'; } }); @@ -1053,32 +967,32 @@ const IMGPATH = `https://image.tmdb.org/t/p/w500`; const SEARCHPATH = `https://${getMovieVerseData()}/3/search/movie?&${generateMovieNames()}${getMovieCode()}&query=`; const directors = [ - { name: "Alfred Hitchcock", id: "2636" }, - { name: "Steven Spielberg", id: "488" }, - { name: "Martin Scorsese", id: "1032" }, - { name: "Quentin Tarantino", id: "138" }, - { name: "Christopher Nolan", id: "525" }, - { name: "Stanley Kubrick", id: "240" }, - { name: "Bong Joon-ho", id: "21684" }, - { name: "David Fincher", id: "7467" }, - { name: "James Cameron", id: "2710" }, - { name: "Francis Ford Coppola", id: "1776" }, - { name: "Tim Burton", id: "510" }, - { name: "Ridley Scott", id: "578" }, - { name: "Joel Coen", id: "1223" }, - { name: "Spike Lee", id: "5281" }, - { name: "Woody Allen", id: "1243" }, - { name: "Peter Jackson", id: "108" }, - { name: "Oliver Stone", id: "1152" }, - { name: "David Lynch", id: "5602" }, - { name: "Roman Polanski", id: "3556" }, - { name: "Wes Anderson", id: "5655" }, - { name: "Sergio Leone", id: "4385" }, - { name: "Akira Kurosawa", id: "5026" }, - { name: "Federico Fellini", id: "4415" }, - { name: "John Ford", id: "8500" }, - { name: "Fritz Lang", id: "68" }, - { name: "Frank Capra", id: "2662" }, + { name: 'Alfred Hitchcock', id: '2636' }, + { name: 'Steven Spielberg', id: '488' }, + { name: 'Martin Scorsese', id: '1032' }, + { name: 'Quentin Tarantino', id: '138' }, + { name: 'Christopher Nolan', id: '525' }, + { name: 'Stanley Kubrick', id: '240' }, + { name: 'Bong Joon-ho', id: '21684' }, + { name: 'David Fincher', id: '7467' }, + { name: 'James Cameron', id: '2710' }, + { name: 'Francis Ford Coppola', id: '1776' }, + { name: 'Tim Burton', id: '510' }, + { name: 'Ridley Scott', id: '578' }, + { name: 'Joel Coen', id: '1223' }, + { name: 'Spike Lee', id: '5281' }, + { name: 'Woody Allen', id: '1243' }, + { name: 'Peter Jackson', id: '108' }, + { name: 'Oliver Stone', id: '1152' }, + { name: 'David Lynch', id: '5602' }, + { name: 'Roman Polanski', id: '3556' }, + { name: 'Wes Anderson', id: '5655' }, + { name: 'Sergio Leone', id: '4385' }, + { name: 'Akira Kurosawa', id: '5026' }, + { name: 'Federico Fellini', id: '4415' }, + { name: 'John Ford', id: '8500' }, + { name: 'Fritz Lang', id: '68' }, + { name: 'Frank Capra', id: '2662' }, ]; let currentDirectorIndex = 0; @@ -1097,8 +1011,7 @@ setInterval(changeDirector, 3600000); function updateDirectorSpotlight() { const director = directors[currentDirectorIndex]; - document.getElementById("spotlight-director-name").textContent = - director.name; + document.getElementById('spotlight-director-name').textContent = director.name; const url = `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_people=${ director.id @@ -1107,26 +1020,7 @@ function updateDirectorSpotlight() { } function getMovieVerseData(input) { - return String.fromCharCode( - 97, - 112, - 105, - 46, - 116, - 104, - 101, - 109, - 111, - 118, - 105, - 101, - 100, - 98, - 46, - 111, - 114, - 103, - ); + return String.fromCharCode(97, 112, 105, 46, 116, 104, 101, 109, 111, 118, 105, 101, 100, 98, 46, 111, 114, 103); } function generateMovieNames(input) { @@ -1150,10 +1044,10 @@ async function getDirectorSpotlight(url) { } function showMoviesDirectorSpotlight(movies) { - director_main.innerHTML = ""; + director_main.innerHTML = ''; // Inject CSS for the sliding-up animation effect with delay support - const style = document.createElement("style"); + const style = document.createElement('style'); style.innerHTML = ` .movie { opacity: 0; @@ -1169,40 +1063,39 @@ function showMoviesDirectorSpotlight(movies) { // Observer to trigger the slide-up animation with a staggered delay const slideObserver = new IntersectionObserver( - (entries) => { + entries => { entries.forEach((entry, index) => { if (entry.isIntersecting) { const movieEl = entry.target; // Apply a staggered delay based on the card's index movieEl.style.transitionDelay = `${index * 100}ms`; // Adjust delay as needed - movieEl.classList.add("visible"); + movieEl.classList.add('visible'); slideObserver.unobserve(movieEl); } }); }, { - rootMargin: "50px 0px", + rootMargin: '50px 0px', threshold: 0.1, - }, + } ); movies.forEach((movie, index) => { const { id, poster_path, title, vote_average, genre_ids } = movie; - const movieEl = document.createElement("div"); + const movieEl = document.createElement('div'); - movieEl.classList.add("movie"); - movieEl.style.zIndex = "1000"; + movieEl.classList.add('movie'); + movieEl.style.zIndex = '1000'; // Movie image and fallback in case the image is unavailable const movieImage = poster_path ? `${title}` : `
Image Not Available
`; - const voteAvg = vote_average > 0 ? vote_average.toFixed(1) : "Unrated"; - const ratingClass = - vote_average > 0 ? getClassByRate(vote_average) : "unrated"; + const voteAvg = vote_average > 0 ? vote_average.toFixed(1) : 'Unrated'; + const ratingClass = vote_average > 0 ? getClassByRate(vote_average) : 'unrated'; movieEl.innerHTML = ` ${movieImage} @@ -1215,12 +1108,12 @@ function showMoviesDirectorSpotlight(movies) { ${movie.overview} `; - movieEl.addEventListener("click", () => { - localStorage.setItem("selectedMovieId", id); + movieEl.addEventListener('click', () => { + localStorage.setItem('selectedMovieId', id); updateUniqueMoviesViewed(id); updateFavoriteGenre(genre_ids); updateMovieVisitCount(id, title); - window.location.href = "MovieVerse-Frontend/html/movie-details.html"; + window.location.href = 'MovieVerse-Frontend/html/movie-details.html'; }); director_main.appendChild(movieEl); @@ -1231,13 +1124,13 @@ function showMoviesDirectorSpotlight(movies) { } function handleSignInOut() { - const isSignedIn = JSON.parse(localStorage.getItem("isSignedIn")) || false; + const isSignedIn = JSON.parse(localStorage.getItem('isSignedIn')) || false; if (isSignedIn) { - localStorage.setItem("isSignedIn", JSON.stringify(false)); - alert("You have been signed out."); + localStorage.setItem('isSignedIn', JSON.stringify(false)); + alert('You have been signed out.'); } else { - window.location.href = "MovieVerse-Frontend/html/sign-in.html"; + window.location.href = 'MovieVerse-Frontend/html/sign-in.html'; return; } @@ -1245,215 +1138,213 @@ function handleSignInOut() { } function updateSignInButtonState() { - const isSignedIn = JSON.parse(localStorage.getItem("isSignedIn")) || false; - const signInText = document.getElementById("signInOutText"); - const signInIcon = document.getElementById("signInIcon"); - const signOutIcon = document.getElementById("signOutIcon"); + const isSignedIn = JSON.parse(localStorage.getItem('isSignedIn')) || false; + const signInText = document.getElementById('signInOutText'); + const signInIcon = document.getElementById('signInIcon'); + const signOutIcon = document.getElementById('signOutIcon'); if (isSignedIn) { - signInText.textContent = "Sign Out"; - signInIcon.style.display = "none"; - signOutIcon.style.display = "inline-block"; + signInText.textContent = 'Sign Out'; + signInIcon.style.display = 'none'; + signOutIcon.style.display = 'inline-block'; } else { - signInText.textContent = "Sign In"; - signInIcon.style.display = "inline-block"; - signOutIcon.style.display = "none"; + signInText.textContent = 'Sign In'; + signInIcon.style.display = 'inline-block'; + signOutIcon.style.display = 'none'; } - const mobileSignInText = document.getElementById("mobileSignInOutText"); - const mobileSignInIcon = document.getElementById("mobileSignInIcon"); - const mobileSignOutIcon = document.getElementById("mobileSignOutIcon"); + const mobileSignInText = document.getElementById('mobileSignInOutText'); + const mobileSignInIcon = document.getElementById('mobileSignInIcon'); + const mobileSignOutIcon = document.getElementById('mobileSignOutIcon'); if (isSignedIn) { - mobileSignInText.textContent = "Sign Out"; - mobileSignInIcon.style.display = "none"; - mobileSignOutIcon.style.display = "inline-block"; + mobileSignInText.textContent = 'Sign Out'; + mobileSignInIcon.style.display = 'none'; + mobileSignOutIcon.style.display = 'inline-block'; } else { - mobileSignInText.textContent = "Sign In"; - mobileSignInIcon.style.display = "inline-block"; - mobileSignOutIcon.style.display = "none"; + mobileSignInText.textContent = 'Sign In'; + mobileSignInIcon.style.display = 'inline-block'; + mobileSignOutIcon.style.display = 'none'; } } setupPagination( - "award-winning", - "award-winning-pagination", - "award-winning-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&sort_by=vote_average.desc&vote_count.gte=1000`, + 'award-winning', + 'award-winning-pagination', + 'award-winning-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&sort_by=vote_average.desc&vote_count.gte=1000` ); setupPagination( - "hidden-gems", - "hidden-gems-pagination", - "hidden-gems-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&sort_by=vote_average.desc&vote_count.gte=100&vote_average.gte=7&popularity.lte=10`, + 'hidden-gems', + 'hidden-gems-pagination', + 'hidden-gems-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&sort_by=vote_average.desc&vote_count.gte=100&vote_average.gte=7&popularity.lte=10` ); setupPagination( - "western", - "western-pagination", - "western-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=37&sort_by=popularity.desc&vote_count.gte=8`, + 'western', + 'western-pagination', + 'western-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=37&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "war", - "war-pagination", - "war-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10752&sort_by=popularity.desc&vote_count.gte=8`, + 'war', + 'war-pagination', + 'war-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10752&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "vietnamese", - "vietnamese-pagination", - "vietnamese-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_original_language=vi&sort_by=popularity.desc`, + 'vietnamese', + 'vietnamese-pagination', + 'vietnamese-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_original_language=vi&sort_by=popularity.desc` ); setupPagination( - "korean", - "korean-pagination", - "korean-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_original_language=ko&sort_by=vote_average.desc,popularity.desc&vote_count.gte=10&vote_average.gte=8`, + 'korean', + 'korean-pagination', + 'korean-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_original_language=ko&sort_by=vote_average.desc,popularity.desc&vote_count.gte=10&vote_average.gte=8` ); setupPagination( - "musical", - "musical-pagination", - "musical-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10402&sort_by=popularity.desc&vote_count.gte=8`, + 'musical', + 'musical-pagination', + 'musical-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10402&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "drama", - "drama-pagination", - "drama-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=18&sort_by=popularity.desc&vote_count.gte=8`, + 'drama', + 'drama-pagination', + 'drama-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=18&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "indian", - "indian-pagination", - "indian-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_original_language=hi&sort_by=popularity.desc`, + 'indian', + 'indian-pagination', + 'indian-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_original_language=hi&sort_by=popularity.desc` ); setupPagination( - "action", - "action-pagination", - "action-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=28&sort_by=popularity.desc&vote_count.gte=8`, + 'action', + 'action-pagination', + 'action-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=28&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "horror", - "horror-pagination", - "horror-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=27&sort_by=popularity.desc&vote_count.gte=8`, + 'horror', + 'horror-pagination', + 'horror-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=27&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "documentary", - "documentary-pagination", - "documentary-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=99&sort_by=popularity.desc&vote_count.gte=8`, + 'documentary', + 'documentary-pagination', + 'documentary-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=99&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "animation", - "animation-pagination", - "animation-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=16&sort_by=popularity.desc&vote_count.gte=8`, + 'animation', + 'animation-pagination', + 'animation-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=16&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "sci-fi", - "sci-fi-pagination", - "sci-fi-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=878&sort_by=popularity.desc&vote_count.gte=8`, + 'sci-fi', + 'sci-fi-pagination', + 'sci-fi-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=878&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "romantic", - "romantic-pagination", - "romantic-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10749&sort_by=popularity.desc&vote_count.gte=8`, + 'romantic', + 'romantic-pagination', + 'romantic-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10749&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "thriller", - "thriller-pagination", - "thriller-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=53&sort_by=popularity.desc&vote_count.gte=8`, + 'thriller', + 'thriller-pagination', + 'thriller-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=53&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "mystery", - "mystery-pagination", - "mystery-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=9648&sort_by=popularity.desc&vote_count.gte=8`, + 'mystery', + 'mystery-pagination', + 'mystery-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=9648&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "comedy", - "comedy-pagination", - "comedy-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=35&sort_by=popularity.desc&vote_count.gte=8`, + 'comedy', + 'comedy-pagination', + 'comedy-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=35&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "fantasy", - "fantasy-pagination", - "fantasy-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=14&sort_by=popularity.desc&vote_count.gte=8`, + 'fantasy', + 'fantasy-pagination', + 'fantasy-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=14&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "family", - "family-pagination", - "family-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10751&sort_by=popularity.desc&vote_count.gte=8`, + 'family', + 'family-pagination', + 'family-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10751&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "tv-series", - "tv-series-pagination", - "tv-series-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10770&sort_by=popularity.desc&vote_count.gte=8`, + 'tv-series', + 'tv-series-pagination', + 'tv-series-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10770&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "crime", - "crime-pagination", - "crime-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=80&sort_by=popularity.desc&vote_count.gte=8`, + 'crime', + 'crime-pagination', + 'crime-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=80&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "classic", - "classic-pagination", - "classic-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&sort_by=popularity.desc&release_date.lte=1980`, + 'classic', + 'classic-pagination', + 'classic-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&sort_by=popularity.desc&release_date.lte=1980` ); -document.addEventListener("DOMContentLoaded", function () { +document.addEventListener('DOMContentLoaded', function () { updateSignInButtonState(); - document - .getElementById("googleSignInBtn") - .addEventListener("click", handleSignInOut); + document.getElementById('googleSignInBtn').addEventListener('click', handleSignInOut); }); function handleSearch() { - const searchQuery = document.getElementById("search").value; + const searchQuery = document.getElementById('search').value; - localStorage.setItem("searchQuery", searchQuery); - window.location.href = "MovieVerse-Frontend/html/search.html"; + localStorage.setItem('searchQuery', searchQuery); + window.location.href = 'MovieVerse-Frontend/html/search.html'; } -document.addEventListener("DOMContentLoaded", () => { - const notificationBtn = document.getElementById("notificationBtn"); +document.addEventListener('DOMContentLoaded', () => { + const notificationBtn = document.getElementById('notificationBtn'); - notificationBtn.addEventListener("click", () => { - window.location.href = "MovieVerse-Frontend/html/notifications.html"; + notificationBtn.addEventListener('click', () => { + window.location.href = 'MovieVerse-Frontend/html/notifications.html'; }); }); diff --git a/MovieVerse-Mobile/platforms/android/app/src/main/assets/www/sitemap.xml b/MovieVerse-Mobile/platforms/android/app/src/main/assets/www/sitemap.xml index 513c6ff0..74730b44 100644 --- a/MovieVerse-Mobile/platforms/android/app/src/main/assets/www/sitemap.xml +++ b/MovieVerse-Mobile/platforms/android/app/src/main/assets/www/sitemap.xml @@ -2,137 +2,137 @@ https://movie-verse.com/ - 2024-08-25 + 2024-11-15 1.00 https://movie-verse.com/MovieVerse-Frontend/html/about.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/favorites.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/movie-match.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/movie-timeline.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/notifications.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/chatbot.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/trivia.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/settings.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/chat.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/movie-details.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/director-details.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/actor-details.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/company-details.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/sign-in.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/create-account.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/reset-password.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/privacy-policy.html - 2024-08-25 - 0.60 + 2024-11-15 + 0.80 https://movie-verse.com/MovieVerse-Frontend/html/terms-of-service.html - 2024-08-25 - 0.60 + 2024-11-15 + 0.80 https://movie-verse.com/MovieVerse-Frontend/html/search.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/analytics.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/feedback.html - 2024-08-25 - 0.60 + 2024-11-15 + 0.80 https://movie-verse.com/MovieVerse-Frontend/html/support.html - 2024-08-25 - 0.60 + 2024-11-15 + 0.80 https://movie-verse.com/MovieVerse-Frontend/html/inception.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/user-profile.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/leonardo-dicaprio.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/christopher-nolan.html - 2024-08-25 + 2024-11-15 0.80 diff --git a/MovieVerse-Mobile/platforms/ios/www/MovieVerse-Frontend/css/style.css b/MovieVerse-Mobile/platforms/ios/www/MovieVerse-Frontend/css/style.css index d6261880..f2377a4f 100644 --- a/MovieVerse-Mobile/platforms/ios/www/MovieVerse-Frontend/css/style.css +++ b/MovieVerse-Mobile/platforms/ios/www/MovieVerse-Frontend/css/style.css @@ -1928,7 +1928,6 @@ strong { } #favorite-btn:hover::after { - content: 'Favorite / Unfavorite'; position: absolute; top: -45px; left: 50%; diff --git a/MovieVerse-Mobile/platforms/ios/www/MovieVerse-Frontend/js/favorites.js b/MovieVerse-Mobile/platforms/ios/www/MovieVerse-Frontend/js/favorites.js index d3841f0a..6e4206e5 100644 --- a/MovieVerse-Mobile/platforms/ios/www/MovieVerse-Frontend/js/favorites.js +++ b/MovieVerse-Mobile/platforms/ios/www/MovieVerse-Frontend/js/favorites.js @@ -1369,18 +1369,19 @@ function getClassByRate(vote) { const searchForm = document.getElementById('form'); -searchForm.addEventListener('submit', e => { - e.preventDefault(); - const searchQuery = document.getElementById('search').value; - localStorage.setItem('searchQuery', searchQuery); - window.location.href = 'search.html'; -}); +// searchForm.addEventListener('submit', e => { +// e.preventDefault(); +// const searchQuery = document.getElementById('search').value; +// localStorage.setItem('searchQuery', searchQuery); +// window.location.href = 'search.html'; +// }); function handleSearch() { const searchQuery = document.getElementById('search').value; localStorage.setItem('searchQuery', searchQuery); window.location.href = 'search.html'; } + async function loadWatchLists() { const displaySection = document.getElementById('watchlists-display-section'); @@ -1391,17 +1392,23 @@ async function loadWatchLists() { let watchlists = []; if (currentUserEmail) { - const cachedWatchlists = JSON.parse(localStorage.getItem('cachedWatchlists_' + currentUserEmail)) || []; - if (cachedWatchlists.length > 0) { - watchlists = cachedWatchlists; - } else { + try { + // Attempt to fetch from Firebase first const q = query(collection(db, 'watchlists'), where('userEmail', '==', currentUserEmail)); const querySnapshot = await getDocs(q); watchlists = querySnapshot.docs.map(doc => ({ id: doc.id, ...doc.data(), })); + + // Cache the results if successful localStorage.setItem('cachedWatchlists_' + currentUserEmail, JSON.stringify(watchlists)); + } catch (firebaseError) { + console.warn('Firebase fetch failed, loading from cache:', firebaseError); + + // If Firebase fails, load from cache + const cachedWatchlists = JSON.parse(localStorage.getItem('cachedWatchlists_' + currentUserEmail)) || []; + watchlists = cachedWatchlists; } if (watchlists.length === 0) { @@ -1414,8 +1421,11 @@ async function loadWatchLists() { e.preventDefault(); document.getElementById('watchlist-header').scrollIntoView({ behavior: 'smooth' }); }); + + // Sort by order and pinned status watchlists.sort((a, b) => a.order - b.order); watchlists.sort((a, b) => (b.pinned === a.pinned ? 0 : b.pinned ? 1 : -1)); + for (const watchlist of watchlists) { const watchlistDiv = await createWatchListDiv(watchlist); if (watchlist.pinned) { @@ -1425,6 +1435,7 @@ async function loadWatchLists() { } } } else { + // Handle the case where there is no signed-in user (local watchlists) let localWatchlists = JSON.parse(localStorage.getItem('localWatchlists')) || []; if (localWatchlists.length === 0) { displaySection.innerHTML = '

No watch lists found. Start by adding movies to your watchlist.

'; @@ -1445,193 +1456,80 @@ async function loadWatchLists() { let favorites = []; let favoritesTVSeries = []; + // Load favorites and favoritesTVSeries, first attempting from Firebase and then cache if needed if (currentUserEmail) { - const cachedFavorites = JSON.parse(localStorage.getItem('cachedFavorites_' + currentUserEmail)) || {}; - favorites = cachedFavorites.favorites || []; - favoritesTVSeries = cachedFavorites.favoritesTVSeries || []; - - if (favorites.length === 0 || favoritesTVSeries.length === 0) { + try { + // Attempt to fetch favorites from Firebase const usersRef = query(collection(db, 'MovieVerseUsers'), where('email', '==', currentUserEmail)); const userSnapshot = await getDocs(usersRef); if (!userSnapshot.empty) { const userData = userSnapshot.docs[0].data(); favorites = userData.favoritesMovies || []; favoritesTVSeries = userData.favoritesTVSeries || []; + + // Cache the results if successful localStorage.setItem('cachedFavorites_' + currentUserEmail, JSON.stringify({ favorites, favoritesTVSeries })); } + } catch (firebaseError) { + console.warn('Firebase favorites fetch failed, loading from cache:', firebaseError); + + // If Firebase fails, load from cache + const cachedFavorites = JSON.parse(localStorage.getItem('cachedFavorites_' + currentUserEmail)) || {}; + favorites = cachedFavorites.favorites || []; + favoritesTVSeries = cachedFavorites.favoritesTVSeries || []; } } else { favorites = JSON.parse(localStorage.getItem('moviesFavorited')) || []; favoritesTVSeries = JSON.parse(localStorage.getItem('favoritesTVSeries')) || []; } - if (favorites.length > 0) { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-movies'; - - const title = document.createElement('h3'); - title.textContent = 'Favorite Movies'; - title.className = 'watchlist-title'; - title.style.cursor = 'pointer'; - title.addEventListener('click', () => { - favoritesDiv.scrollIntoView({ behavior: 'smooth' }); - }); - - const description = document.createElement('p'); - description.textContent = 'A collection of your favorite movies.'; - description.className = 'watchlist-description'; - - favoritesDiv.appendChild(title); - favoritesDiv.appendChild(description); - - const moviesContainer = document.createElement('div'); - moviesContainer.className = 'movies-container'; - - const movieCards = await Promise.all(favorites.map(fetchMovieDetails)); - movieCards.forEach(movieCard => moviesContainer.appendChild(movieCard)); - - favoritesDiv.appendChild(moviesContainer); - displaySection.appendChild(favoritesDiv); - } else { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-movies'; - favoritesDiv.innerHTML = - '

Favorite Movies

No favorite movies added yet.

'; - displaySection.appendChild(favoritesDiv); - } - - if (favoritesTVSeries.length > 0) { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-tv-series'; - - const title = document.createElement('h3'); - title.textContent = 'Favorite TV Series'; - title.className = 'watchlist-title'; - title.style.cursor = 'pointer'; - title.addEventListener('click', () => { - favoritesDiv.scrollIntoView({ behavior: 'smooth' }); - }); - - const description = document.createElement('p'); - description.textContent = 'A collection of your favorite TV series.'; - description.className = 'watchlist-description'; - - favoritesDiv.appendChild(title); - favoritesDiv.appendChild(description); - - const moviesContainer = document.createElement('div'); - moviesContainer.className = 'movies-container'; - - const tvSeriesCards = await Promise.all(favoritesTVSeries.map(fetchTVSeriesDetails)); - tvSeriesCards.forEach(tvSeriesCard => moviesContainer.appendChild(tvSeriesCard)); - - favoritesDiv.appendChild(moviesContainer); - displaySection.appendChild(favoritesDiv); - } else { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-tv-series'; - favoritesDiv.innerHTML = - '

Favorite TV Series

No favorite TV series added yet.

'; - displaySection.appendChild(favoritesDiv); - } + // Display Favorites Movies and TV Series sections + displayFavoritesSection('Favorite Movies', favorites, displaySection); + displayFavoritesSection('Favorite TV Series', favoritesTVSeries, displaySection); hideSpinner(); } catch (error) { - if (error.code === 'resource-exhausted') { - let localWatchlists = JSON.parse(localStorage.getItem('localWatchlists')) || []; - if (localWatchlists.length === 0) { - displaySection.innerHTML = '

No watch lists found. Start by adding movies to your watchlist.

'; - } else { - displaySection.innerHTML = ''; - displaySection.innerHTML += '

Your Watch Lists

'; - localWatchlists.sort((a, b) => (b.pinned === a.pinned ? 0 : b.pinned ? 1 : -1)); - for (const watchlist of localWatchlists) { - const watchlistDiv = await createWatchListDiv(watchlist); - if (watchlist.pinned) { - watchlistDiv.classList.add('pinned'); - } - displaySection.appendChild(watchlistDiv); - } - } - - let favorites = JSON.parse(localStorage.getItem('moviesFavorited')) || []; - let favoritesTVSeries = JSON.parse(localStorage.getItem('favoritesTVSeries')) || []; - - if (favorites.length > 0) { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-movies'; - - const title = document.createElement('h3'); - title.textContent = 'Favorite Movies'; - title.className = 'watchlist-title'; - - const description = document.createElement('p'); - description.textContent = 'A collection of your favorite movies.'; - description.className = 'watchlist-description'; - - favoritesDiv.appendChild(title); - favoritesDiv.appendChild(description); - - const moviesContainer = document.createElement('div'); - moviesContainer.className = 'movies-container'; - - const movieCards = await Promise.all(favorites.map(fetchMovieDetails)); - movieCards.forEach(movieCard => moviesContainer.appendChild(movieCard)); - - favoritesDiv.appendChild(moviesContainer); - displaySection.appendChild(favoritesDiv); - } else { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-movies'; - favoritesDiv.innerHTML = - '

Favorite Movies

No favorite movies added yet.

'; - displaySection.appendChild(favoritesDiv); - } - - if (favoritesTVSeries.length > 0) { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-tv-series'; + console.error('An unexpected error occurred:', error); + hideSpinner(); + } +} - const title = document.createElement('h3'); - title.textContent = 'Favorite TV Series'; - title.className = 'watchlist-title'; +// Helper function to display favorite movies/TV series sections +async function displayFavoritesSection(titleText, items, displaySection) { + if (items.length > 0) { + const favoritesDiv = document.createElement('div'); + favoritesDiv.className = 'watchlist'; + favoritesDiv.id = titleText.toLowerCase().replace(' ', '-'); + + const title = document.createElement('h3'); + title.textContent = titleText; + title.className = 'watchlist-title'; + title.style.cursor = 'pointer'; + title.addEventListener('click', () => { + favoritesDiv.scrollIntoView({ behavior: 'smooth' }); + }); - const description = document.createElement('p'); - description.textContent = 'A collection of your favorite TV series.'; - description.className = 'watchlist-description'; + const description = document.createElement('p'); + description.textContent = `A collection of your ${titleText.toLowerCase()}.`; + description.className = 'watchlist-description'; - favoritesDiv.appendChild(title); - favoritesDiv.appendChild(description); + favoritesDiv.appendChild(title); + favoritesDiv.appendChild(description); - const moviesContainer = document.createElement('div'); - moviesContainer.className = 'movies-container'; + const container = document.createElement('div'); + container.className = 'movies-container'; - const tvSeriesCards = await Promise.all(favoritesTVSeries.map(fetchTVSeriesDetails)); - tvSeriesCards.forEach(tvSeriesCard => moviesContainer.appendChild(tvSeriesCard)); + const cards = await Promise.all(items.map(titleText === 'Favorite Movies' ? fetchMovieDetails : fetchTVSeriesDetails)); + cards.forEach(card => container.appendChild(card)); - favoritesDiv.appendChild(moviesContainer); - displaySection.appendChild(favoritesDiv); - hideSpinner(); - } else { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-tv-series'; - favoritesDiv.innerHTML = - '

Favorite TV Series

No favorite TV series added yet.

'; - displaySection.appendChild(favoritesDiv); - hideSpinner(); - } - } else { - console.error('An error occurred:', error); - hideSpinner(); - } + favoritesDiv.appendChild(container); + displaySection.appendChild(favoritesDiv); + } else { + const favoritesDiv = document.createElement('div'); + favoritesDiv.className = 'watchlist'; + favoritesDiv.id = titleText.toLowerCase().replace(' ', '-'); + favoritesDiv.innerHTML = `

${titleText}

No ${titleText.toLowerCase()} added yet.

`; + displaySection.appendChild(favoritesDiv); } } diff --git a/MovieVerse-Mobile/platforms/ios/www/index.html b/MovieVerse-Mobile/platforms/ios/www/index.html index 16f205ea..74a10688 100644 --- a/MovieVerse-Mobile/platforms/ios/www/index.html +++ b/MovieVerse-Mobile/platforms/ios/www/index.html @@ -19,7 +19,7 @@ name="keywords" content="movies, movies verse, film guide, directors, actors, movie genres, cinema, film reviews, tv shows, movie verse, moviesverse, movieverse, moviesvers, film, movie, movieverse.in" /> - + @@ -56,7 +56,6 @@ - - diff --git a/MovieVerse-Mobile/platforms/ios/www/index.js b/MovieVerse-Mobile/platforms/ios/www/index.js index 68445014..f433a1cb 100644 --- a/MovieVerse-Mobile/platforms/ios/www/index.js +++ b/MovieVerse-Mobile/platforms/ios/www/index.js @@ -1,22 +1,22 @@ -const director_main = document.getElementById("director-spotlight"); -const form = document.getElementById("form"); -const search = document.getElementById("search"); -const searchButton = document.getElementById("button-search"); -const searchTitle = document.getElementById("search-title"); -const otherTitle = document.getElementById("other1"); +const director_main = document.getElementById('director-spotlight'); +const form = document.getElementById('form'); +const search = document.getElementById('search'); +const searchButton = document.getElementById('button-search'); +const searchTitle = document.getElementById('search-title'); +const otherTitle = document.getElementById('other1'); function showSpinner() { - document.getElementById("myModal").classList.add("modal-visible"); + document.getElementById('myModal').classList.add('modal-visible'); } function hideSpinner() { - document.getElementById("myModal").classList.remove("modal-visible"); + document.getElementById('myModal').classList.remove('modal-visible'); } -document.addEventListener("DOMContentLoaded", function () { - const pagination = document.getElementById("most-popular-pagination"); - const genresContainer = document.querySelector(".genres"); - const mainContainer = document.getElementById("most-popular"); +document.addEventListener('DOMContentLoaded', function () { + const pagination = document.getElementById('most-popular-pagination'); + const genresContainer = document.querySelector('.genres'); + const mainContainer = document.getElementById('most-popular'); function movePagination() { if (window.innerWidth <= 767) { @@ -27,16 +27,14 @@ document.addEventListener("DOMContentLoaded", function () { } movePagination(); - window.addEventListener("resize", movePagination); + window.addEventListener('resize', movePagination); }); -document.addEventListener("DOMContentLoaded", function () { +document.addEventListener('DOMContentLoaded', function () { let currentPageMostPopular = 1; const totalPages = 320; - const mostPopularMain = document.getElementById("most-popular"); - const paginationContainer = document.getElementById( - "most-popular-pagination", - ); + const mostPopularMain = document.getElementById('most-popular'); + const paginationContainer = document.getElementById('most-popular-pagination'); const fetchAndUpdateMostPopular = () => { const mostPopularUrl = `https://${getMovieVerseData()}/3/movie/popular?${generateMovieNames()}${getMovieCode()}`; @@ -45,16 +43,12 @@ document.addEventListener("DOMContentLoaded", function () { }; const updatePaginationDisplay = () => { - paginationContainer.innerHTML = ""; + paginationContainer.innerHTML = ''; - const prevButton = createNavigationButton( - "<", - currentPageMostPopular > 1, - () => { - currentPageMostPopular--; - fetchAndUpdateMostPopular(); - }, - ); + const prevButton = createNavigationButton('<', currentPageMostPopular > 1, () => { + currentPageMostPopular--; + fetchAndUpdateMostPopular(); + }); paginationContainer.appendChild(prevButton); let startPage = Math.max(currentPageMostPopular - 2, 1); @@ -64,8 +58,7 @@ document.addEventListener("DOMContentLoaded", function () { if (startPage > 1) { paginationContainer.appendChild(createPageButton(1)); - if (startPage > 2) - paginationContainer.appendChild(createPageButton("...")); + if (startPage > 2) paginationContainer.appendChild(createPageButton('...')); } for (let i = startPage; i <= endPage; i++) { @@ -73,27 +66,22 @@ document.addEventListener("DOMContentLoaded", function () { } if (endPage < totalPages) { - if (endPage < totalPages - 1) - paginationContainer.appendChild(createPageButton("...")); + if (endPage < totalPages - 1) paginationContainer.appendChild(createPageButton('...')); paginationContainer.appendChild(createPageButton(totalPages)); } - const nextButton = createNavigationButton( - ">", - currentPageMostPopular < totalPages, - () => { - currentPageMostPopular++; - fetchAndUpdateMostPopular(); - }, - ); + const nextButton = createNavigationButton('>', currentPageMostPopular < totalPages, () => { + currentPageMostPopular++; + fetchAndUpdateMostPopular(); + }); paginationContainer.appendChild(nextButton); }; const createNavigationButton = (text, enabled, clickHandler) => { - const button = document.createElement("button"); + const button = document.createElement('button'); button.innerHTML = text; button.disabled = !enabled; - button.className = "nav-button"; + button.className = 'nav-button'; if (enabled) { button.onclick = clickHandler; @@ -102,12 +90,12 @@ document.addEventListener("DOMContentLoaded", function () { return button; }; - const createPageButton = (pageNum) => { - const button = document.createElement("button"); + const createPageButton = pageNum => { + const button = document.createElement('button'); button.textContent = pageNum; - button.className = "page-button"; + button.className = 'page-button'; - if (pageNum === "...") { + if (pageNum === '...') { button.disabled = true; } else { button.onclick = function () { @@ -116,7 +104,7 @@ document.addEventListener("DOMContentLoaded", function () { }; if (pageNum === currentPageMostPopular) { - button.classList.add("active"); + button.classList.add('active'); } } return button; @@ -125,12 +113,7 @@ document.addEventListener("DOMContentLoaded", function () { fetchAndUpdateMostPopular(); }); -function setupPagination( - mainElementId, - paginationContainerId, - genresContainerId, - baseUrl, -) { +function setupPagination(mainElementId, paginationContainerId, genresContainerId, baseUrl) { let currentPage = 1; let totalPages = 10; @@ -185,7 +168,7 @@ function setupPagination( mainElement.innerHTML = `

No movies found on this page.

`; } } catch (error) { - console.log("Error fetching data: ", error); + console.log('Error fetching data: ', error); mainElement.innerHTML = `

No movies found on this page.

`; } finally { hideSpinner(); @@ -194,9 +177,9 @@ function setupPagination( } const updatePaginationDisplay = () => { - paginationContainer.innerHTML = ""; + paginationContainer.innerHTML = ''; - const prevButton = createNavigationButton("<", currentPage > 1, () => { + const prevButton = createNavigationButton('<', currentPage > 1, () => { currentPage--; fetchAndUpdate(); }); @@ -211,8 +194,7 @@ function setupPagination( if (startPage > 1) { paginationContainer.appendChild(createPageButton(1)); - if (startPage > 2) - paginationContainer.appendChild(createPageButton("...")); + if (startPage > 2) paginationContainer.appendChild(createPageButton('...')); } for (let i = startPage; i <= endPage; i++) { @@ -220,50 +202,45 @@ function setupPagination( } if (endPage < totalPages) { - if (endPage < totalPages - 1) - paginationContainer.appendChild(createPageButton("...")); + if (endPage < totalPages - 1) paginationContainer.appendChild(createPageButton('...')); paginationContainer.appendChild(createPageButton(totalPages)); } - const nextButton = createNavigationButton( - ">", - currentPage < totalPages, - () => { - currentPage++; - fetchAndUpdate(); - }, - ); + const nextButton = createNavigationButton('>', currentPage < totalPages, () => { + currentPage++; + fetchAndUpdate(); + }); paginationContainer.appendChild(nextButton); }; function createNavigationButton(text, enabled, clickHandler) { - const button = document.createElement("button"); + const button = document.createElement('button'); button.textContent = text; button.disabled = !enabled; - button.className = "nav-button"; + button.className = 'nav-button'; if (enabled) { - button.addEventListener("click", clickHandler); + button.addEventListener('click', clickHandler); } return button; } function createPageButton(pageNum) { - const button = document.createElement("button"); + const button = document.createElement('button'); button.textContent = pageNum; - button.className = "page-button"; + button.className = 'page-button'; - if (pageNum === "...") { + if (pageNum === '...') { button.disabled = true; } else { - button.addEventListener("click", () => { - currentPage = typeof pageNum === "number" ? pageNum : currentPage; + button.addEventListener('click', () => { + currentPage = typeof pageNum === 'number' ? pageNum : currentPage; fetchAndUpdate(); }); if (pageNum === currentPage) { - button.classList.add("active"); + button.classList.add('active'); } } return button; @@ -273,7 +250,7 @@ function setupPagination( fetchAndUpdate(); let resizeTimer; - window.addEventListener("resize", () => { + window.addEventListener('resize', () => { clearTimeout(resizeTimer); resizeTimer = setTimeout(movePagination, 250); }); @@ -288,21 +265,16 @@ async function fetchAndDisplayMovies(url, count, mainElement) { showMovies(movies, mainElement); } -document.addEventListener("DOMContentLoaded", async () => { +document.addEventListener('DOMContentLoaded', async () => { let currentPageRecommended = 1; const totalPagesRecommended = 60; - const recommendedMain = document.getElementById("recommended"); - const paginationContainerRecommended = document.getElementById( - "recommended-pagination", - ); - const genresContainer = document.getElementById("recommendedDIV"); + const recommendedMain = document.getElementById('recommended'); + const paginationContainerRecommended = document.getElementById('recommended-pagination'); + const genresContainer = document.getElementById('recommendedDIV'); function movePagination() { if (window.innerWidth <= 767) { - recommendedMain.parentNode.insertBefore( - paginationContainerRecommended, - recommendedMain, - ); + recommendedMain.parentNode.insertBefore(paginationContainerRecommended, recommendedMain); } else { genresContainer.appendChild(paginationContainerRecommended); } @@ -315,7 +287,7 @@ document.addEventListener("DOMContentLoaded", async () => { const mostCommonGenre = getMostCommonGenre(); const mostVisitedMovieGenre = await getMostVisitedMovieGenre(); - recommendedMain.innerHTML = ""; + recommendedMain.innerHTML = ''; if (!mostVisitedMovieGenre || !mostCommonGenre) { recommendedMain.innerHTML = `
@@ -330,29 +302,17 @@ document.addEventListener("DOMContentLoaded", async () => { const commonGenreUrl = `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=${mostCommonGenre}&sort_by=popularity.desc&vote_count.gte=10&page=${currentPageRecommended}`; const visitedGenreUrl = `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=${mostVisitedMovieGenre}&sort_by=popularity.desc&vote_count.gte=10&page=${currentPageRecommended}`; - await fetchAndDisplayMovies( - commonGenreUrl, - totalMoviesToDisplay, - recommendedMain, - ); - await fetchAndDisplayMovies( - visitedGenreUrl, - totalMoviesToDisplay, - recommendedMain, - ); + await fetchAndDisplayMovies(commonGenreUrl, totalMoviesToDisplay, recommendedMain); + await fetchAndDisplayMovies(visitedGenreUrl, totalMoviesToDisplay, recommendedMain); updatePaginationDisplayRecommended(); hideSpinner(); } function updatePaginationDisplayRecommended() { - paginationContainerRecommended.innerHTML = ""; + paginationContainerRecommended.innerHTML = ''; - const prevButton = createNavigationButton( - "<", - currentPageRecommended > 1, - () => generateRecommendations(currentPageRecommended - 1), - ); + const prevButton = createNavigationButton('<', currentPageRecommended > 1, () => generateRecommendations(currentPageRecommended - 1)); paginationContainerRecommended.appendChild(prevButton); let startPage = Math.max(currentPageRecommended - 2, 1); @@ -361,57 +321,43 @@ document.addEventListener("DOMContentLoaded", async () => { if (endPage === totalPagesRecommended) startPage = Math.max(endPage - 4, 1); if (startPage > 1) { - paginationContainerRecommended.appendChild( - createPageButton(1, generateRecommendations), - ); - if (startPage > 2) - paginationContainerRecommended.appendChild(createPageButton("...")); + paginationContainerRecommended.appendChild(createPageButton(1, generateRecommendations)); + if (startPage > 2) paginationContainerRecommended.appendChild(createPageButton('...')); } for (let i = startPage; i <= endPage; i++) { - paginationContainerRecommended.appendChild( - createPageButton( - i, - generateRecommendations, - i === currentPageRecommended, - ), - ); + paginationContainerRecommended.appendChild(createPageButton(i, generateRecommendations, i === currentPageRecommended)); } if (endPage < totalPagesRecommended) { - if (endPage < totalPagesRecommended - 1) - paginationContainerRecommended.appendChild(createPageButton("...")); - paginationContainerRecommended.appendChild( - createPageButton(totalPagesRecommended, generateRecommendations), - ); + if (endPage < totalPagesRecommended - 1) paginationContainerRecommended.appendChild(createPageButton('...')); + paginationContainerRecommended.appendChild(createPageButton(totalPagesRecommended, generateRecommendations)); } - const nextButton = createNavigationButton( - ">", - currentPageRecommended < totalPagesRecommended, - () => generateRecommendations(currentPageRecommended + 1), + const nextButton = createNavigationButton('>', currentPageRecommended < totalPagesRecommended, () => + generateRecommendations(currentPageRecommended + 1) ); paginationContainerRecommended.appendChild(nextButton); } function createNavigationButton(text, enabled, clickHandler) { - const button = document.createElement("button"); + const button = document.createElement('button'); button.innerHTML = text; button.disabled = !enabled; - button.className = "nav-button"; + button.className = 'nav-button'; if (enabled) { - button.addEventListener("click", clickHandler); + button.addEventListener('click', clickHandler); } return button; } function createPageButton(pageNum, fetchFunction, isActive) { - const button = document.createElement("button"); + const button = document.createElement('button'); button.textContent = pageNum; - button.className = "page-button" + (isActive ? " active" : ""); + button.className = 'page-button' + (isActive ? ' active' : ''); - if (pageNum !== "...") { - button.addEventListener("click", () => fetchFunction(pageNum)); + if (pageNum !== '...') { + button.addEventListener('click', () => fetchFunction(pageNum)); } else { button.disabled = true; } @@ -421,7 +367,7 @@ document.addEventListener("DOMContentLoaded", async () => { movePagination(); await generateRecommendations(); - window.addEventListener("resize", movePagination); + window.addEventListener('resize', movePagination); }); async function getMovies(url, mainElement, page = 1) { @@ -452,37 +398,33 @@ async function getMovies(url, mainElement, page = 1) { } async function getAdditionalPosters(movieId) { - const response = await fetch( - `https://${getMovieVerseData()}/3/movie/${movieId}/images?${generateMovieNames()}${getMovieCode()}`, - ); + const response = await fetch(`https://${getMovieVerseData()}/3/movie/${movieId}/images?${generateMovieNames()}${getMovieCode()}`); const data = await response.json(); - return data.posters.map((poster) => poster.file_path); + return data.posters.map(poster => poster.file_path); } function rotateImages(imageElements, interval = 3000) { - const uniqueImageElements = Array.from(imageElements).filter( - (el, index, self) => index === self.findIndex((e) => e.src === el.src), - ); + const uniqueImageElements = Array.from(imageElements).filter((el, index, self) => index === self.findIndex(e => e.src === el.src)); if (uniqueImageElements.length <= 1) return; let currentIndex = 0; - uniqueImageElements[currentIndex].style.opacity = "1"; + uniqueImageElements[currentIndex].style.opacity = '1'; setTimeout(() => { setInterval(() => { - uniqueImageElements[currentIndex].style.opacity = "0"; + uniqueImageElements[currentIndex].style.opacity = '0'; currentIndex = (currentIndex + 1) % uniqueImageElements.length; - uniqueImageElements[currentIndex].style.opacity = "1"; + uniqueImageElements[currentIndex].style.opacity = '1'; }, interval); }, 0); } async function showMovies(movies, mainElement) { - mainElement.innerHTML = ""; + mainElement.innerHTML = ''; // Inject CSS for the sliding-up animation effect with delay support - const style = document.createElement("style"); + const style = document.createElement('style'); style.innerHTML = ` .movie { opacity: 0; @@ -498,23 +440,23 @@ async function showMovies(movies, mainElement) { // Observer to trigger the slide-up animation with a staggered delay const slideObserver = new IntersectionObserver( - (entries) => { + entries => { entries.forEach((entry, index) => { if (entry.isIntersecting) { const movieEl = entry.target; // Apply a staggered delay based on the card's index movieEl.style.transitionDelay = `${index * 100}ms`; // Adjust delay as needed - movieEl.classList.add("visible"); + movieEl.classList.add('visible'); slideObserver.unobserve(movieEl); } }); }, { - rootMargin: "50px 0px", + rootMargin: '50px 0px', threshold: 0.1, - }, + } ); // Observer for background image loading and rotation setup @@ -528,7 +470,7 @@ async function showMovies(movies, mainElement) { // Fetch additional posters and set up rotation in the background const additionalPosters = await getAdditionalPosters(movieId); let allPosters = [movieEl.dataset.posterPath, ...additionalPosters]; - const movieImageContainer = movieEl.querySelector(".movie-images"); + const movieImageContainer = movieEl.querySelector('.movie-images'); allPosters = allPosters.sort(() => 0.5 - Math.random()).slice(0, 10); @@ -536,20 +478,20 @@ async function showMovies(movies, mainElement) { allPosters.forEach((poster, index) => { const img = new Image(); img.src = `${IMGPATH + poster}`; - img.loading = index === 0 ? "eager" : "lazy"; + img.loading = index === 0 ? 'eager' : 'lazy'; img.alt = `${movieEl.dataset.title} poster ${index + 1}`; img.width = 300; img.height = 435; - img.style.position = "absolute"; + img.style.position = 'absolute'; img.style.top = 0; img.style.left = 0; - img.style.transition = "opacity 1s ease-in-out"; - img.style.opacity = "0"; - img.classList.add("poster-img"); + img.style.transition = 'opacity 1s ease-in-out'; + img.style.opacity = '0'; + img.classList.add('poster-img'); movieImageContainer.appendChild(img); img.onload = () => { - if (index === 0) img.style.opacity = "1"; // Show the first image + if (index === 0) img.style.opacity = '1'; // Show the first image }; }); @@ -560,41 +502,32 @@ async function showMovies(movies, mainElement) { } }, { - rootMargin: "50px 0px", + rootMargin: '50px 0px', threshold: 0.1, - }, + } ); movies.forEach((movie, index) => { - let { - id, - poster_path, - title, - vote_average, - vote_count, - overview, - genre_ids, - } = movie; - - const movieEl = document.createElement("div"); - movieEl.style.zIndex = "1000"; - movieEl.classList.add("movie"); + let { id, poster_path, title, vote_average, vote_count, overview, genre_ids } = movie; + + const movieEl = document.createElement('div'); + movieEl.style.zIndex = '1000'; + movieEl.classList.add('movie'); movieEl.dataset.id = id; movieEl.dataset.posterPath = poster_path; movieEl.dataset.title = title; - const words = title.split(" "); + const words = title.split(' '); if (words.length >= 8) { - words[7] = "..."; - title = words.slice(0, 8).join(" "); + words[7] = '...'; + title = words.slice(0, 8).join(' '); } - const voteAvg = vote_count === 0 ? "Unrated" : vote_average.toFixed(1); - const ratingClass = - vote_count === 0 ? "unrated" : getClassByRate(vote_average); + const voteAvg = vote_count === 0 ? 'Unrated' : vote_average.toFixed(1); + const ratingClass = vote_count === 0 ? 'unrated' : getClassByRate(vote_average); - if (overview === "") { - overview = "No overview available."; + if (overview === '') { + overview = 'No overview available.'; } movieEl.innerHTML = ` @@ -612,12 +545,12 @@ async function showMovies(movies, mainElement) { ${overview}
`; - movieEl.addEventListener("click", () => { - localStorage.setItem("selectedMovieId", id); + movieEl.addEventListener('click', () => { + localStorage.setItem('selectedMovieId', id); updateUniqueMoviesViewed(id); updateFavoriteGenre(genre_ids); updateMovieVisitCount(id, title); - window.location.href = "MovieVerse-Frontend/html/movie-details.html"; + window.location.href = 'MovieVerse-Frontend/html/movie-details.html'; }); mainElement.appendChild(movieEl); @@ -632,24 +565,22 @@ async function showMovies(movies, mainElement) { function updateFavoriteGenre(genre_ids) { if (genre_ids && genre_ids.length > 0) { - const favoriteGenres = - JSON.parse(localStorage.getItem("favoriteGenres")) || []; + const favoriteGenres = JSON.parse(localStorage.getItem('favoriteGenres')) || []; favoriteGenres.push(genre_ids[0]); - localStorage.setItem("favoriteGenres", JSON.stringify(favoriteGenres)); + localStorage.setItem('favoriteGenres', JSON.stringify(favoriteGenres)); } } function updateUniqueMoviesViewed(movieId) { - let viewedMovies = - JSON.parse(localStorage.getItem("uniqueMoviesViewed")) || []; + let viewedMovies = JSON.parse(localStorage.getItem('uniqueMoviesViewed')) || []; if (!viewedMovies.includes(movieId)) { viewedMovies.push(movieId); - localStorage.setItem("uniqueMoviesViewed", JSON.stringify(viewedMovies)); + localStorage.setItem('uniqueMoviesViewed', JSON.stringify(viewedMovies)); } } async function ensureGenreMapIsAvailable() { - if (!localStorage.getItem("genreMap")) { + if (!localStorage.getItem('genreMap')) { await fetchGenreMap(); } } @@ -664,9 +595,9 @@ async function fetchGenreMap() { map[genre.id] = genre.name; return map; }, {}); - localStorage.setItem("genreMap", JSON.stringify(genreMap)); + localStorage.setItem('genreMap', JSON.stringify(genreMap)); } catch (error) { - console.log("Error fetching genre map:", error); + console.log('Error fetching genre map:', error); } } @@ -675,51 +606,49 @@ async function rotateUserStats() { const stats = [ { - label: "Your Current Time", + label: 'Your Current Time', getValue: () => { const now = new Date(); let hours = now.getHours(); let minutes = now.getMinutes(); - hours = hours < 10 ? "0" + hours : hours; - minutes = minutes < 10 ? "0" + minutes : minutes; + hours = hours < 10 ? '0' + hours : hours; + minutes = minutes < 10 ? '0' + minutes : minutes; return `${hours}:${minutes}`; }, }, - { label: "Most Visited Movie", getValue: getMostVisitedMovie }, - { label: "Most Visited Director", getValue: getMostVisitedDirector }, - { label: "Most Visited Actor", getValue: getMostVisitedActor }, + { label: 'Most Visited Movie', getValue: getMostVisitedMovie }, + { label: 'Most Visited Director', getValue: getMostVisitedDirector }, + { label: 'Most Visited Actor', getValue: getMostVisitedActor }, { - label: "Movies Discovered", + label: 'Movies Discovered', getValue: () => { - const viewedMovies = - JSON.parse(localStorage.getItem("uniqueMoviesViewed")) || []; + const viewedMovies = JSON.parse(localStorage.getItem('uniqueMoviesViewed')) || []; return viewedMovies.length; }, }, { - label: "Favorite Movies", + label: 'Favorite Movies', getValue: () => { - const favoritedMovies = - JSON.parse(localStorage.getItem("moviesFavorited")) || []; + const favoritedMovies = JSON.parse(localStorage.getItem('moviesFavorited')) || []; return favoritedMovies.length; }, }, { - label: "Favorite Genre", + label: 'Favorite Genre', getValue: () => { const mostCommonGenreCode = getMostCommonGenre(); - const genreMapString = localStorage.getItem("genreMap"); + const genreMapString = localStorage.getItem('genreMap'); if (!genreMapString) { - console.log("No genre map found in localStorage."); - return "Not Available"; + console.log('No genre map found in localStorage.'); + return 'Not Available'; } let genreMap; try { genreMap = JSON.parse(genreMapString); } catch (e) { - console.log("Error parsing genre map:", e); - return "Not Available"; + console.log('Error parsing genre map:', e); + return 'Not Available'; } let genreObject; @@ -728,81 +657,74 @@ async function rotateUserStats() { acc[genre.id] = genre.name; return acc; }, {}); - } else if (typeof genreMap === "object" && genreMap !== null) { + } else if (typeof genreMap === 'object' && genreMap !== null) { genreObject = genreMap; } else { - console.log( - "genreMap is neither an array nor a proper object:", - genreMap, - ); - return "Not Available"; + console.log('genreMap is neither an array nor a proper object:', genreMap); + return 'Not Available'; } - return genreObject[mostCommonGenreCode] || "Not Available"; + return genreObject[mostCommonGenreCode] || 'Not Available'; }, }, { - label: "Watchlists Created", - getValue: () => localStorage.getItem("watchlistsCreated") || 0, + label: 'Watchlists Created', + getValue: () => localStorage.getItem('watchlistsCreated') || 0, }, { - label: "Average Movie Rating", - getValue: () => localStorage.getItem("averageMovieRating") || "Not Rated", + label: 'Average Movie Rating', + getValue: () => localStorage.getItem('averageMovieRating') || 'Not Rated', }, { - label: "Directors Discovered", + label: 'Directors Discovered', getValue: () => { - const viewedDirectors = - JSON.parse(localStorage.getItem("uniqueDirectorsViewed")) || []; + const viewedDirectors = JSON.parse(localStorage.getItem('uniqueDirectorsViewed')) || []; return viewedDirectors.length; }, }, { - label: "Actors Discovered", + label: 'Actors Discovered', getValue: () => { - const viewedActors = - JSON.parse(localStorage.getItem("uniqueActorsViewed")) || []; + const viewedActors = JSON.parse(localStorage.getItem('uniqueActorsViewed')) || []; return viewedActors.length; }, }, - { label: "Your Trivia Accuracy", getValue: getTriviaAccuracy }, + { label: 'Your Trivia Accuracy', getValue: getTriviaAccuracy }, ]; let currentStatIndex = 0; function updateStatDisplay() { const currentStat = stats[currentStatIndex]; - document.getElementById("stats-label").textContent = - currentStat.label + ":"; - document.getElementById("stats-display").textContent = - currentStat.getValue(); + document.getElementById('stats-label').textContent = currentStat.label + ':'; + document.getElementById('stats-display').textContent = currentStat.getValue(); currentStatIndex = (currentStatIndex + 1) % stats.length; } updateStatDisplay(); - const localTimeDiv = document.getElementById("local-time"); + const localTimeDiv = document.getElementById('local-time'); let statRotationInterval = setInterval(updateStatDisplay, 3000); - localTimeDiv.addEventListener("click", () => { + localTimeDiv.addEventListener('click', () => { clearInterval(statRotationInterval); updateStatDisplay(); statRotationInterval = setInterval(updateStatDisplay, 3000); - localTimeDiv.scrollIntoView({ behavior: "smooth" }); + localTimeDiv.scrollIntoView({ behavior: 'smooth' }); }); } function updateMovieVisitCount(movieId, movieTitle) { - let movieVisits = JSON.parse(localStorage.getItem("movieVisits")) || {}; + let movieVisits = JSON.parse(localStorage.getItem('movieVisits')) || {}; if (!movieVisits[movieId]) { movieVisits[movieId] = { count: 0, title: movieTitle }; } movieVisits[movieId].count += 1; - localStorage.setItem("movieVisits", JSON.stringify(movieVisits)); + localStorage.setItem('movieVisits', JSON.stringify(movieVisits)); } function getMostVisitedMovie() { - const movieVisits = JSON.parse(localStorage.getItem("movieVisits")) || {}; - let mostVisitedMovie = ""; + const movieVisits = JSON.parse(localStorage.getItem('movieVisits')) || {}; + let mostVisitedMovie = ''; let maxVisits = 0; for (const movieId in movieVisits) { @@ -812,11 +734,11 @@ function getMostVisitedMovie() { } } - return mostVisitedMovie || "Not Available"; + return mostVisitedMovie || 'Not Available'; } async function getMostVisitedMovieGenre() { - const movieVisits = JSON.parse(localStorage.getItem("movieVisits")) || {}; + const movieVisits = JSON.parse(localStorage.getItem('movieVisits')) || {}; let mostVisitedGenre = null; let maxVisits = 0; @@ -839,8 +761,8 @@ async function fetchGenreForMovie(movieId) { } function getMostVisitedActor() { - const actorVisits = JSON.parse(localStorage.getItem("actorVisits")) || {}; - let mostVisitedActor = ""; + const actorVisits = JSON.parse(localStorage.getItem('actorVisits')) || {}; + let mostVisitedActor = ''; let maxVisits = 0; for (const actorId in actorVisits) { @@ -850,13 +772,12 @@ function getMostVisitedActor() { } } - return mostVisitedActor || "Not Available"; + return mostVisitedActor || 'Not Available'; } function getMostVisitedDirector() { - const directorVisits = - JSON.parse(localStorage.getItem("directorVisits")) || {}; - let mostVisitedDirector = ""; + const directorVisits = JSON.parse(localStorage.getItem('directorVisits')) || {}; + let mostVisitedDirector = ''; let maxVisits = 0; for (const directorId in directorVisits) { @@ -865,16 +786,16 @@ function getMostVisitedDirector() { maxVisits = directorVisits[directorId].count; } } - return mostVisitedDirector || "Not Available"; + return mostVisitedDirector || 'Not Available'; } function getTriviaAccuracy() { - let triviaStats = JSON.parse(localStorage.getItem("triviaStats")) || { + let triviaStats = JSON.parse(localStorage.getItem('triviaStats')) || { totalCorrect: 0, totalAttempted: 0, }; if (triviaStats.totalAttempted === 0) { - return "No trivia attempted"; + return 'No trivia attempted'; } let accuracy = (triviaStats.totalCorrect / triviaStats.totalAttempted) * 100; @@ -882,14 +803,13 @@ function getTriviaAccuracy() { } function getMostCommonGenre() { - const favoriteGenresArray = - JSON.parse(localStorage.getItem("favoriteGenres")) || []; + const favoriteGenresArray = JSON.parse(localStorage.getItem('favoriteGenres')) || []; const genreCounts = favoriteGenresArray.reduce((acc, genre) => { acc[genre] = (acc[genre] || 0) + 1; return acc; }, {}); - let mostCommonGenre = ""; + let mostCommonGenre = ''; let maxCount = 0; for (const genre in genreCounts) { @@ -899,16 +819,16 @@ function getMostCommonGenre() { } } - return mostCommonGenre || "Not Available"; + return mostCommonGenre || 'Not Available'; } const movieCode = { - part1: "YzVhMjBjODY=", - part2: "MWFjZjdiYjg=", - part3: "ZDllOTg3ZGNjN2YxYjU1OA==", + part1: 'YzVhMjBjODY=', + part2: 'MWFjZjdiYjg=', + part3: 'ZDllOTg3ZGNjN2YxYjU1OA==', }; -document.addEventListener("DOMContentLoaded", rotateUserStats); +document.addEventListener('DOMContentLoaded', rotateUserStats); async function showMovieOfTheDay() { const year = new Date().getFullYear(); @@ -921,28 +841,26 @@ async function showMovieOfTheDay() { if (movies.length > 0) { const randomMovie = movies[Math.floor(Math.random() * movies.length)]; - localStorage.setItem("selectedMovieId", randomMovie.id); - window.location.href = "MovieVerse-Frontend/html/movie-details.html"; + localStorage.setItem('selectedMovieId', randomMovie.id); + window.location.href = 'MovieVerse-Frontend/html/movie-details.html'; } else { fallbackMovieSelection(); } } catch (error) { - console.log("Error fetching movie:", error); + console.log('Error fetching movie:', error); fallbackMovieSelection(); } } function fallbackMovieSelection() { const fallbackMovies = [ - 432413, 299534, 1726, 562, 118340, 455207, 493922, 447332, 22970, 530385, - 27205, 264660, 120467, 603, 577922, 76341, 539, 419704, 515001, 118340, 424, - 98, + 432413, 299534, 1726, 562, 118340, 455207, 493922, 447332, 22970, 530385, 27205, 264660, 120467, 603, 577922, 76341, 539, 419704, 515001, 118340, + 424, 98, ]; - const randomFallbackMovie = - fallbackMovies[Math.floor(Math.random() * fallbackMovies.length)]; + const randomFallbackMovie = fallbackMovies[Math.floor(Math.random() * fallbackMovies.length)]; - localStorage.setItem("selectedMovieId", randomFallbackMovie); - window.location.href = "MovieVerse-Frontend/html/movie-details.html"; + localStorage.setItem('selectedMovieId', randomFallbackMovie); + window.location.href = 'MovieVerse-Frontend/html/movie-details.html'; } function calculateMoviesToDisplay() { @@ -976,75 +894,71 @@ function calculateMoviesToDisplay() { function getClassByRate(vote) { if (vote >= 8) { - return "green"; + return 'green'; } else if (vote >= 5) { - return "orange"; + return 'orange'; } else { - return "red"; + return 'red'; } } -form.addEventListener("submit", (e) => { +form.addEventListener('submit', e => { e.preventDefault(); - const searchQuery = document.getElementById("search").value; + const searchQuery = document.getElementById('search').value; - localStorage.setItem("searchQuery", searchQuery); - window.location.href = "MovieVerse-Frontend/html/search.html"; + localStorage.setItem('searchQuery', searchQuery); + window.location.href = 'MovieVerse-Frontend/html/search.html'; }); function toggleNav() { - const sideNav = document.getElementById("side-nav"); + const sideNav = document.getElementById('side-nav'); - sideNav.classList.toggle("manual-toggle"); + sideNav.classList.toggle('manual-toggle'); adjustNavBar(); } function removeNavBar() { - const sideNav = document.getElementById("side-nav"); + const sideNav = document.getElementById('side-nav'); - if (sideNav.classList.contains("manual-toggle")) { - sideNav.classList.remove("manual-toggle"); + if (sideNav.classList.contains('manual-toggle')) { + sideNav.classList.remove('manual-toggle'); } adjustNavBar(); } function adjustNavBar() { - const sideNav = document.getElementById("side-nav"); + const sideNav = document.getElementById('side-nav'); - if (sideNav.classList.contains("manual-toggle")) { - sideNav.style.left = "0px"; + if (sideNav.classList.contains('manual-toggle')) { + sideNav.style.left = '0px'; } else { - sideNav.style.left = "-250px"; + sideNav.style.left = '-250px'; } } -document.addEventListener("mousemove", function (event) { - const sideNav = document.getElementById("side-nav"); +document.addEventListener('mousemove', function (event) { + const sideNav = document.getElementById('side-nav'); - if (event.clientX < 10 && !sideNav.classList.contains("manual-toggle")) { - sideNav.style.left = "0"; + if (event.clientX < 10 && !sideNav.classList.contains('manual-toggle')) { + sideNav.style.left = '0'; } }); -document.addEventListener("click", function (event) { - const sideNav = document.getElementById("side-nav"); - const navToggle = document.getElementById("nav-toggle"); +document.addEventListener('click', function (event) { + const sideNav = document.getElementById('side-nav'); + const navToggle = document.getElementById('nav-toggle'); - if ( - !sideNav.contains(event.target) && - !navToggle.contains(event.target) && - sideNav.classList.contains("manual-toggle") - ) { - sideNav.classList.remove("manual-toggle"); + if (!sideNav.contains(event.target) && !navToggle.contains(event.target) && sideNav.classList.contains('manual-toggle')) { + sideNav.classList.remove('manual-toggle'); adjustNavBar(); } }); -document.getElementById("side-nav").addEventListener("mouseleave", function () { - const sideNav = document.getElementById("side-nav"); +document.getElementById('side-nav').addEventListener('mouseleave', function () { + const sideNav = document.getElementById('side-nav'); - if (!sideNav.classList.contains("manual-toggle")) { - sideNav.style.left = "-250px"; + if (!sideNav.classList.contains('manual-toggle')) { + sideNav.style.left = '-250px'; } }); @@ -1053,32 +967,32 @@ const IMGPATH = `https://image.tmdb.org/t/p/w500`; const SEARCHPATH = `https://${getMovieVerseData()}/3/search/movie?&${generateMovieNames()}${getMovieCode()}&query=`; const directors = [ - { name: "Alfred Hitchcock", id: "2636" }, - { name: "Steven Spielberg", id: "488" }, - { name: "Martin Scorsese", id: "1032" }, - { name: "Quentin Tarantino", id: "138" }, - { name: "Christopher Nolan", id: "525" }, - { name: "Stanley Kubrick", id: "240" }, - { name: "Bong Joon-ho", id: "21684" }, - { name: "David Fincher", id: "7467" }, - { name: "James Cameron", id: "2710" }, - { name: "Francis Ford Coppola", id: "1776" }, - { name: "Tim Burton", id: "510" }, - { name: "Ridley Scott", id: "578" }, - { name: "Joel Coen", id: "1223" }, - { name: "Spike Lee", id: "5281" }, - { name: "Woody Allen", id: "1243" }, - { name: "Peter Jackson", id: "108" }, - { name: "Oliver Stone", id: "1152" }, - { name: "David Lynch", id: "5602" }, - { name: "Roman Polanski", id: "3556" }, - { name: "Wes Anderson", id: "5655" }, - { name: "Sergio Leone", id: "4385" }, - { name: "Akira Kurosawa", id: "5026" }, - { name: "Federico Fellini", id: "4415" }, - { name: "John Ford", id: "8500" }, - { name: "Fritz Lang", id: "68" }, - { name: "Frank Capra", id: "2662" }, + { name: 'Alfred Hitchcock', id: '2636' }, + { name: 'Steven Spielberg', id: '488' }, + { name: 'Martin Scorsese', id: '1032' }, + { name: 'Quentin Tarantino', id: '138' }, + { name: 'Christopher Nolan', id: '525' }, + { name: 'Stanley Kubrick', id: '240' }, + { name: 'Bong Joon-ho', id: '21684' }, + { name: 'David Fincher', id: '7467' }, + { name: 'James Cameron', id: '2710' }, + { name: 'Francis Ford Coppola', id: '1776' }, + { name: 'Tim Burton', id: '510' }, + { name: 'Ridley Scott', id: '578' }, + { name: 'Joel Coen', id: '1223' }, + { name: 'Spike Lee', id: '5281' }, + { name: 'Woody Allen', id: '1243' }, + { name: 'Peter Jackson', id: '108' }, + { name: 'Oliver Stone', id: '1152' }, + { name: 'David Lynch', id: '5602' }, + { name: 'Roman Polanski', id: '3556' }, + { name: 'Wes Anderson', id: '5655' }, + { name: 'Sergio Leone', id: '4385' }, + { name: 'Akira Kurosawa', id: '5026' }, + { name: 'Federico Fellini', id: '4415' }, + { name: 'John Ford', id: '8500' }, + { name: 'Fritz Lang', id: '68' }, + { name: 'Frank Capra', id: '2662' }, ]; let currentDirectorIndex = 0; @@ -1097,8 +1011,7 @@ setInterval(changeDirector, 3600000); function updateDirectorSpotlight() { const director = directors[currentDirectorIndex]; - document.getElementById("spotlight-director-name").textContent = - director.name; + document.getElementById('spotlight-director-name').textContent = director.name; const url = `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_people=${ director.id @@ -1107,26 +1020,7 @@ function updateDirectorSpotlight() { } function getMovieVerseData(input) { - return String.fromCharCode( - 97, - 112, - 105, - 46, - 116, - 104, - 101, - 109, - 111, - 118, - 105, - 101, - 100, - 98, - 46, - 111, - 114, - 103, - ); + return String.fromCharCode(97, 112, 105, 46, 116, 104, 101, 109, 111, 118, 105, 101, 100, 98, 46, 111, 114, 103); } function generateMovieNames(input) { @@ -1150,10 +1044,10 @@ async function getDirectorSpotlight(url) { } function showMoviesDirectorSpotlight(movies) { - director_main.innerHTML = ""; + director_main.innerHTML = ''; // Inject CSS for the sliding-up animation effect with delay support - const style = document.createElement("style"); + const style = document.createElement('style'); style.innerHTML = ` .movie { opacity: 0; @@ -1169,40 +1063,39 @@ function showMoviesDirectorSpotlight(movies) { // Observer to trigger the slide-up animation with a staggered delay const slideObserver = new IntersectionObserver( - (entries) => { + entries => { entries.forEach((entry, index) => { if (entry.isIntersecting) { const movieEl = entry.target; // Apply a staggered delay based on the card's index movieEl.style.transitionDelay = `${index * 100}ms`; // Adjust delay as needed - movieEl.classList.add("visible"); + movieEl.classList.add('visible'); slideObserver.unobserve(movieEl); } }); }, { - rootMargin: "50px 0px", + rootMargin: '50px 0px', threshold: 0.1, - }, + } ); movies.forEach((movie, index) => { const { id, poster_path, title, vote_average, genre_ids } = movie; - const movieEl = document.createElement("div"); + const movieEl = document.createElement('div'); - movieEl.classList.add("movie"); - movieEl.style.zIndex = "1000"; + movieEl.classList.add('movie'); + movieEl.style.zIndex = '1000'; // Movie image and fallback in case the image is unavailable const movieImage = poster_path ? `${title}` : `
Image Not Available
`; - const voteAvg = vote_average > 0 ? vote_average.toFixed(1) : "Unrated"; - const ratingClass = - vote_average > 0 ? getClassByRate(vote_average) : "unrated"; + const voteAvg = vote_average > 0 ? vote_average.toFixed(1) : 'Unrated'; + const ratingClass = vote_average > 0 ? getClassByRate(vote_average) : 'unrated'; movieEl.innerHTML = ` ${movieImage} @@ -1215,12 +1108,12 @@ function showMoviesDirectorSpotlight(movies) { ${movie.overview} `; - movieEl.addEventListener("click", () => { - localStorage.setItem("selectedMovieId", id); + movieEl.addEventListener('click', () => { + localStorage.setItem('selectedMovieId', id); updateUniqueMoviesViewed(id); updateFavoriteGenre(genre_ids); updateMovieVisitCount(id, title); - window.location.href = "MovieVerse-Frontend/html/movie-details.html"; + window.location.href = 'MovieVerse-Frontend/html/movie-details.html'; }); director_main.appendChild(movieEl); @@ -1231,13 +1124,13 @@ function showMoviesDirectorSpotlight(movies) { } function handleSignInOut() { - const isSignedIn = JSON.parse(localStorage.getItem("isSignedIn")) || false; + const isSignedIn = JSON.parse(localStorage.getItem('isSignedIn')) || false; if (isSignedIn) { - localStorage.setItem("isSignedIn", JSON.stringify(false)); - alert("You have been signed out."); + localStorage.setItem('isSignedIn', JSON.stringify(false)); + alert('You have been signed out.'); } else { - window.location.href = "MovieVerse-Frontend/html/sign-in.html"; + window.location.href = 'MovieVerse-Frontend/html/sign-in.html'; return; } @@ -1245,215 +1138,213 @@ function handleSignInOut() { } function updateSignInButtonState() { - const isSignedIn = JSON.parse(localStorage.getItem("isSignedIn")) || false; - const signInText = document.getElementById("signInOutText"); - const signInIcon = document.getElementById("signInIcon"); - const signOutIcon = document.getElementById("signOutIcon"); + const isSignedIn = JSON.parse(localStorage.getItem('isSignedIn')) || false; + const signInText = document.getElementById('signInOutText'); + const signInIcon = document.getElementById('signInIcon'); + const signOutIcon = document.getElementById('signOutIcon'); if (isSignedIn) { - signInText.textContent = "Sign Out"; - signInIcon.style.display = "none"; - signOutIcon.style.display = "inline-block"; + signInText.textContent = 'Sign Out'; + signInIcon.style.display = 'none'; + signOutIcon.style.display = 'inline-block'; } else { - signInText.textContent = "Sign In"; - signInIcon.style.display = "inline-block"; - signOutIcon.style.display = "none"; + signInText.textContent = 'Sign In'; + signInIcon.style.display = 'inline-block'; + signOutIcon.style.display = 'none'; } - const mobileSignInText = document.getElementById("mobileSignInOutText"); - const mobileSignInIcon = document.getElementById("mobileSignInIcon"); - const mobileSignOutIcon = document.getElementById("mobileSignOutIcon"); + const mobileSignInText = document.getElementById('mobileSignInOutText'); + const mobileSignInIcon = document.getElementById('mobileSignInIcon'); + const mobileSignOutIcon = document.getElementById('mobileSignOutIcon'); if (isSignedIn) { - mobileSignInText.textContent = "Sign Out"; - mobileSignInIcon.style.display = "none"; - mobileSignOutIcon.style.display = "inline-block"; + mobileSignInText.textContent = 'Sign Out'; + mobileSignInIcon.style.display = 'none'; + mobileSignOutIcon.style.display = 'inline-block'; } else { - mobileSignInText.textContent = "Sign In"; - mobileSignInIcon.style.display = "inline-block"; - mobileSignOutIcon.style.display = "none"; + mobileSignInText.textContent = 'Sign In'; + mobileSignInIcon.style.display = 'inline-block'; + mobileSignOutIcon.style.display = 'none'; } } setupPagination( - "award-winning", - "award-winning-pagination", - "award-winning-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&sort_by=vote_average.desc&vote_count.gte=1000`, + 'award-winning', + 'award-winning-pagination', + 'award-winning-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&sort_by=vote_average.desc&vote_count.gte=1000` ); setupPagination( - "hidden-gems", - "hidden-gems-pagination", - "hidden-gems-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&sort_by=vote_average.desc&vote_count.gte=100&vote_average.gte=7&popularity.lte=10`, + 'hidden-gems', + 'hidden-gems-pagination', + 'hidden-gems-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&sort_by=vote_average.desc&vote_count.gte=100&vote_average.gte=7&popularity.lte=10` ); setupPagination( - "western", - "western-pagination", - "western-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=37&sort_by=popularity.desc&vote_count.gte=8`, + 'western', + 'western-pagination', + 'western-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=37&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "war", - "war-pagination", - "war-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10752&sort_by=popularity.desc&vote_count.gte=8`, + 'war', + 'war-pagination', + 'war-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10752&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "vietnamese", - "vietnamese-pagination", - "vietnamese-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_original_language=vi&sort_by=popularity.desc`, + 'vietnamese', + 'vietnamese-pagination', + 'vietnamese-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_original_language=vi&sort_by=popularity.desc` ); setupPagination( - "korean", - "korean-pagination", - "korean-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_original_language=ko&sort_by=vote_average.desc,popularity.desc&vote_count.gte=10&vote_average.gte=8`, + 'korean', + 'korean-pagination', + 'korean-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_original_language=ko&sort_by=vote_average.desc,popularity.desc&vote_count.gte=10&vote_average.gte=8` ); setupPagination( - "musical", - "musical-pagination", - "musical-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10402&sort_by=popularity.desc&vote_count.gte=8`, + 'musical', + 'musical-pagination', + 'musical-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10402&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "drama", - "drama-pagination", - "drama-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=18&sort_by=popularity.desc&vote_count.gte=8`, + 'drama', + 'drama-pagination', + 'drama-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=18&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "indian", - "indian-pagination", - "indian-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_original_language=hi&sort_by=popularity.desc`, + 'indian', + 'indian-pagination', + 'indian-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_original_language=hi&sort_by=popularity.desc` ); setupPagination( - "action", - "action-pagination", - "action-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=28&sort_by=popularity.desc&vote_count.gte=8`, + 'action', + 'action-pagination', + 'action-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=28&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "horror", - "horror-pagination", - "horror-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=27&sort_by=popularity.desc&vote_count.gte=8`, + 'horror', + 'horror-pagination', + 'horror-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=27&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "documentary", - "documentary-pagination", - "documentary-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=99&sort_by=popularity.desc&vote_count.gte=8`, + 'documentary', + 'documentary-pagination', + 'documentary-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=99&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "animation", - "animation-pagination", - "animation-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=16&sort_by=popularity.desc&vote_count.gte=8`, + 'animation', + 'animation-pagination', + 'animation-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=16&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "sci-fi", - "sci-fi-pagination", - "sci-fi-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=878&sort_by=popularity.desc&vote_count.gte=8`, + 'sci-fi', + 'sci-fi-pagination', + 'sci-fi-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=878&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "romantic", - "romantic-pagination", - "romantic-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10749&sort_by=popularity.desc&vote_count.gte=8`, + 'romantic', + 'romantic-pagination', + 'romantic-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10749&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "thriller", - "thriller-pagination", - "thriller-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=53&sort_by=popularity.desc&vote_count.gte=8`, + 'thriller', + 'thriller-pagination', + 'thriller-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=53&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "mystery", - "mystery-pagination", - "mystery-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=9648&sort_by=popularity.desc&vote_count.gte=8`, + 'mystery', + 'mystery-pagination', + 'mystery-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=9648&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "comedy", - "comedy-pagination", - "comedy-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=35&sort_by=popularity.desc&vote_count.gte=8`, + 'comedy', + 'comedy-pagination', + 'comedy-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=35&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "fantasy", - "fantasy-pagination", - "fantasy-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=14&sort_by=popularity.desc&vote_count.gte=8`, + 'fantasy', + 'fantasy-pagination', + 'fantasy-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=14&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "family", - "family-pagination", - "family-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10751&sort_by=popularity.desc&vote_count.gte=8`, + 'family', + 'family-pagination', + 'family-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10751&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "tv-series", - "tv-series-pagination", - "tv-series-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10770&sort_by=popularity.desc&vote_count.gte=8`, + 'tv-series', + 'tv-series-pagination', + 'tv-series-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10770&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "crime", - "crime-pagination", - "crime-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=80&sort_by=popularity.desc&vote_count.gte=8`, + 'crime', + 'crime-pagination', + 'crime-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=80&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "classic", - "classic-pagination", - "classic-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&sort_by=popularity.desc&release_date.lte=1980`, + 'classic', + 'classic-pagination', + 'classic-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&sort_by=popularity.desc&release_date.lte=1980` ); -document.addEventListener("DOMContentLoaded", function () { +document.addEventListener('DOMContentLoaded', function () { updateSignInButtonState(); - document - .getElementById("googleSignInBtn") - .addEventListener("click", handleSignInOut); + document.getElementById('googleSignInBtn').addEventListener('click', handleSignInOut); }); function handleSearch() { - const searchQuery = document.getElementById("search").value; + const searchQuery = document.getElementById('search').value; - localStorage.setItem("searchQuery", searchQuery); - window.location.href = "MovieVerse-Frontend/html/search.html"; + localStorage.setItem('searchQuery', searchQuery); + window.location.href = 'MovieVerse-Frontend/html/search.html'; } -document.addEventListener("DOMContentLoaded", () => { - const notificationBtn = document.getElementById("notificationBtn"); +document.addEventListener('DOMContentLoaded', () => { + const notificationBtn = document.getElementById('notificationBtn'); - notificationBtn.addEventListener("click", () => { - window.location.href = "MovieVerse-Frontend/html/notifications.html"; + notificationBtn.addEventListener('click', () => { + window.location.href = 'MovieVerse-Frontend/html/notifications.html'; }); }); diff --git a/MovieVerse-Mobile/platforms/ios/www/sitemap.xml b/MovieVerse-Mobile/platforms/ios/www/sitemap.xml index 513c6ff0..74730b44 100644 --- a/MovieVerse-Mobile/platforms/ios/www/sitemap.xml +++ b/MovieVerse-Mobile/platforms/ios/www/sitemap.xml @@ -2,137 +2,137 @@ https://movie-verse.com/ - 2024-08-25 + 2024-11-15 1.00 https://movie-verse.com/MovieVerse-Frontend/html/about.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/favorites.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/movie-match.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/movie-timeline.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/notifications.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/chatbot.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/trivia.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/settings.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/chat.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/movie-details.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/director-details.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/actor-details.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/company-details.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/sign-in.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/create-account.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/reset-password.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/privacy-policy.html - 2024-08-25 - 0.60 + 2024-11-15 + 0.80 https://movie-verse.com/MovieVerse-Frontend/html/terms-of-service.html - 2024-08-25 - 0.60 + 2024-11-15 + 0.80 https://movie-verse.com/MovieVerse-Frontend/html/search.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/analytics.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/feedback.html - 2024-08-25 - 0.60 + 2024-11-15 + 0.80 https://movie-verse.com/MovieVerse-Frontend/html/support.html - 2024-08-25 - 0.60 + 2024-11-15 + 0.80 https://movie-verse.com/MovieVerse-Frontend/html/inception.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/user-profile.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/leonardo-dicaprio.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/christopher-nolan.html - 2024-08-25 + 2024-11-15 0.80 diff --git a/MovieVerse-Mobile/www/MovieVerse-Frontend/css/style.css b/MovieVerse-Mobile/www/MovieVerse-Frontend/css/style.css index d6261880..f2377a4f 100644 --- a/MovieVerse-Mobile/www/MovieVerse-Frontend/css/style.css +++ b/MovieVerse-Mobile/www/MovieVerse-Frontend/css/style.css @@ -1928,7 +1928,6 @@ strong { } #favorite-btn:hover::after { - content: 'Favorite / Unfavorite'; position: absolute; top: -45px; left: 50%; diff --git a/MovieVerse-Mobile/www/MovieVerse-Frontend/js/favorites.js b/MovieVerse-Mobile/www/MovieVerse-Frontend/js/favorites.js index d3841f0a..6e4206e5 100644 --- a/MovieVerse-Mobile/www/MovieVerse-Frontend/js/favorites.js +++ b/MovieVerse-Mobile/www/MovieVerse-Frontend/js/favorites.js @@ -1369,18 +1369,19 @@ function getClassByRate(vote) { const searchForm = document.getElementById('form'); -searchForm.addEventListener('submit', e => { - e.preventDefault(); - const searchQuery = document.getElementById('search').value; - localStorage.setItem('searchQuery', searchQuery); - window.location.href = 'search.html'; -}); +// searchForm.addEventListener('submit', e => { +// e.preventDefault(); +// const searchQuery = document.getElementById('search').value; +// localStorage.setItem('searchQuery', searchQuery); +// window.location.href = 'search.html'; +// }); function handleSearch() { const searchQuery = document.getElementById('search').value; localStorage.setItem('searchQuery', searchQuery); window.location.href = 'search.html'; } + async function loadWatchLists() { const displaySection = document.getElementById('watchlists-display-section'); @@ -1391,17 +1392,23 @@ async function loadWatchLists() { let watchlists = []; if (currentUserEmail) { - const cachedWatchlists = JSON.parse(localStorage.getItem('cachedWatchlists_' + currentUserEmail)) || []; - if (cachedWatchlists.length > 0) { - watchlists = cachedWatchlists; - } else { + try { + // Attempt to fetch from Firebase first const q = query(collection(db, 'watchlists'), where('userEmail', '==', currentUserEmail)); const querySnapshot = await getDocs(q); watchlists = querySnapshot.docs.map(doc => ({ id: doc.id, ...doc.data(), })); + + // Cache the results if successful localStorage.setItem('cachedWatchlists_' + currentUserEmail, JSON.stringify(watchlists)); + } catch (firebaseError) { + console.warn('Firebase fetch failed, loading from cache:', firebaseError); + + // If Firebase fails, load from cache + const cachedWatchlists = JSON.parse(localStorage.getItem('cachedWatchlists_' + currentUserEmail)) || []; + watchlists = cachedWatchlists; } if (watchlists.length === 0) { @@ -1414,8 +1421,11 @@ async function loadWatchLists() { e.preventDefault(); document.getElementById('watchlist-header').scrollIntoView({ behavior: 'smooth' }); }); + + // Sort by order and pinned status watchlists.sort((a, b) => a.order - b.order); watchlists.sort((a, b) => (b.pinned === a.pinned ? 0 : b.pinned ? 1 : -1)); + for (const watchlist of watchlists) { const watchlistDiv = await createWatchListDiv(watchlist); if (watchlist.pinned) { @@ -1425,6 +1435,7 @@ async function loadWatchLists() { } } } else { + // Handle the case where there is no signed-in user (local watchlists) let localWatchlists = JSON.parse(localStorage.getItem('localWatchlists')) || []; if (localWatchlists.length === 0) { displaySection.innerHTML = '

No watch lists found. Start by adding movies to your watchlist.

'; @@ -1445,193 +1456,80 @@ async function loadWatchLists() { let favorites = []; let favoritesTVSeries = []; + // Load favorites and favoritesTVSeries, first attempting from Firebase and then cache if needed if (currentUserEmail) { - const cachedFavorites = JSON.parse(localStorage.getItem('cachedFavorites_' + currentUserEmail)) || {}; - favorites = cachedFavorites.favorites || []; - favoritesTVSeries = cachedFavorites.favoritesTVSeries || []; - - if (favorites.length === 0 || favoritesTVSeries.length === 0) { + try { + // Attempt to fetch favorites from Firebase const usersRef = query(collection(db, 'MovieVerseUsers'), where('email', '==', currentUserEmail)); const userSnapshot = await getDocs(usersRef); if (!userSnapshot.empty) { const userData = userSnapshot.docs[0].data(); favorites = userData.favoritesMovies || []; favoritesTVSeries = userData.favoritesTVSeries || []; + + // Cache the results if successful localStorage.setItem('cachedFavorites_' + currentUserEmail, JSON.stringify({ favorites, favoritesTVSeries })); } + } catch (firebaseError) { + console.warn('Firebase favorites fetch failed, loading from cache:', firebaseError); + + // If Firebase fails, load from cache + const cachedFavorites = JSON.parse(localStorage.getItem('cachedFavorites_' + currentUserEmail)) || {}; + favorites = cachedFavorites.favorites || []; + favoritesTVSeries = cachedFavorites.favoritesTVSeries || []; } } else { favorites = JSON.parse(localStorage.getItem('moviesFavorited')) || []; favoritesTVSeries = JSON.parse(localStorage.getItem('favoritesTVSeries')) || []; } - if (favorites.length > 0) { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-movies'; - - const title = document.createElement('h3'); - title.textContent = 'Favorite Movies'; - title.className = 'watchlist-title'; - title.style.cursor = 'pointer'; - title.addEventListener('click', () => { - favoritesDiv.scrollIntoView({ behavior: 'smooth' }); - }); - - const description = document.createElement('p'); - description.textContent = 'A collection of your favorite movies.'; - description.className = 'watchlist-description'; - - favoritesDiv.appendChild(title); - favoritesDiv.appendChild(description); - - const moviesContainer = document.createElement('div'); - moviesContainer.className = 'movies-container'; - - const movieCards = await Promise.all(favorites.map(fetchMovieDetails)); - movieCards.forEach(movieCard => moviesContainer.appendChild(movieCard)); - - favoritesDiv.appendChild(moviesContainer); - displaySection.appendChild(favoritesDiv); - } else { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-movies'; - favoritesDiv.innerHTML = - '

Favorite Movies

No favorite movies added yet.

'; - displaySection.appendChild(favoritesDiv); - } - - if (favoritesTVSeries.length > 0) { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-tv-series'; - - const title = document.createElement('h3'); - title.textContent = 'Favorite TV Series'; - title.className = 'watchlist-title'; - title.style.cursor = 'pointer'; - title.addEventListener('click', () => { - favoritesDiv.scrollIntoView({ behavior: 'smooth' }); - }); - - const description = document.createElement('p'); - description.textContent = 'A collection of your favorite TV series.'; - description.className = 'watchlist-description'; - - favoritesDiv.appendChild(title); - favoritesDiv.appendChild(description); - - const moviesContainer = document.createElement('div'); - moviesContainer.className = 'movies-container'; - - const tvSeriesCards = await Promise.all(favoritesTVSeries.map(fetchTVSeriesDetails)); - tvSeriesCards.forEach(tvSeriesCard => moviesContainer.appendChild(tvSeriesCard)); - - favoritesDiv.appendChild(moviesContainer); - displaySection.appendChild(favoritesDiv); - } else { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-tv-series'; - favoritesDiv.innerHTML = - '

Favorite TV Series

No favorite TV series added yet.

'; - displaySection.appendChild(favoritesDiv); - } + // Display Favorites Movies and TV Series sections + displayFavoritesSection('Favorite Movies', favorites, displaySection); + displayFavoritesSection('Favorite TV Series', favoritesTVSeries, displaySection); hideSpinner(); } catch (error) { - if (error.code === 'resource-exhausted') { - let localWatchlists = JSON.parse(localStorage.getItem('localWatchlists')) || []; - if (localWatchlists.length === 0) { - displaySection.innerHTML = '

No watch lists found. Start by adding movies to your watchlist.

'; - } else { - displaySection.innerHTML = ''; - displaySection.innerHTML += '

Your Watch Lists

'; - localWatchlists.sort((a, b) => (b.pinned === a.pinned ? 0 : b.pinned ? 1 : -1)); - for (const watchlist of localWatchlists) { - const watchlistDiv = await createWatchListDiv(watchlist); - if (watchlist.pinned) { - watchlistDiv.classList.add('pinned'); - } - displaySection.appendChild(watchlistDiv); - } - } - - let favorites = JSON.parse(localStorage.getItem('moviesFavorited')) || []; - let favoritesTVSeries = JSON.parse(localStorage.getItem('favoritesTVSeries')) || []; - - if (favorites.length > 0) { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-movies'; - - const title = document.createElement('h3'); - title.textContent = 'Favorite Movies'; - title.className = 'watchlist-title'; - - const description = document.createElement('p'); - description.textContent = 'A collection of your favorite movies.'; - description.className = 'watchlist-description'; - - favoritesDiv.appendChild(title); - favoritesDiv.appendChild(description); - - const moviesContainer = document.createElement('div'); - moviesContainer.className = 'movies-container'; - - const movieCards = await Promise.all(favorites.map(fetchMovieDetails)); - movieCards.forEach(movieCard => moviesContainer.appendChild(movieCard)); - - favoritesDiv.appendChild(moviesContainer); - displaySection.appendChild(favoritesDiv); - } else { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-movies'; - favoritesDiv.innerHTML = - '

Favorite Movies

No favorite movies added yet.

'; - displaySection.appendChild(favoritesDiv); - } - - if (favoritesTVSeries.length > 0) { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-tv-series'; + console.error('An unexpected error occurred:', error); + hideSpinner(); + } +} - const title = document.createElement('h3'); - title.textContent = 'Favorite TV Series'; - title.className = 'watchlist-title'; +// Helper function to display favorite movies/TV series sections +async function displayFavoritesSection(titleText, items, displaySection) { + if (items.length > 0) { + const favoritesDiv = document.createElement('div'); + favoritesDiv.className = 'watchlist'; + favoritesDiv.id = titleText.toLowerCase().replace(' ', '-'); + + const title = document.createElement('h3'); + title.textContent = titleText; + title.className = 'watchlist-title'; + title.style.cursor = 'pointer'; + title.addEventListener('click', () => { + favoritesDiv.scrollIntoView({ behavior: 'smooth' }); + }); - const description = document.createElement('p'); - description.textContent = 'A collection of your favorite TV series.'; - description.className = 'watchlist-description'; + const description = document.createElement('p'); + description.textContent = `A collection of your ${titleText.toLowerCase()}.`; + description.className = 'watchlist-description'; - favoritesDiv.appendChild(title); - favoritesDiv.appendChild(description); + favoritesDiv.appendChild(title); + favoritesDiv.appendChild(description); - const moviesContainer = document.createElement('div'); - moviesContainer.className = 'movies-container'; + const container = document.createElement('div'); + container.className = 'movies-container'; - const tvSeriesCards = await Promise.all(favoritesTVSeries.map(fetchTVSeriesDetails)); - tvSeriesCards.forEach(tvSeriesCard => moviesContainer.appendChild(tvSeriesCard)); + const cards = await Promise.all(items.map(titleText === 'Favorite Movies' ? fetchMovieDetails : fetchTVSeriesDetails)); + cards.forEach(card => container.appendChild(card)); - favoritesDiv.appendChild(moviesContainer); - displaySection.appendChild(favoritesDiv); - hideSpinner(); - } else { - const favoritesDiv = document.createElement('div'); - favoritesDiv.className = 'watchlist'; - favoritesDiv.id = 'favorite-tv-series'; - favoritesDiv.innerHTML = - '

Favorite TV Series

No favorite TV series added yet.

'; - displaySection.appendChild(favoritesDiv); - hideSpinner(); - } - } else { - console.error('An error occurred:', error); - hideSpinner(); - } + favoritesDiv.appendChild(container); + displaySection.appendChild(favoritesDiv); + } else { + const favoritesDiv = document.createElement('div'); + favoritesDiv.className = 'watchlist'; + favoritesDiv.id = titleText.toLowerCase().replace(' ', '-'); + favoritesDiv.innerHTML = `

${titleText}

No ${titleText.toLowerCase()} added yet.

`; + displaySection.appendChild(favoritesDiv); } } diff --git a/MovieVerse-Mobile/www/index.html b/MovieVerse-Mobile/www/index.html index 16f205ea..74a10688 100644 --- a/MovieVerse-Mobile/www/index.html +++ b/MovieVerse-Mobile/www/index.html @@ -19,7 +19,7 @@ name="keywords" content="movies, movies verse, film guide, directors, actors, movie genres, cinema, film reviews, tv shows, movie verse, moviesverse, movieverse, moviesvers, film, movie, movieverse.in" /> - + @@ -56,7 +56,6 @@ - - diff --git a/MovieVerse-Mobile/www/index.js b/MovieVerse-Mobile/www/index.js index 68445014..f433a1cb 100644 --- a/MovieVerse-Mobile/www/index.js +++ b/MovieVerse-Mobile/www/index.js @@ -1,22 +1,22 @@ -const director_main = document.getElementById("director-spotlight"); -const form = document.getElementById("form"); -const search = document.getElementById("search"); -const searchButton = document.getElementById("button-search"); -const searchTitle = document.getElementById("search-title"); -const otherTitle = document.getElementById("other1"); +const director_main = document.getElementById('director-spotlight'); +const form = document.getElementById('form'); +const search = document.getElementById('search'); +const searchButton = document.getElementById('button-search'); +const searchTitle = document.getElementById('search-title'); +const otherTitle = document.getElementById('other1'); function showSpinner() { - document.getElementById("myModal").classList.add("modal-visible"); + document.getElementById('myModal').classList.add('modal-visible'); } function hideSpinner() { - document.getElementById("myModal").classList.remove("modal-visible"); + document.getElementById('myModal').classList.remove('modal-visible'); } -document.addEventListener("DOMContentLoaded", function () { - const pagination = document.getElementById("most-popular-pagination"); - const genresContainer = document.querySelector(".genres"); - const mainContainer = document.getElementById("most-popular"); +document.addEventListener('DOMContentLoaded', function () { + const pagination = document.getElementById('most-popular-pagination'); + const genresContainer = document.querySelector('.genres'); + const mainContainer = document.getElementById('most-popular'); function movePagination() { if (window.innerWidth <= 767) { @@ -27,16 +27,14 @@ document.addEventListener("DOMContentLoaded", function () { } movePagination(); - window.addEventListener("resize", movePagination); + window.addEventListener('resize', movePagination); }); -document.addEventListener("DOMContentLoaded", function () { +document.addEventListener('DOMContentLoaded', function () { let currentPageMostPopular = 1; const totalPages = 320; - const mostPopularMain = document.getElementById("most-popular"); - const paginationContainer = document.getElementById( - "most-popular-pagination", - ); + const mostPopularMain = document.getElementById('most-popular'); + const paginationContainer = document.getElementById('most-popular-pagination'); const fetchAndUpdateMostPopular = () => { const mostPopularUrl = `https://${getMovieVerseData()}/3/movie/popular?${generateMovieNames()}${getMovieCode()}`; @@ -45,16 +43,12 @@ document.addEventListener("DOMContentLoaded", function () { }; const updatePaginationDisplay = () => { - paginationContainer.innerHTML = ""; + paginationContainer.innerHTML = ''; - const prevButton = createNavigationButton( - "<", - currentPageMostPopular > 1, - () => { - currentPageMostPopular--; - fetchAndUpdateMostPopular(); - }, - ); + const prevButton = createNavigationButton('<', currentPageMostPopular > 1, () => { + currentPageMostPopular--; + fetchAndUpdateMostPopular(); + }); paginationContainer.appendChild(prevButton); let startPage = Math.max(currentPageMostPopular - 2, 1); @@ -64,8 +58,7 @@ document.addEventListener("DOMContentLoaded", function () { if (startPage > 1) { paginationContainer.appendChild(createPageButton(1)); - if (startPage > 2) - paginationContainer.appendChild(createPageButton("...")); + if (startPage > 2) paginationContainer.appendChild(createPageButton('...')); } for (let i = startPage; i <= endPage; i++) { @@ -73,27 +66,22 @@ document.addEventListener("DOMContentLoaded", function () { } if (endPage < totalPages) { - if (endPage < totalPages - 1) - paginationContainer.appendChild(createPageButton("...")); + if (endPage < totalPages - 1) paginationContainer.appendChild(createPageButton('...')); paginationContainer.appendChild(createPageButton(totalPages)); } - const nextButton = createNavigationButton( - ">", - currentPageMostPopular < totalPages, - () => { - currentPageMostPopular++; - fetchAndUpdateMostPopular(); - }, - ); + const nextButton = createNavigationButton('>', currentPageMostPopular < totalPages, () => { + currentPageMostPopular++; + fetchAndUpdateMostPopular(); + }); paginationContainer.appendChild(nextButton); }; const createNavigationButton = (text, enabled, clickHandler) => { - const button = document.createElement("button"); + const button = document.createElement('button'); button.innerHTML = text; button.disabled = !enabled; - button.className = "nav-button"; + button.className = 'nav-button'; if (enabled) { button.onclick = clickHandler; @@ -102,12 +90,12 @@ document.addEventListener("DOMContentLoaded", function () { return button; }; - const createPageButton = (pageNum) => { - const button = document.createElement("button"); + const createPageButton = pageNum => { + const button = document.createElement('button'); button.textContent = pageNum; - button.className = "page-button"; + button.className = 'page-button'; - if (pageNum === "...") { + if (pageNum === '...') { button.disabled = true; } else { button.onclick = function () { @@ -116,7 +104,7 @@ document.addEventListener("DOMContentLoaded", function () { }; if (pageNum === currentPageMostPopular) { - button.classList.add("active"); + button.classList.add('active'); } } return button; @@ -125,12 +113,7 @@ document.addEventListener("DOMContentLoaded", function () { fetchAndUpdateMostPopular(); }); -function setupPagination( - mainElementId, - paginationContainerId, - genresContainerId, - baseUrl, -) { +function setupPagination(mainElementId, paginationContainerId, genresContainerId, baseUrl) { let currentPage = 1; let totalPages = 10; @@ -185,7 +168,7 @@ function setupPagination( mainElement.innerHTML = `

No movies found on this page.

`; } } catch (error) { - console.log("Error fetching data: ", error); + console.log('Error fetching data: ', error); mainElement.innerHTML = `

No movies found on this page.

`; } finally { hideSpinner(); @@ -194,9 +177,9 @@ function setupPagination( } const updatePaginationDisplay = () => { - paginationContainer.innerHTML = ""; + paginationContainer.innerHTML = ''; - const prevButton = createNavigationButton("<", currentPage > 1, () => { + const prevButton = createNavigationButton('<', currentPage > 1, () => { currentPage--; fetchAndUpdate(); }); @@ -211,8 +194,7 @@ function setupPagination( if (startPage > 1) { paginationContainer.appendChild(createPageButton(1)); - if (startPage > 2) - paginationContainer.appendChild(createPageButton("...")); + if (startPage > 2) paginationContainer.appendChild(createPageButton('...')); } for (let i = startPage; i <= endPage; i++) { @@ -220,50 +202,45 @@ function setupPagination( } if (endPage < totalPages) { - if (endPage < totalPages - 1) - paginationContainer.appendChild(createPageButton("...")); + if (endPage < totalPages - 1) paginationContainer.appendChild(createPageButton('...')); paginationContainer.appendChild(createPageButton(totalPages)); } - const nextButton = createNavigationButton( - ">", - currentPage < totalPages, - () => { - currentPage++; - fetchAndUpdate(); - }, - ); + const nextButton = createNavigationButton('>', currentPage < totalPages, () => { + currentPage++; + fetchAndUpdate(); + }); paginationContainer.appendChild(nextButton); }; function createNavigationButton(text, enabled, clickHandler) { - const button = document.createElement("button"); + const button = document.createElement('button'); button.textContent = text; button.disabled = !enabled; - button.className = "nav-button"; + button.className = 'nav-button'; if (enabled) { - button.addEventListener("click", clickHandler); + button.addEventListener('click', clickHandler); } return button; } function createPageButton(pageNum) { - const button = document.createElement("button"); + const button = document.createElement('button'); button.textContent = pageNum; - button.className = "page-button"; + button.className = 'page-button'; - if (pageNum === "...") { + if (pageNum === '...') { button.disabled = true; } else { - button.addEventListener("click", () => { - currentPage = typeof pageNum === "number" ? pageNum : currentPage; + button.addEventListener('click', () => { + currentPage = typeof pageNum === 'number' ? pageNum : currentPage; fetchAndUpdate(); }); if (pageNum === currentPage) { - button.classList.add("active"); + button.classList.add('active'); } } return button; @@ -273,7 +250,7 @@ function setupPagination( fetchAndUpdate(); let resizeTimer; - window.addEventListener("resize", () => { + window.addEventListener('resize', () => { clearTimeout(resizeTimer); resizeTimer = setTimeout(movePagination, 250); }); @@ -288,21 +265,16 @@ async function fetchAndDisplayMovies(url, count, mainElement) { showMovies(movies, mainElement); } -document.addEventListener("DOMContentLoaded", async () => { +document.addEventListener('DOMContentLoaded', async () => { let currentPageRecommended = 1; const totalPagesRecommended = 60; - const recommendedMain = document.getElementById("recommended"); - const paginationContainerRecommended = document.getElementById( - "recommended-pagination", - ); - const genresContainer = document.getElementById("recommendedDIV"); + const recommendedMain = document.getElementById('recommended'); + const paginationContainerRecommended = document.getElementById('recommended-pagination'); + const genresContainer = document.getElementById('recommendedDIV'); function movePagination() { if (window.innerWidth <= 767) { - recommendedMain.parentNode.insertBefore( - paginationContainerRecommended, - recommendedMain, - ); + recommendedMain.parentNode.insertBefore(paginationContainerRecommended, recommendedMain); } else { genresContainer.appendChild(paginationContainerRecommended); } @@ -315,7 +287,7 @@ document.addEventListener("DOMContentLoaded", async () => { const mostCommonGenre = getMostCommonGenre(); const mostVisitedMovieGenre = await getMostVisitedMovieGenre(); - recommendedMain.innerHTML = ""; + recommendedMain.innerHTML = ''; if (!mostVisitedMovieGenre || !mostCommonGenre) { recommendedMain.innerHTML = `
@@ -330,29 +302,17 @@ document.addEventListener("DOMContentLoaded", async () => { const commonGenreUrl = `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=${mostCommonGenre}&sort_by=popularity.desc&vote_count.gte=10&page=${currentPageRecommended}`; const visitedGenreUrl = `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=${mostVisitedMovieGenre}&sort_by=popularity.desc&vote_count.gte=10&page=${currentPageRecommended}`; - await fetchAndDisplayMovies( - commonGenreUrl, - totalMoviesToDisplay, - recommendedMain, - ); - await fetchAndDisplayMovies( - visitedGenreUrl, - totalMoviesToDisplay, - recommendedMain, - ); + await fetchAndDisplayMovies(commonGenreUrl, totalMoviesToDisplay, recommendedMain); + await fetchAndDisplayMovies(visitedGenreUrl, totalMoviesToDisplay, recommendedMain); updatePaginationDisplayRecommended(); hideSpinner(); } function updatePaginationDisplayRecommended() { - paginationContainerRecommended.innerHTML = ""; + paginationContainerRecommended.innerHTML = ''; - const prevButton = createNavigationButton( - "<", - currentPageRecommended > 1, - () => generateRecommendations(currentPageRecommended - 1), - ); + const prevButton = createNavigationButton('<', currentPageRecommended > 1, () => generateRecommendations(currentPageRecommended - 1)); paginationContainerRecommended.appendChild(prevButton); let startPage = Math.max(currentPageRecommended - 2, 1); @@ -361,57 +321,43 @@ document.addEventListener("DOMContentLoaded", async () => { if (endPage === totalPagesRecommended) startPage = Math.max(endPage - 4, 1); if (startPage > 1) { - paginationContainerRecommended.appendChild( - createPageButton(1, generateRecommendations), - ); - if (startPage > 2) - paginationContainerRecommended.appendChild(createPageButton("...")); + paginationContainerRecommended.appendChild(createPageButton(1, generateRecommendations)); + if (startPage > 2) paginationContainerRecommended.appendChild(createPageButton('...')); } for (let i = startPage; i <= endPage; i++) { - paginationContainerRecommended.appendChild( - createPageButton( - i, - generateRecommendations, - i === currentPageRecommended, - ), - ); + paginationContainerRecommended.appendChild(createPageButton(i, generateRecommendations, i === currentPageRecommended)); } if (endPage < totalPagesRecommended) { - if (endPage < totalPagesRecommended - 1) - paginationContainerRecommended.appendChild(createPageButton("...")); - paginationContainerRecommended.appendChild( - createPageButton(totalPagesRecommended, generateRecommendations), - ); + if (endPage < totalPagesRecommended - 1) paginationContainerRecommended.appendChild(createPageButton('...')); + paginationContainerRecommended.appendChild(createPageButton(totalPagesRecommended, generateRecommendations)); } - const nextButton = createNavigationButton( - ">", - currentPageRecommended < totalPagesRecommended, - () => generateRecommendations(currentPageRecommended + 1), + const nextButton = createNavigationButton('>', currentPageRecommended < totalPagesRecommended, () => + generateRecommendations(currentPageRecommended + 1) ); paginationContainerRecommended.appendChild(nextButton); } function createNavigationButton(text, enabled, clickHandler) { - const button = document.createElement("button"); + const button = document.createElement('button'); button.innerHTML = text; button.disabled = !enabled; - button.className = "nav-button"; + button.className = 'nav-button'; if (enabled) { - button.addEventListener("click", clickHandler); + button.addEventListener('click', clickHandler); } return button; } function createPageButton(pageNum, fetchFunction, isActive) { - const button = document.createElement("button"); + const button = document.createElement('button'); button.textContent = pageNum; - button.className = "page-button" + (isActive ? " active" : ""); + button.className = 'page-button' + (isActive ? ' active' : ''); - if (pageNum !== "...") { - button.addEventListener("click", () => fetchFunction(pageNum)); + if (pageNum !== '...') { + button.addEventListener('click', () => fetchFunction(pageNum)); } else { button.disabled = true; } @@ -421,7 +367,7 @@ document.addEventListener("DOMContentLoaded", async () => { movePagination(); await generateRecommendations(); - window.addEventListener("resize", movePagination); + window.addEventListener('resize', movePagination); }); async function getMovies(url, mainElement, page = 1) { @@ -452,37 +398,33 @@ async function getMovies(url, mainElement, page = 1) { } async function getAdditionalPosters(movieId) { - const response = await fetch( - `https://${getMovieVerseData()}/3/movie/${movieId}/images?${generateMovieNames()}${getMovieCode()}`, - ); + const response = await fetch(`https://${getMovieVerseData()}/3/movie/${movieId}/images?${generateMovieNames()}${getMovieCode()}`); const data = await response.json(); - return data.posters.map((poster) => poster.file_path); + return data.posters.map(poster => poster.file_path); } function rotateImages(imageElements, interval = 3000) { - const uniqueImageElements = Array.from(imageElements).filter( - (el, index, self) => index === self.findIndex((e) => e.src === el.src), - ); + const uniqueImageElements = Array.from(imageElements).filter((el, index, self) => index === self.findIndex(e => e.src === el.src)); if (uniqueImageElements.length <= 1) return; let currentIndex = 0; - uniqueImageElements[currentIndex].style.opacity = "1"; + uniqueImageElements[currentIndex].style.opacity = '1'; setTimeout(() => { setInterval(() => { - uniqueImageElements[currentIndex].style.opacity = "0"; + uniqueImageElements[currentIndex].style.opacity = '0'; currentIndex = (currentIndex + 1) % uniqueImageElements.length; - uniqueImageElements[currentIndex].style.opacity = "1"; + uniqueImageElements[currentIndex].style.opacity = '1'; }, interval); }, 0); } async function showMovies(movies, mainElement) { - mainElement.innerHTML = ""; + mainElement.innerHTML = ''; // Inject CSS for the sliding-up animation effect with delay support - const style = document.createElement("style"); + const style = document.createElement('style'); style.innerHTML = ` .movie { opacity: 0; @@ -498,23 +440,23 @@ async function showMovies(movies, mainElement) { // Observer to trigger the slide-up animation with a staggered delay const slideObserver = new IntersectionObserver( - (entries) => { + entries => { entries.forEach((entry, index) => { if (entry.isIntersecting) { const movieEl = entry.target; // Apply a staggered delay based on the card's index movieEl.style.transitionDelay = `${index * 100}ms`; // Adjust delay as needed - movieEl.classList.add("visible"); + movieEl.classList.add('visible'); slideObserver.unobserve(movieEl); } }); }, { - rootMargin: "50px 0px", + rootMargin: '50px 0px', threshold: 0.1, - }, + } ); // Observer for background image loading and rotation setup @@ -528,7 +470,7 @@ async function showMovies(movies, mainElement) { // Fetch additional posters and set up rotation in the background const additionalPosters = await getAdditionalPosters(movieId); let allPosters = [movieEl.dataset.posterPath, ...additionalPosters]; - const movieImageContainer = movieEl.querySelector(".movie-images"); + const movieImageContainer = movieEl.querySelector('.movie-images'); allPosters = allPosters.sort(() => 0.5 - Math.random()).slice(0, 10); @@ -536,20 +478,20 @@ async function showMovies(movies, mainElement) { allPosters.forEach((poster, index) => { const img = new Image(); img.src = `${IMGPATH + poster}`; - img.loading = index === 0 ? "eager" : "lazy"; + img.loading = index === 0 ? 'eager' : 'lazy'; img.alt = `${movieEl.dataset.title} poster ${index + 1}`; img.width = 300; img.height = 435; - img.style.position = "absolute"; + img.style.position = 'absolute'; img.style.top = 0; img.style.left = 0; - img.style.transition = "opacity 1s ease-in-out"; - img.style.opacity = "0"; - img.classList.add("poster-img"); + img.style.transition = 'opacity 1s ease-in-out'; + img.style.opacity = '0'; + img.classList.add('poster-img'); movieImageContainer.appendChild(img); img.onload = () => { - if (index === 0) img.style.opacity = "1"; // Show the first image + if (index === 0) img.style.opacity = '1'; // Show the first image }; }); @@ -560,41 +502,32 @@ async function showMovies(movies, mainElement) { } }, { - rootMargin: "50px 0px", + rootMargin: '50px 0px', threshold: 0.1, - }, + } ); movies.forEach((movie, index) => { - let { - id, - poster_path, - title, - vote_average, - vote_count, - overview, - genre_ids, - } = movie; - - const movieEl = document.createElement("div"); - movieEl.style.zIndex = "1000"; - movieEl.classList.add("movie"); + let { id, poster_path, title, vote_average, vote_count, overview, genre_ids } = movie; + + const movieEl = document.createElement('div'); + movieEl.style.zIndex = '1000'; + movieEl.classList.add('movie'); movieEl.dataset.id = id; movieEl.dataset.posterPath = poster_path; movieEl.dataset.title = title; - const words = title.split(" "); + const words = title.split(' '); if (words.length >= 8) { - words[7] = "..."; - title = words.slice(0, 8).join(" "); + words[7] = '...'; + title = words.slice(0, 8).join(' '); } - const voteAvg = vote_count === 0 ? "Unrated" : vote_average.toFixed(1); - const ratingClass = - vote_count === 0 ? "unrated" : getClassByRate(vote_average); + const voteAvg = vote_count === 0 ? 'Unrated' : vote_average.toFixed(1); + const ratingClass = vote_count === 0 ? 'unrated' : getClassByRate(vote_average); - if (overview === "") { - overview = "No overview available."; + if (overview === '') { + overview = 'No overview available.'; } movieEl.innerHTML = ` @@ -612,12 +545,12 @@ async function showMovies(movies, mainElement) { ${overview}
`; - movieEl.addEventListener("click", () => { - localStorage.setItem("selectedMovieId", id); + movieEl.addEventListener('click', () => { + localStorage.setItem('selectedMovieId', id); updateUniqueMoviesViewed(id); updateFavoriteGenre(genre_ids); updateMovieVisitCount(id, title); - window.location.href = "MovieVerse-Frontend/html/movie-details.html"; + window.location.href = 'MovieVerse-Frontend/html/movie-details.html'; }); mainElement.appendChild(movieEl); @@ -632,24 +565,22 @@ async function showMovies(movies, mainElement) { function updateFavoriteGenre(genre_ids) { if (genre_ids && genre_ids.length > 0) { - const favoriteGenres = - JSON.parse(localStorage.getItem("favoriteGenres")) || []; + const favoriteGenres = JSON.parse(localStorage.getItem('favoriteGenres')) || []; favoriteGenres.push(genre_ids[0]); - localStorage.setItem("favoriteGenres", JSON.stringify(favoriteGenres)); + localStorage.setItem('favoriteGenres', JSON.stringify(favoriteGenres)); } } function updateUniqueMoviesViewed(movieId) { - let viewedMovies = - JSON.parse(localStorage.getItem("uniqueMoviesViewed")) || []; + let viewedMovies = JSON.parse(localStorage.getItem('uniqueMoviesViewed')) || []; if (!viewedMovies.includes(movieId)) { viewedMovies.push(movieId); - localStorage.setItem("uniqueMoviesViewed", JSON.stringify(viewedMovies)); + localStorage.setItem('uniqueMoviesViewed', JSON.stringify(viewedMovies)); } } async function ensureGenreMapIsAvailable() { - if (!localStorage.getItem("genreMap")) { + if (!localStorage.getItem('genreMap')) { await fetchGenreMap(); } } @@ -664,9 +595,9 @@ async function fetchGenreMap() { map[genre.id] = genre.name; return map; }, {}); - localStorage.setItem("genreMap", JSON.stringify(genreMap)); + localStorage.setItem('genreMap', JSON.stringify(genreMap)); } catch (error) { - console.log("Error fetching genre map:", error); + console.log('Error fetching genre map:', error); } } @@ -675,51 +606,49 @@ async function rotateUserStats() { const stats = [ { - label: "Your Current Time", + label: 'Your Current Time', getValue: () => { const now = new Date(); let hours = now.getHours(); let minutes = now.getMinutes(); - hours = hours < 10 ? "0" + hours : hours; - minutes = minutes < 10 ? "0" + minutes : minutes; + hours = hours < 10 ? '0' + hours : hours; + minutes = minutes < 10 ? '0' + minutes : minutes; return `${hours}:${minutes}`; }, }, - { label: "Most Visited Movie", getValue: getMostVisitedMovie }, - { label: "Most Visited Director", getValue: getMostVisitedDirector }, - { label: "Most Visited Actor", getValue: getMostVisitedActor }, + { label: 'Most Visited Movie', getValue: getMostVisitedMovie }, + { label: 'Most Visited Director', getValue: getMostVisitedDirector }, + { label: 'Most Visited Actor', getValue: getMostVisitedActor }, { - label: "Movies Discovered", + label: 'Movies Discovered', getValue: () => { - const viewedMovies = - JSON.parse(localStorage.getItem("uniqueMoviesViewed")) || []; + const viewedMovies = JSON.parse(localStorage.getItem('uniqueMoviesViewed')) || []; return viewedMovies.length; }, }, { - label: "Favorite Movies", + label: 'Favorite Movies', getValue: () => { - const favoritedMovies = - JSON.parse(localStorage.getItem("moviesFavorited")) || []; + const favoritedMovies = JSON.parse(localStorage.getItem('moviesFavorited')) || []; return favoritedMovies.length; }, }, { - label: "Favorite Genre", + label: 'Favorite Genre', getValue: () => { const mostCommonGenreCode = getMostCommonGenre(); - const genreMapString = localStorage.getItem("genreMap"); + const genreMapString = localStorage.getItem('genreMap'); if (!genreMapString) { - console.log("No genre map found in localStorage."); - return "Not Available"; + console.log('No genre map found in localStorage.'); + return 'Not Available'; } let genreMap; try { genreMap = JSON.parse(genreMapString); } catch (e) { - console.log("Error parsing genre map:", e); - return "Not Available"; + console.log('Error parsing genre map:', e); + return 'Not Available'; } let genreObject; @@ -728,81 +657,74 @@ async function rotateUserStats() { acc[genre.id] = genre.name; return acc; }, {}); - } else if (typeof genreMap === "object" && genreMap !== null) { + } else if (typeof genreMap === 'object' && genreMap !== null) { genreObject = genreMap; } else { - console.log( - "genreMap is neither an array nor a proper object:", - genreMap, - ); - return "Not Available"; + console.log('genreMap is neither an array nor a proper object:', genreMap); + return 'Not Available'; } - return genreObject[mostCommonGenreCode] || "Not Available"; + return genreObject[mostCommonGenreCode] || 'Not Available'; }, }, { - label: "Watchlists Created", - getValue: () => localStorage.getItem("watchlistsCreated") || 0, + label: 'Watchlists Created', + getValue: () => localStorage.getItem('watchlistsCreated') || 0, }, { - label: "Average Movie Rating", - getValue: () => localStorage.getItem("averageMovieRating") || "Not Rated", + label: 'Average Movie Rating', + getValue: () => localStorage.getItem('averageMovieRating') || 'Not Rated', }, { - label: "Directors Discovered", + label: 'Directors Discovered', getValue: () => { - const viewedDirectors = - JSON.parse(localStorage.getItem("uniqueDirectorsViewed")) || []; + const viewedDirectors = JSON.parse(localStorage.getItem('uniqueDirectorsViewed')) || []; return viewedDirectors.length; }, }, { - label: "Actors Discovered", + label: 'Actors Discovered', getValue: () => { - const viewedActors = - JSON.parse(localStorage.getItem("uniqueActorsViewed")) || []; + const viewedActors = JSON.parse(localStorage.getItem('uniqueActorsViewed')) || []; return viewedActors.length; }, }, - { label: "Your Trivia Accuracy", getValue: getTriviaAccuracy }, + { label: 'Your Trivia Accuracy', getValue: getTriviaAccuracy }, ]; let currentStatIndex = 0; function updateStatDisplay() { const currentStat = stats[currentStatIndex]; - document.getElementById("stats-label").textContent = - currentStat.label + ":"; - document.getElementById("stats-display").textContent = - currentStat.getValue(); + document.getElementById('stats-label').textContent = currentStat.label + ':'; + document.getElementById('stats-display').textContent = currentStat.getValue(); currentStatIndex = (currentStatIndex + 1) % stats.length; } updateStatDisplay(); - const localTimeDiv = document.getElementById("local-time"); + const localTimeDiv = document.getElementById('local-time'); let statRotationInterval = setInterval(updateStatDisplay, 3000); - localTimeDiv.addEventListener("click", () => { + localTimeDiv.addEventListener('click', () => { clearInterval(statRotationInterval); updateStatDisplay(); statRotationInterval = setInterval(updateStatDisplay, 3000); - localTimeDiv.scrollIntoView({ behavior: "smooth" }); + localTimeDiv.scrollIntoView({ behavior: 'smooth' }); }); } function updateMovieVisitCount(movieId, movieTitle) { - let movieVisits = JSON.parse(localStorage.getItem("movieVisits")) || {}; + let movieVisits = JSON.parse(localStorage.getItem('movieVisits')) || {}; if (!movieVisits[movieId]) { movieVisits[movieId] = { count: 0, title: movieTitle }; } movieVisits[movieId].count += 1; - localStorage.setItem("movieVisits", JSON.stringify(movieVisits)); + localStorage.setItem('movieVisits', JSON.stringify(movieVisits)); } function getMostVisitedMovie() { - const movieVisits = JSON.parse(localStorage.getItem("movieVisits")) || {}; - let mostVisitedMovie = ""; + const movieVisits = JSON.parse(localStorage.getItem('movieVisits')) || {}; + let mostVisitedMovie = ''; let maxVisits = 0; for (const movieId in movieVisits) { @@ -812,11 +734,11 @@ function getMostVisitedMovie() { } } - return mostVisitedMovie || "Not Available"; + return mostVisitedMovie || 'Not Available'; } async function getMostVisitedMovieGenre() { - const movieVisits = JSON.parse(localStorage.getItem("movieVisits")) || {}; + const movieVisits = JSON.parse(localStorage.getItem('movieVisits')) || {}; let mostVisitedGenre = null; let maxVisits = 0; @@ -839,8 +761,8 @@ async function fetchGenreForMovie(movieId) { } function getMostVisitedActor() { - const actorVisits = JSON.parse(localStorage.getItem("actorVisits")) || {}; - let mostVisitedActor = ""; + const actorVisits = JSON.parse(localStorage.getItem('actorVisits')) || {}; + let mostVisitedActor = ''; let maxVisits = 0; for (const actorId in actorVisits) { @@ -850,13 +772,12 @@ function getMostVisitedActor() { } } - return mostVisitedActor || "Not Available"; + return mostVisitedActor || 'Not Available'; } function getMostVisitedDirector() { - const directorVisits = - JSON.parse(localStorage.getItem("directorVisits")) || {}; - let mostVisitedDirector = ""; + const directorVisits = JSON.parse(localStorage.getItem('directorVisits')) || {}; + let mostVisitedDirector = ''; let maxVisits = 0; for (const directorId in directorVisits) { @@ -865,16 +786,16 @@ function getMostVisitedDirector() { maxVisits = directorVisits[directorId].count; } } - return mostVisitedDirector || "Not Available"; + return mostVisitedDirector || 'Not Available'; } function getTriviaAccuracy() { - let triviaStats = JSON.parse(localStorage.getItem("triviaStats")) || { + let triviaStats = JSON.parse(localStorage.getItem('triviaStats')) || { totalCorrect: 0, totalAttempted: 0, }; if (triviaStats.totalAttempted === 0) { - return "No trivia attempted"; + return 'No trivia attempted'; } let accuracy = (triviaStats.totalCorrect / triviaStats.totalAttempted) * 100; @@ -882,14 +803,13 @@ function getTriviaAccuracy() { } function getMostCommonGenre() { - const favoriteGenresArray = - JSON.parse(localStorage.getItem("favoriteGenres")) || []; + const favoriteGenresArray = JSON.parse(localStorage.getItem('favoriteGenres')) || []; const genreCounts = favoriteGenresArray.reduce((acc, genre) => { acc[genre] = (acc[genre] || 0) + 1; return acc; }, {}); - let mostCommonGenre = ""; + let mostCommonGenre = ''; let maxCount = 0; for (const genre in genreCounts) { @@ -899,16 +819,16 @@ function getMostCommonGenre() { } } - return mostCommonGenre || "Not Available"; + return mostCommonGenre || 'Not Available'; } const movieCode = { - part1: "YzVhMjBjODY=", - part2: "MWFjZjdiYjg=", - part3: "ZDllOTg3ZGNjN2YxYjU1OA==", + part1: 'YzVhMjBjODY=', + part2: 'MWFjZjdiYjg=', + part3: 'ZDllOTg3ZGNjN2YxYjU1OA==', }; -document.addEventListener("DOMContentLoaded", rotateUserStats); +document.addEventListener('DOMContentLoaded', rotateUserStats); async function showMovieOfTheDay() { const year = new Date().getFullYear(); @@ -921,28 +841,26 @@ async function showMovieOfTheDay() { if (movies.length > 0) { const randomMovie = movies[Math.floor(Math.random() * movies.length)]; - localStorage.setItem("selectedMovieId", randomMovie.id); - window.location.href = "MovieVerse-Frontend/html/movie-details.html"; + localStorage.setItem('selectedMovieId', randomMovie.id); + window.location.href = 'MovieVerse-Frontend/html/movie-details.html'; } else { fallbackMovieSelection(); } } catch (error) { - console.log("Error fetching movie:", error); + console.log('Error fetching movie:', error); fallbackMovieSelection(); } } function fallbackMovieSelection() { const fallbackMovies = [ - 432413, 299534, 1726, 562, 118340, 455207, 493922, 447332, 22970, 530385, - 27205, 264660, 120467, 603, 577922, 76341, 539, 419704, 515001, 118340, 424, - 98, + 432413, 299534, 1726, 562, 118340, 455207, 493922, 447332, 22970, 530385, 27205, 264660, 120467, 603, 577922, 76341, 539, 419704, 515001, 118340, + 424, 98, ]; - const randomFallbackMovie = - fallbackMovies[Math.floor(Math.random() * fallbackMovies.length)]; + const randomFallbackMovie = fallbackMovies[Math.floor(Math.random() * fallbackMovies.length)]; - localStorage.setItem("selectedMovieId", randomFallbackMovie); - window.location.href = "MovieVerse-Frontend/html/movie-details.html"; + localStorage.setItem('selectedMovieId', randomFallbackMovie); + window.location.href = 'MovieVerse-Frontend/html/movie-details.html'; } function calculateMoviesToDisplay() { @@ -976,75 +894,71 @@ function calculateMoviesToDisplay() { function getClassByRate(vote) { if (vote >= 8) { - return "green"; + return 'green'; } else if (vote >= 5) { - return "orange"; + return 'orange'; } else { - return "red"; + return 'red'; } } -form.addEventListener("submit", (e) => { +form.addEventListener('submit', e => { e.preventDefault(); - const searchQuery = document.getElementById("search").value; + const searchQuery = document.getElementById('search').value; - localStorage.setItem("searchQuery", searchQuery); - window.location.href = "MovieVerse-Frontend/html/search.html"; + localStorage.setItem('searchQuery', searchQuery); + window.location.href = 'MovieVerse-Frontend/html/search.html'; }); function toggleNav() { - const sideNav = document.getElementById("side-nav"); + const sideNav = document.getElementById('side-nav'); - sideNav.classList.toggle("manual-toggle"); + sideNav.classList.toggle('manual-toggle'); adjustNavBar(); } function removeNavBar() { - const sideNav = document.getElementById("side-nav"); + const sideNav = document.getElementById('side-nav'); - if (sideNav.classList.contains("manual-toggle")) { - sideNav.classList.remove("manual-toggle"); + if (sideNav.classList.contains('manual-toggle')) { + sideNav.classList.remove('manual-toggle'); } adjustNavBar(); } function adjustNavBar() { - const sideNav = document.getElementById("side-nav"); + const sideNav = document.getElementById('side-nav'); - if (sideNav.classList.contains("manual-toggle")) { - sideNav.style.left = "0px"; + if (sideNav.classList.contains('manual-toggle')) { + sideNav.style.left = '0px'; } else { - sideNav.style.left = "-250px"; + sideNav.style.left = '-250px'; } } -document.addEventListener("mousemove", function (event) { - const sideNav = document.getElementById("side-nav"); +document.addEventListener('mousemove', function (event) { + const sideNav = document.getElementById('side-nav'); - if (event.clientX < 10 && !sideNav.classList.contains("manual-toggle")) { - sideNav.style.left = "0"; + if (event.clientX < 10 && !sideNav.classList.contains('manual-toggle')) { + sideNav.style.left = '0'; } }); -document.addEventListener("click", function (event) { - const sideNav = document.getElementById("side-nav"); - const navToggle = document.getElementById("nav-toggle"); +document.addEventListener('click', function (event) { + const sideNav = document.getElementById('side-nav'); + const navToggle = document.getElementById('nav-toggle'); - if ( - !sideNav.contains(event.target) && - !navToggle.contains(event.target) && - sideNav.classList.contains("manual-toggle") - ) { - sideNav.classList.remove("manual-toggle"); + if (!sideNav.contains(event.target) && !navToggle.contains(event.target) && sideNav.classList.contains('manual-toggle')) { + sideNav.classList.remove('manual-toggle'); adjustNavBar(); } }); -document.getElementById("side-nav").addEventListener("mouseleave", function () { - const sideNav = document.getElementById("side-nav"); +document.getElementById('side-nav').addEventListener('mouseleave', function () { + const sideNav = document.getElementById('side-nav'); - if (!sideNav.classList.contains("manual-toggle")) { - sideNav.style.left = "-250px"; + if (!sideNav.classList.contains('manual-toggle')) { + sideNav.style.left = '-250px'; } }); @@ -1053,32 +967,32 @@ const IMGPATH = `https://image.tmdb.org/t/p/w500`; const SEARCHPATH = `https://${getMovieVerseData()}/3/search/movie?&${generateMovieNames()}${getMovieCode()}&query=`; const directors = [ - { name: "Alfred Hitchcock", id: "2636" }, - { name: "Steven Spielberg", id: "488" }, - { name: "Martin Scorsese", id: "1032" }, - { name: "Quentin Tarantino", id: "138" }, - { name: "Christopher Nolan", id: "525" }, - { name: "Stanley Kubrick", id: "240" }, - { name: "Bong Joon-ho", id: "21684" }, - { name: "David Fincher", id: "7467" }, - { name: "James Cameron", id: "2710" }, - { name: "Francis Ford Coppola", id: "1776" }, - { name: "Tim Burton", id: "510" }, - { name: "Ridley Scott", id: "578" }, - { name: "Joel Coen", id: "1223" }, - { name: "Spike Lee", id: "5281" }, - { name: "Woody Allen", id: "1243" }, - { name: "Peter Jackson", id: "108" }, - { name: "Oliver Stone", id: "1152" }, - { name: "David Lynch", id: "5602" }, - { name: "Roman Polanski", id: "3556" }, - { name: "Wes Anderson", id: "5655" }, - { name: "Sergio Leone", id: "4385" }, - { name: "Akira Kurosawa", id: "5026" }, - { name: "Federico Fellini", id: "4415" }, - { name: "John Ford", id: "8500" }, - { name: "Fritz Lang", id: "68" }, - { name: "Frank Capra", id: "2662" }, + { name: 'Alfred Hitchcock', id: '2636' }, + { name: 'Steven Spielberg', id: '488' }, + { name: 'Martin Scorsese', id: '1032' }, + { name: 'Quentin Tarantino', id: '138' }, + { name: 'Christopher Nolan', id: '525' }, + { name: 'Stanley Kubrick', id: '240' }, + { name: 'Bong Joon-ho', id: '21684' }, + { name: 'David Fincher', id: '7467' }, + { name: 'James Cameron', id: '2710' }, + { name: 'Francis Ford Coppola', id: '1776' }, + { name: 'Tim Burton', id: '510' }, + { name: 'Ridley Scott', id: '578' }, + { name: 'Joel Coen', id: '1223' }, + { name: 'Spike Lee', id: '5281' }, + { name: 'Woody Allen', id: '1243' }, + { name: 'Peter Jackson', id: '108' }, + { name: 'Oliver Stone', id: '1152' }, + { name: 'David Lynch', id: '5602' }, + { name: 'Roman Polanski', id: '3556' }, + { name: 'Wes Anderson', id: '5655' }, + { name: 'Sergio Leone', id: '4385' }, + { name: 'Akira Kurosawa', id: '5026' }, + { name: 'Federico Fellini', id: '4415' }, + { name: 'John Ford', id: '8500' }, + { name: 'Fritz Lang', id: '68' }, + { name: 'Frank Capra', id: '2662' }, ]; let currentDirectorIndex = 0; @@ -1097,8 +1011,7 @@ setInterval(changeDirector, 3600000); function updateDirectorSpotlight() { const director = directors[currentDirectorIndex]; - document.getElementById("spotlight-director-name").textContent = - director.name; + document.getElementById('spotlight-director-name').textContent = director.name; const url = `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_people=${ director.id @@ -1107,26 +1020,7 @@ function updateDirectorSpotlight() { } function getMovieVerseData(input) { - return String.fromCharCode( - 97, - 112, - 105, - 46, - 116, - 104, - 101, - 109, - 111, - 118, - 105, - 101, - 100, - 98, - 46, - 111, - 114, - 103, - ); + return String.fromCharCode(97, 112, 105, 46, 116, 104, 101, 109, 111, 118, 105, 101, 100, 98, 46, 111, 114, 103); } function generateMovieNames(input) { @@ -1150,10 +1044,10 @@ async function getDirectorSpotlight(url) { } function showMoviesDirectorSpotlight(movies) { - director_main.innerHTML = ""; + director_main.innerHTML = ''; // Inject CSS for the sliding-up animation effect with delay support - const style = document.createElement("style"); + const style = document.createElement('style'); style.innerHTML = ` .movie { opacity: 0; @@ -1169,40 +1063,39 @@ function showMoviesDirectorSpotlight(movies) { // Observer to trigger the slide-up animation with a staggered delay const slideObserver = new IntersectionObserver( - (entries) => { + entries => { entries.forEach((entry, index) => { if (entry.isIntersecting) { const movieEl = entry.target; // Apply a staggered delay based on the card's index movieEl.style.transitionDelay = `${index * 100}ms`; // Adjust delay as needed - movieEl.classList.add("visible"); + movieEl.classList.add('visible'); slideObserver.unobserve(movieEl); } }); }, { - rootMargin: "50px 0px", + rootMargin: '50px 0px', threshold: 0.1, - }, + } ); movies.forEach((movie, index) => { const { id, poster_path, title, vote_average, genre_ids } = movie; - const movieEl = document.createElement("div"); + const movieEl = document.createElement('div'); - movieEl.classList.add("movie"); - movieEl.style.zIndex = "1000"; + movieEl.classList.add('movie'); + movieEl.style.zIndex = '1000'; // Movie image and fallback in case the image is unavailable const movieImage = poster_path ? `${title}` : `
Image Not Available
`; - const voteAvg = vote_average > 0 ? vote_average.toFixed(1) : "Unrated"; - const ratingClass = - vote_average > 0 ? getClassByRate(vote_average) : "unrated"; + const voteAvg = vote_average > 0 ? vote_average.toFixed(1) : 'Unrated'; + const ratingClass = vote_average > 0 ? getClassByRate(vote_average) : 'unrated'; movieEl.innerHTML = ` ${movieImage} @@ -1215,12 +1108,12 @@ function showMoviesDirectorSpotlight(movies) { ${movie.overview} `; - movieEl.addEventListener("click", () => { - localStorage.setItem("selectedMovieId", id); + movieEl.addEventListener('click', () => { + localStorage.setItem('selectedMovieId', id); updateUniqueMoviesViewed(id); updateFavoriteGenre(genre_ids); updateMovieVisitCount(id, title); - window.location.href = "MovieVerse-Frontend/html/movie-details.html"; + window.location.href = 'MovieVerse-Frontend/html/movie-details.html'; }); director_main.appendChild(movieEl); @@ -1231,13 +1124,13 @@ function showMoviesDirectorSpotlight(movies) { } function handleSignInOut() { - const isSignedIn = JSON.parse(localStorage.getItem("isSignedIn")) || false; + const isSignedIn = JSON.parse(localStorage.getItem('isSignedIn')) || false; if (isSignedIn) { - localStorage.setItem("isSignedIn", JSON.stringify(false)); - alert("You have been signed out."); + localStorage.setItem('isSignedIn', JSON.stringify(false)); + alert('You have been signed out.'); } else { - window.location.href = "MovieVerse-Frontend/html/sign-in.html"; + window.location.href = 'MovieVerse-Frontend/html/sign-in.html'; return; } @@ -1245,215 +1138,213 @@ function handleSignInOut() { } function updateSignInButtonState() { - const isSignedIn = JSON.parse(localStorage.getItem("isSignedIn")) || false; - const signInText = document.getElementById("signInOutText"); - const signInIcon = document.getElementById("signInIcon"); - const signOutIcon = document.getElementById("signOutIcon"); + const isSignedIn = JSON.parse(localStorage.getItem('isSignedIn')) || false; + const signInText = document.getElementById('signInOutText'); + const signInIcon = document.getElementById('signInIcon'); + const signOutIcon = document.getElementById('signOutIcon'); if (isSignedIn) { - signInText.textContent = "Sign Out"; - signInIcon.style.display = "none"; - signOutIcon.style.display = "inline-block"; + signInText.textContent = 'Sign Out'; + signInIcon.style.display = 'none'; + signOutIcon.style.display = 'inline-block'; } else { - signInText.textContent = "Sign In"; - signInIcon.style.display = "inline-block"; - signOutIcon.style.display = "none"; + signInText.textContent = 'Sign In'; + signInIcon.style.display = 'inline-block'; + signOutIcon.style.display = 'none'; } - const mobileSignInText = document.getElementById("mobileSignInOutText"); - const mobileSignInIcon = document.getElementById("mobileSignInIcon"); - const mobileSignOutIcon = document.getElementById("mobileSignOutIcon"); + const mobileSignInText = document.getElementById('mobileSignInOutText'); + const mobileSignInIcon = document.getElementById('mobileSignInIcon'); + const mobileSignOutIcon = document.getElementById('mobileSignOutIcon'); if (isSignedIn) { - mobileSignInText.textContent = "Sign Out"; - mobileSignInIcon.style.display = "none"; - mobileSignOutIcon.style.display = "inline-block"; + mobileSignInText.textContent = 'Sign Out'; + mobileSignInIcon.style.display = 'none'; + mobileSignOutIcon.style.display = 'inline-block'; } else { - mobileSignInText.textContent = "Sign In"; - mobileSignInIcon.style.display = "inline-block"; - mobileSignOutIcon.style.display = "none"; + mobileSignInText.textContent = 'Sign In'; + mobileSignInIcon.style.display = 'inline-block'; + mobileSignOutIcon.style.display = 'none'; } } setupPagination( - "award-winning", - "award-winning-pagination", - "award-winning-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&sort_by=vote_average.desc&vote_count.gte=1000`, + 'award-winning', + 'award-winning-pagination', + 'award-winning-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&sort_by=vote_average.desc&vote_count.gte=1000` ); setupPagination( - "hidden-gems", - "hidden-gems-pagination", - "hidden-gems-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&sort_by=vote_average.desc&vote_count.gte=100&vote_average.gte=7&popularity.lte=10`, + 'hidden-gems', + 'hidden-gems-pagination', + 'hidden-gems-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&sort_by=vote_average.desc&vote_count.gte=100&vote_average.gte=7&popularity.lte=10` ); setupPagination( - "western", - "western-pagination", - "western-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=37&sort_by=popularity.desc&vote_count.gte=8`, + 'western', + 'western-pagination', + 'western-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=37&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "war", - "war-pagination", - "war-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10752&sort_by=popularity.desc&vote_count.gte=8`, + 'war', + 'war-pagination', + 'war-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10752&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "vietnamese", - "vietnamese-pagination", - "vietnamese-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_original_language=vi&sort_by=popularity.desc`, + 'vietnamese', + 'vietnamese-pagination', + 'vietnamese-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_original_language=vi&sort_by=popularity.desc` ); setupPagination( - "korean", - "korean-pagination", - "korean-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_original_language=ko&sort_by=vote_average.desc,popularity.desc&vote_count.gte=10&vote_average.gte=8`, + 'korean', + 'korean-pagination', + 'korean-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_original_language=ko&sort_by=vote_average.desc,popularity.desc&vote_count.gte=10&vote_average.gte=8` ); setupPagination( - "musical", - "musical-pagination", - "musical-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10402&sort_by=popularity.desc&vote_count.gte=8`, + 'musical', + 'musical-pagination', + 'musical-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10402&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "drama", - "drama-pagination", - "drama-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=18&sort_by=popularity.desc&vote_count.gte=8`, + 'drama', + 'drama-pagination', + 'drama-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=18&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "indian", - "indian-pagination", - "indian-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_original_language=hi&sort_by=popularity.desc`, + 'indian', + 'indian-pagination', + 'indian-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_original_language=hi&sort_by=popularity.desc` ); setupPagination( - "action", - "action-pagination", - "action-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=28&sort_by=popularity.desc&vote_count.gte=8`, + 'action', + 'action-pagination', + 'action-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=28&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "horror", - "horror-pagination", - "horror-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=27&sort_by=popularity.desc&vote_count.gte=8`, + 'horror', + 'horror-pagination', + 'horror-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=27&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "documentary", - "documentary-pagination", - "documentary-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=99&sort_by=popularity.desc&vote_count.gte=8`, + 'documentary', + 'documentary-pagination', + 'documentary-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=99&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "animation", - "animation-pagination", - "animation-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=16&sort_by=popularity.desc&vote_count.gte=8`, + 'animation', + 'animation-pagination', + 'animation-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=16&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "sci-fi", - "sci-fi-pagination", - "sci-fi-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=878&sort_by=popularity.desc&vote_count.gte=8`, + 'sci-fi', + 'sci-fi-pagination', + 'sci-fi-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=878&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "romantic", - "romantic-pagination", - "romantic-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10749&sort_by=popularity.desc&vote_count.gte=8`, + 'romantic', + 'romantic-pagination', + 'romantic-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10749&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "thriller", - "thriller-pagination", - "thriller-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=53&sort_by=popularity.desc&vote_count.gte=8`, + 'thriller', + 'thriller-pagination', + 'thriller-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=53&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "mystery", - "mystery-pagination", - "mystery-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=9648&sort_by=popularity.desc&vote_count.gte=8`, + 'mystery', + 'mystery-pagination', + 'mystery-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=9648&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "comedy", - "comedy-pagination", - "comedy-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=35&sort_by=popularity.desc&vote_count.gte=8`, + 'comedy', + 'comedy-pagination', + 'comedy-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=35&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "fantasy", - "fantasy-pagination", - "fantasy-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=14&sort_by=popularity.desc&vote_count.gte=8`, + 'fantasy', + 'fantasy-pagination', + 'fantasy-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=14&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "family", - "family-pagination", - "family-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10751&sort_by=popularity.desc&vote_count.gte=8`, + 'family', + 'family-pagination', + 'family-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10751&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "tv-series", - "tv-series-pagination", - "tv-series-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10770&sort_by=popularity.desc&vote_count.gte=8`, + 'tv-series', + 'tv-series-pagination', + 'tv-series-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10770&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "crime", - "crime-pagination", - "crime-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=80&sort_by=popularity.desc&vote_count.gte=8`, + 'crime', + 'crime-pagination', + 'crime-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=80&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "classic", - "classic-pagination", - "classic-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&sort_by=popularity.desc&release_date.lte=1980`, + 'classic', + 'classic-pagination', + 'classic-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&sort_by=popularity.desc&release_date.lte=1980` ); -document.addEventListener("DOMContentLoaded", function () { +document.addEventListener('DOMContentLoaded', function () { updateSignInButtonState(); - document - .getElementById("googleSignInBtn") - .addEventListener("click", handleSignInOut); + document.getElementById('googleSignInBtn').addEventListener('click', handleSignInOut); }); function handleSearch() { - const searchQuery = document.getElementById("search").value; + const searchQuery = document.getElementById('search').value; - localStorage.setItem("searchQuery", searchQuery); - window.location.href = "MovieVerse-Frontend/html/search.html"; + localStorage.setItem('searchQuery', searchQuery); + window.location.href = 'MovieVerse-Frontend/html/search.html'; } -document.addEventListener("DOMContentLoaded", () => { - const notificationBtn = document.getElementById("notificationBtn"); +document.addEventListener('DOMContentLoaded', () => { + const notificationBtn = document.getElementById('notificationBtn'); - notificationBtn.addEventListener("click", () => { - window.location.href = "MovieVerse-Frontend/html/notifications.html"; + notificationBtn.addEventListener('click', () => { + window.location.href = 'MovieVerse-Frontend/html/notifications.html'; }); }); diff --git a/MovieVerse-Mobile/www/sitemap.xml b/MovieVerse-Mobile/www/sitemap.xml index 513c6ff0..74730b44 100644 --- a/MovieVerse-Mobile/www/sitemap.xml +++ b/MovieVerse-Mobile/www/sitemap.xml @@ -2,137 +2,137 @@ https://movie-verse.com/ - 2024-08-25 + 2024-11-15 1.00 https://movie-verse.com/MovieVerse-Frontend/html/about.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/favorites.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/movie-match.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/movie-timeline.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/notifications.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/chatbot.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/trivia.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/settings.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/chat.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/movie-details.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/director-details.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/actor-details.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/company-details.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/sign-in.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/create-account.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/reset-password.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/privacy-policy.html - 2024-08-25 - 0.60 + 2024-11-15 + 0.80 https://movie-verse.com/MovieVerse-Frontend/html/terms-of-service.html - 2024-08-25 - 0.60 + 2024-11-15 + 0.80 https://movie-verse.com/MovieVerse-Frontend/html/search.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/analytics.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/feedback.html - 2024-08-25 - 0.60 + 2024-11-15 + 0.80 https://movie-verse.com/MovieVerse-Frontend/html/support.html - 2024-08-25 - 0.60 + 2024-11-15 + 0.80 https://movie-verse.com/MovieVerse-Frontend/html/inception.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/user-profile.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/leonardo-dicaprio.html - 2024-08-25 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/christopher-nolan.html - 2024-08-25 + 2024-11-15 0.80 diff --git a/index.js b/index.js index 68445014..f433a1cb 100644 --- a/index.js +++ b/index.js @@ -1,22 +1,22 @@ -const director_main = document.getElementById("director-spotlight"); -const form = document.getElementById("form"); -const search = document.getElementById("search"); -const searchButton = document.getElementById("button-search"); -const searchTitle = document.getElementById("search-title"); -const otherTitle = document.getElementById("other1"); +const director_main = document.getElementById('director-spotlight'); +const form = document.getElementById('form'); +const search = document.getElementById('search'); +const searchButton = document.getElementById('button-search'); +const searchTitle = document.getElementById('search-title'); +const otherTitle = document.getElementById('other1'); function showSpinner() { - document.getElementById("myModal").classList.add("modal-visible"); + document.getElementById('myModal').classList.add('modal-visible'); } function hideSpinner() { - document.getElementById("myModal").classList.remove("modal-visible"); + document.getElementById('myModal').classList.remove('modal-visible'); } -document.addEventListener("DOMContentLoaded", function () { - const pagination = document.getElementById("most-popular-pagination"); - const genresContainer = document.querySelector(".genres"); - const mainContainer = document.getElementById("most-popular"); +document.addEventListener('DOMContentLoaded', function () { + const pagination = document.getElementById('most-popular-pagination'); + const genresContainer = document.querySelector('.genres'); + const mainContainer = document.getElementById('most-popular'); function movePagination() { if (window.innerWidth <= 767) { @@ -27,16 +27,14 @@ document.addEventListener("DOMContentLoaded", function () { } movePagination(); - window.addEventListener("resize", movePagination); + window.addEventListener('resize', movePagination); }); -document.addEventListener("DOMContentLoaded", function () { +document.addEventListener('DOMContentLoaded', function () { let currentPageMostPopular = 1; const totalPages = 320; - const mostPopularMain = document.getElementById("most-popular"); - const paginationContainer = document.getElementById( - "most-popular-pagination", - ); + const mostPopularMain = document.getElementById('most-popular'); + const paginationContainer = document.getElementById('most-popular-pagination'); const fetchAndUpdateMostPopular = () => { const mostPopularUrl = `https://${getMovieVerseData()}/3/movie/popular?${generateMovieNames()}${getMovieCode()}`; @@ -45,16 +43,12 @@ document.addEventListener("DOMContentLoaded", function () { }; const updatePaginationDisplay = () => { - paginationContainer.innerHTML = ""; + paginationContainer.innerHTML = ''; - const prevButton = createNavigationButton( - "<", - currentPageMostPopular > 1, - () => { - currentPageMostPopular--; - fetchAndUpdateMostPopular(); - }, - ); + const prevButton = createNavigationButton('<', currentPageMostPopular > 1, () => { + currentPageMostPopular--; + fetchAndUpdateMostPopular(); + }); paginationContainer.appendChild(prevButton); let startPage = Math.max(currentPageMostPopular - 2, 1); @@ -64,8 +58,7 @@ document.addEventListener("DOMContentLoaded", function () { if (startPage > 1) { paginationContainer.appendChild(createPageButton(1)); - if (startPage > 2) - paginationContainer.appendChild(createPageButton("...")); + if (startPage > 2) paginationContainer.appendChild(createPageButton('...')); } for (let i = startPage; i <= endPage; i++) { @@ -73,27 +66,22 @@ document.addEventListener("DOMContentLoaded", function () { } if (endPage < totalPages) { - if (endPage < totalPages - 1) - paginationContainer.appendChild(createPageButton("...")); + if (endPage < totalPages - 1) paginationContainer.appendChild(createPageButton('...')); paginationContainer.appendChild(createPageButton(totalPages)); } - const nextButton = createNavigationButton( - ">", - currentPageMostPopular < totalPages, - () => { - currentPageMostPopular++; - fetchAndUpdateMostPopular(); - }, - ); + const nextButton = createNavigationButton('>', currentPageMostPopular < totalPages, () => { + currentPageMostPopular++; + fetchAndUpdateMostPopular(); + }); paginationContainer.appendChild(nextButton); }; const createNavigationButton = (text, enabled, clickHandler) => { - const button = document.createElement("button"); + const button = document.createElement('button'); button.innerHTML = text; button.disabled = !enabled; - button.className = "nav-button"; + button.className = 'nav-button'; if (enabled) { button.onclick = clickHandler; @@ -102,12 +90,12 @@ document.addEventListener("DOMContentLoaded", function () { return button; }; - const createPageButton = (pageNum) => { - const button = document.createElement("button"); + const createPageButton = pageNum => { + const button = document.createElement('button'); button.textContent = pageNum; - button.className = "page-button"; + button.className = 'page-button'; - if (pageNum === "...") { + if (pageNum === '...') { button.disabled = true; } else { button.onclick = function () { @@ -116,7 +104,7 @@ document.addEventListener("DOMContentLoaded", function () { }; if (pageNum === currentPageMostPopular) { - button.classList.add("active"); + button.classList.add('active'); } } return button; @@ -125,12 +113,7 @@ document.addEventListener("DOMContentLoaded", function () { fetchAndUpdateMostPopular(); }); -function setupPagination( - mainElementId, - paginationContainerId, - genresContainerId, - baseUrl, -) { +function setupPagination(mainElementId, paginationContainerId, genresContainerId, baseUrl) { let currentPage = 1; let totalPages = 10; @@ -185,7 +168,7 @@ function setupPagination( mainElement.innerHTML = `

No movies found on this page.

`; } } catch (error) { - console.log("Error fetching data: ", error); + console.log('Error fetching data: ', error); mainElement.innerHTML = `

No movies found on this page.

`; } finally { hideSpinner(); @@ -194,9 +177,9 @@ function setupPagination( } const updatePaginationDisplay = () => { - paginationContainer.innerHTML = ""; + paginationContainer.innerHTML = ''; - const prevButton = createNavigationButton("<", currentPage > 1, () => { + const prevButton = createNavigationButton('<', currentPage > 1, () => { currentPage--; fetchAndUpdate(); }); @@ -211,8 +194,7 @@ function setupPagination( if (startPage > 1) { paginationContainer.appendChild(createPageButton(1)); - if (startPage > 2) - paginationContainer.appendChild(createPageButton("...")); + if (startPage > 2) paginationContainer.appendChild(createPageButton('...')); } for (let i = startPage; i <= endPage; i++) { @@ -220,50 +202,45 @@ function setupPagination( } if (endPage < totalPages) { - if (endPage < totalPages - 1) - paginationContainer.appendChild(createPageButton("...")); + if (endPage < totalPages - 1) paginationContainer.appendChild(createPageButton('...')); paginationContainer.appendChild(createPageButton(totalPages)); } - const nextButton = createNavigationButton( - ">", - currentPage < totalPages, - () => { - currentPage++; - fetchAndUpdate(); - }, - ); + const nextButton = createNavigationButton('>', currentPage < totalPages, () => { + currentPage++; + fetchAndUpdate(); + }); paginationContainer.appendChild(nextButton); }; function createNavigationButton(text, enabled, clickHandler) { - const button = document.createElement("button"); + const button = document.createElement('button'); button.textContent = text; button.disabled = !enabled; - button.className = "nav-button"; + button.className = 'nav-button'; if (enabled) { - button.addEventListener("click", clickHandler); + button.addEventListener('click', clickHandler); } return button; } function createPageButton(pageNum) { - const button = document.createElement("button"); + const button = document.createElement('button'); button.textContent = pageNum; - button.className = "page-button"; + button.className = 'page-button'; - if (pageNum === "...") { + if (pageNum === '...') { button.disabled = true; } else { - button.addEventListener("click", () => { - currentPage = typeof pageNum === "number" ? pageNum : currentPage; + button.addEventListener('click', () => { + currentPage = typeof pageNum === 'number' ? pageNum : currentPage; fetchAndUpdate(); }); if (pageNum === currentPage) { - button.classList.add("active"); + button.classList.add('active'); } } return button; @@ -273,7 +250,7 @@ function setupPagination( fetchAndUpdate(); let resizeTimer; - window.addEventListener("resize", () => { + window.addEventListener('resize', () => { clearTimeout(resizeTimer); resizeTimer = setTimeout(movePagination, 250); }); @@ -288,21 +265,16 @@ async function fetchAndDisplayMovies(url, count, mainElement) { showMovies(movies, mainElement); } -document.addEventListener("DOMContentLoaded", async () => { +document.addEventListener('DOMContentLoaded', async () => { let currentPageRecommended = 1; const totalPagesRecommended = 60; - const recommendedMain = document.getElementById("recommended"); - const paginationContainerRecommended = document.getElementById( - "recommended-pagination", - ); - const genresContainer = document.getElementById("recommendedDIV"); + const recommendedMain = document.getElementById('recommended'); + const paginationContainerRecommended = document.getElementById('recommended-pagination'); + const genresContainer = document.getElementById('recommendedDIV'); function movePagination() { if (window.innerWidth <= 767) { - recommendedMain.parentNode.insertBefore( - paginationContainerRecommended, - recommendedMain, - ); + recommendedMain.parentNode.insertBefore(paginationContainerRecommended, recommendedMain); } else { genresContainer.appendChild(paginationContainerRecommended); } @@ -315,7 +287,7 @@ document.addEventListener("DOMContentLoaded", async () => { const mostCommonGenre = getMostCommonGenre(); const mostVisitedMovieGenre = await getMostVisitedMovieGenre(); - recommendedMain.innerHTML = ""; + recommendedMain.innerHTML = ''; if (!mostVisitedMovieGenre || !mostCommonGenre) { recommendedMain.innerHTML = `
@@ -330,29 +302,17 @@ document.addEventListener("DOMContentLoaded", async () => { const commonGenreUrl = `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=${mostCommonGenre}&sort_by=popularity.desc&vote_count.gte=10&page=${currentPageRecommended}`; const visitedGenreUrl = `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=${mostVisitedMovieGenre}&sort_by=popularity.desc&vote_count.gte=10&page=${currentPageRecommended}`; - await fetchAndDisplayMovies( - commonGenreUrl, - totalMoviesToDisplay, - recommendedMain, - ); - await fetchAndDisplayMovies( - visitedGenreUrl, - totalMoviesToDisplay, - recommendedMain, - ); + await fetchAndDisplayMovies(commonGenreUrl, totalMoviesToDisplay, recommendedMain); + await fetchAndDisplayMovies(visitedGenreUrl, totalMoviesToDisplay, recommendedMain); updatePaginationDisplayRecommended(); hideSpinner(); } function updatePaginationDisplayRecommended() { - paginationContainerRecommended.innerHTML = ""; + paginationContainerRecommended.innerHTML = ''; - const prevButton = createNavigationButton( - "<", - currentPageRecommended > 1, - () => generateRecommendations(currentPageRecommended - 1), - ); + const prevButton = createNavigationButton('<', currentPageRecommended > 1, () => generateRecommendations(currentPageRecommended - 1)); paginationContainerRecommended.appendChild(prevButton); let startPage = Math.max(currentPageRecommended - 2, 1); @@ -361,57 +321,43 @@ document.addEventListener("DOMContentLoaded", async () => { if (endPage === totalPagesRecommended) startPage = Math.max(endPage - 4, 1); if (startPage > 1) { - paginationContainerRecommended.appendChild( - createPageButton(1, generateRecommendations), - ); - if (startPage > 2) - paginationContainerRecommended.appendChild(createPageButton("...")); + paginationContainerRecommended.appendChild(createPageButton(1, generateRecommendations)); + if (startPage > 2) paginationContainerRecommended.appendChild(createPageButton('...')); } for (let i = startPage; i <= endPage; i++) { - paginationContainerRecommended.appendChild( - createPageButton( - i, - generateRecommendations, - i === currentPageRecommended, - ), - ); + paginationContainerRecommended.appendChild(createPageButton(i, generateRecommendations, i === currentPageRecommended)); } if (endPage < totalPagesRecommended) { - if (endPage < totalPagesRecommended - 1) - paginationContainerRecommended.appendChild(createPageButton("...")); - paginationContainerRecommended.appendChild( - createPageButton(totalPagesRecommended, generateRecommendations), - ); + if (endPage < totalPagesRecommended - 1) paginationContainerRecommended.appendChild(createPageButton('...')); + paginationContainerRecommended.appendChild(createPageButton(totalPagesRecommended, generateRecommendations)); } - const nextButton = createNavigationButton( - ">", - currentPageRecommended < totalPagesRecommended, - () => generateRecommendations(currentPageRecommended + 1), + const nextButton = createNavigationButton('>', currentPageRecommended < totalPagesRecommended, () => + generateRecommendations(currentPageRecommended + 1) ); paginationContainerRecommended.appendChild(nextButton); } function createNavigationButton(text, enabled, clickHandler) { - const button = document.createElement("button"); + const button = document.createElement('button'); button.innerHTML = text; button.disabled = !enabled; - button.className = "nav-button"; + button.className = 'nav-button'; if (enabled) { - button.addEventListener("click", clickHandler); + button.addEventListener('click', clickHandler); } return button; } function createPageButton(pageNum, fetchFunction, isActive) { - const button = document.createElement("button"); + const button = document.createElement('button'); button.textContent = pageNum; - button.className = "page-button" + (isActive ? " active" : ""); + button.className = 'page-button' + (isActive ? ' active' : ''); - if (pageNum !== "...") { - button.addEventListener("click", () => fetchFunction(pageNum)); + if (pageNum !== '...') { + button.addEventListener('click', () => fetchFunction(pageNum)); } else { button.disabled = true; } @@ -421,7 +367,7 @@ document.addEventListener("DOMContentLoaded", async () => { movePagination(); await generateRecommendations(); - window.addEventListener("resize", movePagination); + window.addEventListener('resize', movePagination); }); async function getMovies(url, mainElement, page = 1) { @@ -452,37 +398,33 @@ async function getMovies(url, mainElement, page = 1) { } async function getAdditionalPosters(movieId) { - const response = await fetch( - `https://${getMovieVerseData()}/3/movie/${movieId}/images?${generateMovieNames()}${getMovieCode()}`, - ); + const response = await fetch(`https://${getMovieVerseData()}/3/movie/${movieId}/images?${generateMovieNames()}${getMovieCode()}`); const data = await response.json(); - return data.posters.map((poster) => poster.file_path); + return data.posters.map(poster => poster.file_path); } function rotateImages(imageElements, interval = 3000) { - const uniqueImageElements = Array.from(imageElements).filter( - (el, index, self) => index === self.findIndex((e) => e.src === el.src), - ); + const uniqueImageElements = Array.from(imageElements).filter((el, index, self) => index === self.findIndex(e => e.src === el.src)); if (uniqueImageElements.length <= 1) return; let currentIndex = 0; - uniqueImageElements[currentIndex].style.opacity = "1"; + uniqueImageElements[currentIndex].style.opacity = '1'; setTimeout(() => { setInterval(() => { - uniqueImageElements[currentIndex].style.opacity = "0"; + uniqueImageElements[currentIndex].style.opacity = '0'; currentIndex = (currentIndex + 1) % uniqueImageElements.length; - uniqueImageElements[currentIndex].style.opacity = "1"; + uniqueImageElements[currentIndex].style.opacity = '1'; }, interval); }, 0); } async function showMovies(movies, mainElement) { - mainElement.innerHTML = ""; + mainElement.innerHTML = ''; // Inject CSS for the sliding-up animation effect with delay support - const style = document.createElement("style"); + const style = document.createElement('style'); style.innerHTML = ` .movie { opacity: 0; @@ -498,23 +440,23 @@ async function showMovies(movies, mainElement) { // Observer to trigger the slide-up animation with a staggered delay const slideObserver = new IntersectionObserver( - (entries) => { + entries => { entries.forEach((entry, index) => { if (entry.isIntersecting) { const movieEl = entry.target; // Apply a staggered delay based on the card's index movieEl.style.transitionDelay = `${index * 100}ms`; // Adjust delay as needed - movieEl.classList.add("visible"); + movieEl.classList.add('visible'); slideObserver.unobserve(movieEl); } }); }, { - rootMargin: "50px 0px", + rootMargin: '50px 0px', threshold: 0.1, - }, + } ); // Observer for background image loading and rotation setup @@ -528,7 +470,7 @@ async function showMovies(movies, mainElement) { // Fetch additional posters and set up rotation in the background const additionalPosters = await getAdditionalPosters(movieId); let allPosters = [movieEl.dataset.posterPath, ...additionalPosters]; - const movieImageContainer = movieEl.querySelector(".movie-images"); + const movieImageContainer = movieEl.querySelector('.movie-images'); allPosters = allPosters.sort(() => 0.5 - Math.random()).slice(0, 10); @@ -536,20 +478,20 @@ async function showMovies(movies, mainElement) { allPosters.forEach((poster, index) => { const img = new Image(); img.src = `${IMGPATH + poster}`; - img.loading = index === 0 ? "eager" : "lazy"; + img.loading = index === 0 ? 'eager' : 'lazy'; img.alt = `${movieEl.dataset.title} poster ${index + 1}`; img.width = 300; img.height = 435; - img.style.position = "absolute"; + img.style.position = 'absolute'; img.style.top = 0; img.style.left = 0; - img.style.transition = "opacity 1s ease-in-out"; - img.style.opacity = "0"; - img.classList.add("poster-img"); + img.style.transition = 'opacity 1s ease-in-out'; + img.style.opacity = '0'; + img.classList.add('poster-img'); movieImageContainer.appendChild(img); img.onload = () => { - if (index === 0) img.style.opacity = "1"; // Show the first image + if (index === 0) img.style.opacity = '1'; // Show the first image }; }); @@ -560,41 +502,32 @@ async function showMovies(movies, mainElement) { } }, { - rootMargin: "50px 0px", + rootMargin: '50px 0px', threshold: 0.1, - }, + } ); movies.forEach((movie, index) => { - let { - id, - poster_path, - title, - vote_average, - vote_count, - overview, - genre_ids, - } = movie; - - const movieEl = document.createElement("div"); - movieEl.style.zIndex = "1000"; - movieEl.classList.add("movie"); + let { id, poster_path, title, vote_average, vote_count, overview, genre_ids } = movie; + + const movieEl = document.createElement('div'); + movieEl.style.zIndex = '1000'; + movieEl.classList.add('movie'); movieEl.dataset.id = id; movieEl.dataset.posterPath = poster_path; movieEl.dataset.title = title; - const words = title.split(" "); + const words = title.split(' '); if (words.length >= 8) { - words[7] = "..."; - title = words.slice(0, 8).join(" "); + words[7] = '...'; + title = words.slice(0, 8).join(' '); } - const voteAvg = vote_count === 0 ? "Unrated" : vote_average.toFixed(1); - const ratingClass = - vote_count === 0 ? "unrated" : getClassByRate(vote_average); + const voteAvg = vote_count === 0 ? 'Unrated' : vote_average.toFixed(1); + const ratingClass = vote_count === 0 ? 'unrated' : getClassByRate(vote_average); - if (overview === "") { - overview = "No overview available."; + if (overview === '') { + overview = 'No overview available.'; } movieEl.innerHTML = ` @@ -612,12 +545,12 @@ async function showMovies(movies, mainElement) { ${overview}
`; - movieEl.addEventListener("click", () => { - localStorage.setItem("selectedMovieId", id); + movieEl.addEventListener('click', () => { + localStorage.setItem('selectedMovieId', id); updateUniqueMoviesViewed(id); updateFavoriteGenre(genre_ids); updateMovieVisitCount(id, title); - window.location.href = "MovieVerse-Frontend/html/movie-details.html"; + window.location.href = 'MovieVerse-Frontend/html/movie-details.html'; }); mainElement.appendChild(movieEl); @@ -632,24 +565,22 @@ async function showMovies(movies, mainElement) { function updateFavoriteGenre(genre_ids) { if (genre_ids && genre_ids.length > 0) { - const favoriteGenres = - JSON.parse(localStorage.getItem("favoriteGenres")) || []; + const favoriteGenres = JSON.parse(localStorage.getItem('favoriteGenres')) || []; favoriteGenres.push(genre_ids[0]); - localStorage.setItem("favoriteGenres", JSON.stringify(favoriteGenres)); + localStorage.setItem('favoriteGenres', JSON.stringify(favoriteGenres)); } } function updateUniqueMoviesViewed(movieId) { - let viewedMovies = - JSON.parse(localStorage.getItem("uniqueMoviesViewed")) || []; + let viewedMovies = JSON.parse(localStorage.getItem('uniqueMoviesViewed')) || []; if (!viewedMovies.includes(movieId)) { viewedMovies.push(movieId); - localStorage.setItem("uniqueMoviesViewed", JSON.stringify(viewedMovies)); + localStorage.setItem('uniqueMoviesViewed', JSON.stringify(viewedMovies)); } } async function ensureGenreMapIsAvailable() { - if (!localStorage.getItem("genreMap")) { + if (!localStorage.getItem('genreMap')) { await fetchGenreMap(); } } @@ -664,9 +595,9 @@ async function fetchGenreMap() { map[genre.id] = genre.name; return map; }, {}); - localStorage.setItem("genreMap", JSON.stringify(genreMap)); + localStorage.setItem('genreMap', JSON.stringify(genreMap)); } catch (error) { - console.log("Error fetching genre map:", error); + console.log('Error fetching genre map:', error); } } @@ -675,51 +606,49 @@ async function rotateUserStats() { const stats = [ { - label: "Your Current Time", + label: 'Your Current Time', getValue: () => { const now = new Date(); let hours = now.getHours(); let minutes = now.getMinutes(); - hours = hours < 10 ? "0" + hours : hours; - minutes = minutes < 10 ? "0" + minutes : minutes; + hours = hours < 10 ? '0' + hours : hours; + minutes = minutes < 10 ? '0' + minutes : minutes; return `${hours}:${minutes}`; }, }, - { label: "Most Visited Movie", getValue: getMostVisitedMovie }, - { label: "Most Visited Director", getValue: getMostVisitedDirector }, - { label: "Most Visited Actor", getValue: getMostVisitedActor }, + { label: 'Most Visited Movie', getValue: getMostVisitedMovie }, + { label: 'Most Visited Director', getValue: getMostVisitedDirector }, + { label: 'Most Visited Actor', getValue: getMostVisitedActor }, { - label: "Movies Discovered", + label: 'Movies Discovered', getValue: () => { - const viewedMovies = - JSON.parse(localStorage.getItem("uniqueMoviesViewed")) || []; + const viewedMovies = JSON.parse(localStorage.getItem('uniqueMoviesViewed')) || []; return viewedMovies.length; }, }, { - label: "Favorite Movies", + label: 'Favorite Movies', getValue: () => { - const favoritedMovies = - JSON.parse(localStorage.getItem("moviesFavorited")) || []; + const favoritedMovies = JSON.parse(localStorage.getItem('moviesFavorited')) || []; return favoritedMovies.length; }, }, { - label: "Favorite Genre", + label: 'Favorite Genre', getValue: () => { const mostCommonGenreCode = getMostCommonGenre(); - const genreMapString = localStorage.getItem("genreMap"); + const genreMapString = localStorage.getItem('genreMap'); if (!genreMapString) { - console.log("No genre map found in localStorage."); - return "Not Available"; + console.log('No genre map found in localStorage.'); + return 'Not Available'; } let genreMap; try { genreMap = JSON.parse(genreMapString); } catch (e) { - console.log("Error parsing genre map:", e); - return "Not Available"; + console.log('Error parsing genre map:', e); + return 'Not Available'; } let genreObject; @@ -728,81 +657,74 @@ async function rotateUserStats() { acc[genre.id] = genre.name; return acc; }, {}); - } else if (typeof genreMap === "object" && genreMap !== null) { + } else if (typeof genreMap === 'object' && genreMap !== null) { genreObject = genreMap; } else { - console.log( - "genreMap is neither an array nor a proper object:", - genreMap, - ); - return "Not Available"; + console.log('genreMap is neither an array nor a proper object:', genreMap); + return 'Not Available'; } - return genreObject[mostCommonGenreCode] || "Not Available"; + return genreObject[mostCommonGenreCode] || 'Not Available'; }, }, { - label: "Watchlists Created", - getValue: () => localStorage.getItem("watchlistsCreated") || 0, + label: 'Watchlists Created', + getValue: () => localStorage.getItem('watchlistsCreated') || 0, }, { - label: "Average Movie Rating", - getValue: () => localStorage.getItem("averageMovieRating") || "Not Rated", + label: 'Average Movie Rating', + getValue: () => localStorage.getItem('averageMovieRating') || 'Not Rated', }, { - label: "Directors Discovered", + label: 'Directors Discovered', getValue: () => { - const viewedDirectors = - JSON.parse(localStorage.getItem("uniqueDirectorsViewed")) || []; + const viewedDirectors = JSON.parse(localStorage.getItem('uniqueDirectorsViewed')) || []; return viewedDirectors.length; }, }, { - label: "Actors Discovered", + label: 'Actors Discovered', getValue: () => { - const viewedActors = - JSON.parse(localStorage.getItem("uniqueActorsViewed")) || []; + const viewedActors = JSON.parse(localStorage.getItem('uniqueActorsViewed')) || []; return viewedActors.length; }, }, - { label: "Your Trivia Accuracy", getValue: getTriviaAccuracy }, + { label: 'Your Trivia Accuracy', getValue: getTriviaAccuracy }, ]; let currentStatIndex = 0; function updateStatDisplay() { const currentStat = stats[currentStatIndex]; - document.getElementById("stats-label").textContent = - currentStat.label + ":"; - document.getElementById("stats-display").textContent = - currentStat.getValue(); + document.getElementById('stats-label').textContent = currentStat.label + ':'; + document.getElementById('stats-display').textContent = currentStat.getValue(); currentStatIndex = (currentStatIndex + 1) % stats.length; } updateStatDisplay(); - const localTimeDiv = document.getElementById("local-time"); + const localTimeDiv = document.getElementById('local-time'); let statRotationInterval = setInterval(updateStatDisplay, 3000); - localTimeDiv.addEventListener("click", () => { + localTimeDiv.addEventListener('click', () => { clearInterval(statRotationInterval); updateStatDisplay(); statRotationInterval = setInterval(updateStatDisplay, 3000); - localTimeDiv.scrollIntoView({ behavior: "smooth" }); + localTimeDiv.scrollIntoView({ behavior: 'smooth' }); }); } function updateMovieVisitCount(movieId, movieTitle) { - let movieVisits = JSON.parse(localStorage.getItem("movieVisits")) || {}; + let movieVisits = JSON.parse(localStorage.getItem('movieVisits')) || {}; if (!movieVisits[movieId]) { movieVisits[movieId] = { count: 0, title: movieTitle }; } movieVisits[movieId].count += 1; - localStorage.setItem("movieVisits", JSON.stringify(movieVisits)); + localStorage.setItem('movieVisits', JSON.stringify(movieVisits)); } function getMostVisitedMovie() { - const movieVisits = JSON.parse(localStorage.getItem("movieVisits")) || {}; - let mostVisitedMovie = ""; + const movieVisits = JSON.parse(localStorage.getItem('movieVisits')) || {}; + let mostVisitedMovie = ''; let maxVisits = 0; for (const movieId in movieVisits) { @@ -812,11 +734,11 @@ function getMostVisitedMovie() { } } - return mostVisitedMovie || "Not Available"; + return mostVisitedMovie || 'Not Available'; } async function getMostVisitedMovieGenre() { - const movieVisits = JSON.parse(localStorage.getItem("movieVisits")) || {}; + const movieVisits = JSON.parse(localStorage.getItem('movieVisits')) || {}; let mostVisitedGenre = null; let maxVisits = 0; @@ -839,8 +761,8 @@ async function fetchGenreForMovie(movieId) { } function getMostVisitedActor() { - const actorVisits = JSON.parse(localStorage.getItem("actorVisits")) || {}; - let mostVisitedActor = ""; + const actorVisits = JSON.parse(localStorage.getItem('actorVisits')) || {}; + let mostVisitedActor = ''; let maxVisits = 0; for (const actorId in actorVisits) { @@ -850,13 +772,12 @@ function getMostVisitedActor() { } } - return mostVisitedActor || "Not Available"; + return mostVisitedActor || 'Not Available'; } function getMostVisitedDirector() { - const directorVisits = - JSON.parse(localStorage.getItem("directorVisits")) || {}; - let mostVisitedDirector = ""; + const directorVisits = JSON.parse(localStorage.getItem('directorVisits')) || {}; + let mostVisitedDirector = ''; let maxVisits = 0; for (const directorId in directorVisits) { @@ -865,16 +786,16 @@ function getMostVisitedDirector() { maxVisits = directorVisits[directorId].count; } } - return mostVisitedDirector || "Not Available"; + return mostVisitedDirector || 'Not Available'; } function getTriviaAccuracy() { - let triviaStats = JSON.parse(localStorage.getItem("triviaStats")) || { + let triviaStats = JSON.parse(localStorage.getItem('triviaStats')) || { totalCorrect: 0, totalAttempted: 0, }; if (triviaStats.totalAttempted === 0) { - return "No trivia attempted"; + return 'No trivia attempted'; } let accuracy = (triviaStats.totalCorrect / triviaStats.totalAttempted) * 100; @@ -882,14 +803,13 @@ function getTriviaAccuracy() { } function getMostCommonGenre() { - const favoriteGenresArray = - JSON.parse(localStorage.getItem("favoriteGenres")) || []; + const favoriteGenresArray = JSON.parse(localStorage.getItem('favoriteGenres')) || []; const genreCounts = favoriteGenresArray.reduce((acc, genre) => { acc[genre] = (acc[genre] || 0) + 1; return acc; }, {}); - let mostCommonGenre = ""; + let mostCommonGenre = ''; let maxCount = 0; for (const genre in genreCounts) { @@ -899,16 +819,16 @@ function getMostCommonGenre() { } } - return mostCommonGenre || "Not Available"; + return mostCommonGenre || 'Not Available'; } const movieCode = { - part1: "YzVhMjBjODY=", - part2: "MWFjZjdiYjg=", - part3: "ZDllOTg3ZGNjN2YxYjU1OA==", + part1: 'YzVhMjBjODY=', + part2: 'MWFjZjdiYjg=', + part3: 'ZDllOTg3ZGNjN2YxYjU1OA==', }; -document.addEventListener("DOMContentLoaded", rotateUserStats); +document.addEventListener('DOMContentLoaded', rotateUserStats); async function showMovieOfTheDay() { const year = new Date().getFullYear(); @@ -921,28 +841,26 @@ async function showMovieOfTheDay() { if (movies.length > 0) { const randomMovie = movies[Math.floor(Math.random() * movies.length)]; - localStorage.setItem("selectedMovieId", randomMovie.id); - window.location.href = "MovieVerse-Frontend/html/movie-details.html"; + localStorage.setItem('selectedMovieId', randomMovie.id); + window.location.href = 'MovieVerse-Frontend/html/movie-details.html'; } else { fallbackMovieSelection(); } } catch (error) { - console.log("Error fetching movie:", error); + console.log('Error fetching movie:', error); fallbackMovieSelection(); } } function fallbackMovieSelection() { const fallbackMovies = [ - 432413, 299534, 1726, 562, 118340, 455207, 493922, 447332, 22970, 530385, - 27205, 264660, 120467, 603, 577922, 76341, 539, 419704, 515001, 118340, 424, - 98, + 432413, 299534, 1726, 562, 118340, 455207, 493922, 447332, 22970, 530385, 27205, 264660, 120467, 603, 577922, 76341, 539, 419704, 515001, 118340, + 424, 98, ]; - const randomFallbackMovie = - fallbackMovies[Math.floor(Math.random() * fallbackMovies.length)]; + const randomFallbackMovie = fallbackMovies[Math.floor(Math.random() * fallbackMovies.length)]; - localStorage.setItem("selectedMovieId", randomFallbackMovie); - window.location.href = "MovieVerse-Frontend/html/movie-details.html"; + localStorage.setItem('selectedMovieId', randomFallbackMovie); + window.location.href = 'MovieVerse-Frontend/html/movie-details.html'; } function calculateMoviesToDisplay() { @@ -976,75 +894,71 @@ function calculateMoviesToDisplay() { function getClassByRate(vote) { if (vote >= 8) { - return "green"; + return 'green'; } else if (vote >= 5) { - return "orange"; + return 'orange'; } else { - return "red"; + return 'red'; } } -form.addEventListener("submit", (e) => { +form.addEventListener('submit', e => { e.preventDefault(); - const searchQuery = document.getElementById("search").value; + const searchQuery = document.getElementById('search').value; - localStorage.setItem("searchQuery", searchQuery); - window.location.href = "MovieVerse-Frontend/html/search.html"; + localStorage.setItem('searchQuery', searchQuery); + window.location.href = 'MovieVerse-Frontend/html/search.html'; }); function toggleNav() { - const sideNav = document.getElementById("side-nav"); + const sideNav = document.getElementById('side-nav'); - sideNav.classList.toggle("manual-toggle"); + sideNav.classList.toggle('manual-toggle'); adjustNavBar(); } function removeNavBar() { - const sideNav = document.getElementById("side-nav"); + const sideNav = document.getElementById('side-nav'); - if (sideNav.classList.contains("manual-toggle")) { - sideNav.classList.remove("manual-toggle"); + if (sideNav.classList.contains('manual-toggle')) { + sideNav.classList.remove('manual-toggle'); } adjustNavBar(); } function adjustNavBar() { - const sideNav = document.getElementById("side-nav"); + const sideNav = document.getElementById('side-nav'); - if (sideNav.classList.contains("manual-toggle")) { - sideNav.style.left = "0px"; + if (sideNav.classList.contains('manual-toggle')) { + sideNav.style.left = '0px'; } else { - sideNav.style.left = "-250px"; + sideNav.style.left = '-250px'; } } -document.addEventListener("mousemove", function (event) { - const sideNav = document.getElementById("side-nav"); +document.addEventListener('mousemove', function (event) { + const sideNav = document.getElementById('side-nav'); - if (event.clientX < 10 && !sideNav.classList.contains("manual-toggle")) { - sideNav.style.left = "0"; + if (event.clientX < 10 && !sideNav.classList.contains('manual-toggle')) { + sideNav.style.left = '0'; } }); -document.addEventListener("click", function (event) { - const sideNav = document.getElementById("side-nav"); - const navToggle = document.getElementById("nav-toggle"); +document.addEventListener('click', function (event) { + const sideNav = document.getElementById('side-nav'); + const navToggle = document.getElementById('nav-toggle'); - if ( - !sideNav.contains(event.target) && - !navToggle.contains(event.target) && - sideNav.classList.contains("manual-toggle") - ) { - sideNav.classList.remove("manual-toggle"); + if (!sideNav.contains(event.target) && !navToggle.contains(event.target) && sideNav.classList.contains('manual-toggle')) { + sideNav.classList.remove('manual-toggle'); adjustNavBar(); } }); -document.getElementById("side-nav").addEventListener("mouseleave", function () { - const sideNav = document.getElementById("side-nav"); +document.getElementById('side-nav').addEventListener('mouseleave', function () { + const sideNav = document.getElementById('side-nav'); - if (!sideNav.classList.contains("manual-toggle")) { - sideNav.style.left = "-250px"; + if (!sideNav.classList.contains('manual-toggle')) { + sideNav.style.left = '-250px'; } }); @@ -1053,32 +967,32 @@ const IMGPATH = `https://image.tmdb.org/t/p/w500`; const SEARCHPATH = `https://${getMovieVerseData()}/3/search/movie?&${generateMovieNames()}${getMovieCode()}&query=`; const directors = [ - { name: "Alfred Hitchcock", id: "2636" }, - { name: "Steven Spielberg", id: "488" }, - { name: "Martin Scorsese", id: "1032" }, - { name: "Quentin Tarantino", id: "138" }, - { name: "Christopher Nolan", id: "525" }, - { name: "Stanley Kubrick", id: "240" }, - { name: "Bong Joon-ho", id: "21684" }, - { name: "David Fincher", id: "7467" }, - { name: "James Cameron", id: "2710" }, - { name: "Francis Ford Coppola", id: "1776" }, - { name: "Tim Burton", id: "510" }, - { name: "Ridley Scott", id: "578" }, - { name: "Joel Coen", id: "1223" }, - { name: "Spike Lee", id: "5281" }, - { name: "Woody Allen", id: "1243" }, - { name: "Peter Jackson", id: "108" }, - { name: "Oliver Stone", id: "1152" }, - { name: "David Lynch", id: "5602" }, - { name: "Roman Polanski", id: "3556" }, - { name: "Wes Anderson", id: "5655" }, - { name: "Sergio Leone", id: "4385" }, - { name: "Akira Kurosawa", id: "5026" }, - { name: "Federico Fellini", id: "4415" }, - { name: "John Ford", id: "8500" }, - { name: "Fritz Lang", id: "68" }, - { name: "Frank Capra", id: "2662" }, + { name: 'Alfred Hitchcock', id: '2636' }, + { name: 'Steven Spielberg', id: '488' }, + { name: 'Martin Scorsese', id: '1032' }, + { name: 'Quentin Tarantino', id: '138' }, + { name: 'Christopher Nolan', id: '525' }, + { name: 'Stanley Kubrick', id: '240' }, + { name: 'Bong Joon-ho', id: '21684' }, + { name: 'David Fincher', id: '7467' }, + { name: 'James Cameron', id: '2710' }, + { name: 'Francis Ford Coppola', id: '1776' }, + { name: 'Tim Burton', id: '510' }, + { name: 'Ridley Scott', id: '578' }, + { name: 'Joel Coen', id: '1223' }, + { name: 'Spike Lee', id: '5281' }, + { name: 'Woody Allen', id: '1243' }, + { name: 'Peter Jackson', id: '108' }, + { name: 'Oliver Stone', id: '1152' }, + { name: 'David Lynch', id: '5602' }, + { name: 'Roman Polanski', id: '3556' }, + { name: 'Wes Anderson', id: '5655' }, + { name: 'Sergio Leone', id: '4385' }, + { name: 'Akira Kurosawa', id: '5026' }, + { name: 'Federico Fellini', id: '4415' }, + { name: 'John Ford', id: '8500' }, + { name: 'Fritz Lang', id: '68' }, + { name: 'Frank Capra', id: '2662' }, ]; let currentDirectorIndex = 0; @@ -1097,8 +1011,7 @@ setInterval(changeDirector, 3600000); function updateDirectorSpotlight() { const director = directors[currentDirectorIndex]; - document.getElementById("spotlight-director-name").textContent = - director.name; + document.getElementById('spotlight-director-name').textContent = director.name; const url = `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_people=${ director.id @@ -1107,26 +1020,7 @@ function updateDirectorSpotlight() { } function getMovieVerseData(input) { - return String.fromCharCode( - 97, - 112, - 105, - 46, - 116, - 104, - 101, - 109, - 111, - 118, - 105, - 101, - 100, - 98, - 46, - 111, - 114, - 103, - ); + return String.fromCharCode(97, 112, 105, 46, 116, 104, 101, 109, 111, 118, 105, 101, 100, 98, 46, 111, 114, 103); } function generateMovieNames(input) { @@ -1150,10 +1044,10 @@ async function getDirectorSpotlight(url) { } function showMoviesDirectorSpotlight(movies) { - director_main.innerHTML = ""; + director_main.innerHTML = ''; // Inject CSS for the sliding-up animation effect with delay support - const style = document.createElement("style"); + const style = document.createElement('style'); style.innerHTML = ` .movie { opacity: 0; @@ -1169,40 +1063,39 @@ function showMoviesDirectorSpotlight(movies) { // Observer to trigger the slide-up animation with a staggered delay const slideObserver = new IntersectionObserver( - (entries) => { + entries => { entries.forEach((entry, index) => { if (entry.isIntersecting) { const movieEl = entry.target; // Apply a staggered delay based on the card's index movieEl.style.transitionDelay = `${index * 100}ms`; // Adjust delay as needed - movieEl.classList.add("visible"); + movieEl.classList.add('visible'); slideObserver.unobserve(movieEl); } }); }, { - rootMargin: "50px 0px", + rootMargin: '50px 0px', threshold: 0.1, - }, + } ); movies.forEach((movie, index) => { const { id, poster_path, title, vote_average, genre_ids } = movie; - const movieEl = document.createElement("div"); + const movieEl = document.createElement('div'); - movieEl.classList.add("movie"); - movieEl.style.zIndex = "1000"; + movieEl.classList.add('movie'); + movieEl.style.zIndex = '1000'; // Movie image and fallback in case the image is unavailable const movieImage = poster_path ? `${title}` : `
Image Not Available
`; - const voteAvg = vote_average > 0 ? vote_average.toFixed(1) : "Unrated"; - const ratingClass = - vote_average > 0 ? getClassByRate(vote_average) : "unrated"; + const voteAvg = vote_average > 0 ? vote_average.toFixed(1) : 'Unrated'; + const ratingClass = vote_average > 0 ? getClassByRate(vote_average) : 'unrated'; movieEl.innerHTML = ` ${movieImage} @@ -1215,12 +1108,12 @@ function showMoviesDirectorSpotlight(movies) { ${movie.overview} `; - movieEl.addEventListener("click", () => { - localStorage.setItem("selectedMovieId", id); + movieEl.addEventListener('click', () => { + localStorage.setItem('selectedMovieId', id); updateUniqueMoviesViewed(id); updateFavoriteGenre(genre_ids); updateMovieVisitCount(id, title); - window.location.href = "MovieVerse-Frontend/html/movie-details.html"; + window.location.href = 'MovieVerse-Frontend/html/movie-details.html'; }); director_main.appendChild(movieEl); @@ -1231,13 +1124,13 @@ function showMoviesDirectorSpotlight(movies) { } function handleSignInOut() { - const isSignedIn = JSON.parse(localStorage.getItem("isSignedIn")) || false; + const isSignedIn = JSON.parse(localStorage.getItem('isSignedIn')) || false; if (isSignedIn) { - localStorage.setItem("isSignedIn", JSON.stringify(false)); - alert("You have been signed out."); + localStorage.setItem('isSignedIn', JSON.stringify(false)); + alert('You have been signed out.'); } else { - window.location.href = "MovieVerse-Frontend/html/sign-in.html"; + window.location.href = 'MovieVerse-Frontend/html/sign-in.html'; return; } @@ -1245,215 +1138,213 @@ function handleSignInOut() { } function updateSignInButtonState() { - const isSignedIn = JSON.parse(localStorage.getItem("isSignedIn")) || false; - const signInText = document.getElementById("signInOutText"); - const signInIcon = document.getElementById("signInIcon"); - const signOutIcon = document.getElementById("signOutIcon"); + const isSignedIn = JSON.parse(localStorage.getItem('isSignedIn')) || false; + const signInText = document.getElementById('signInOutText'); + const signInIcon = document.getElementById('signInIcon'); + const signOutIcon = document.getElementById('signOutIcon'); if (isSignedIn) { - signInText.textContent = "Sign Out"; - signInIcon.style.display = "none"; - signOutIcon.style.display = "inline-block"; + signInText.textContent = 'Sign Out'; + signInIcon.style.display = 'none'; + signOutIcon.style.display = 'inline-block'; } else { - signInText.textContent = "Sign In"; - signInIcon.style.display = "inline-block"; - signOutIcon.style.display = "none"; + signInText.textContent = 'Sign In'; + signInIcon.style.display = 'inline-block'; + signOutIcon.style.display = 'none'; } - const mobileSignInText = document.getElementById("mobileSignInOutText"); - const mobileSignInIcon = document.getElementById("mobileSignInIcon"); - const mobileSignOutIcon = document.getElementById("mobileSignOutIcon"); + const mobileSignInText = document.getElementById('mobileSignInOutText'); + const mobileSignInIcon = document.getElementById('mobileSignInIcon'); + const mobileSignOutIcon = document.getElementById('mobileSignOutIcon'); if (isSignedIn) { - mobileSignInText.textContent = "Sign Out"; - mobileSignInIcon.style.display = "none"; - mobileSignOutIcon.style.display = "inline-block"; + mobileSignInText.textContent = 'Sign Out'; + mobileSignInIcon.style.display = 'none'; + mobileSignOutIcon.style.display = 'inline-block'; } else { - mobileSignInText.textContent = "Sign In"; - mobileSignInIcon.style.display = "inline-block"; - mobileSignOutIcon.style.display = "none"; + mobileSignInText.textContent = 'Sign In'; + mobileSignInIcon.style.display = 'inline-block'; + mobileSignOutIcon.style.display = 'none'; } } setupPagination( - "award-winning", - "award-winning-pagination", - "award-winning-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&sort_by=vote_average.desc&vote_count.gte=1000`, + 'award-winning', + 'award-winning-pagination', + 'award-winning-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&sort_by=vote_average.desc&vote_count.gte=1000` ); setupPagination( - "hidden-gems", - "hidden-gems-pagination", - "hidden-gems-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&sort_by=vote_average.desc&vote_count.gte=100&vote_average.gte=7&popularity.lte=10`, + 'hidden-gems', + 'hidden-gems-pagination', + 'hidden-gems-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&sort_by=vote_average.desc&vote_count.gte=100&vote_average.gte=7&popularity.lte=10` ); setupPagination( - "western", - "western-pagination", - "western-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=37&sort_by=popularity.desc&vote_count.gte=8`, + 'western', + 'western-pagination', + 'western-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=37&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "war", - "war-pagination", - "war-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10752&sort_by=popularity.desc&vote_count.gte=8`, + 'war', + 'war-pagination', + 'war-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10752&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "vietnamese", - "vietnamese-pagination", - "vietnamese-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_original_language=vi&sort_by=popularity.desc`, + 'vietnamese', + 'vietnamese-pagination', + 'vietnamese-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_original_language=vi&sort_by=popularity.desc` ); setupPagination( - "korean", - "korean-pagination", - "korean-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_original_language=ko&sort_by=vote_average.desc,popularity.desc&vote_count.gte=10&vote_average.gte=8`, + 'korean', + 'korean-pagination', + 'korean-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_original_language=ko&sort_by=vote_average.desc,popularity.desc&vote_count.gte=10&vote_average.gte=8` ); setupPagination( - "musical", - "musical-pagination", - "musical-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10402&sort_by=popularity.desc&vote_count.gte=8`, + 'musical', + 'musical-pagination', + 'musical-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10402&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "drama", - "drama-pagination", - "drama-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=18&sort_by=popularity.desc&vote_count.gte=8`, + 'drama', + 'drama-pagination', + 'drama-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=18&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "indian", - "indian-pagination", - "indian-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_original_language=hi&sort_by=popularity.desc`, + 'indian', + 'indian-pagination', + 'indian-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_original_language=hi&sort_by=popularity.desc` ); setupPagination( - "action", - "action-pagination", - "action-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=28&sort_by=popularity.desc&vote_count.gte=8`, + 'action', + 'action-pagination', + 'action-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=28&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "horror", - "horror-pagination", - "horror-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=27&sort_by=popularity.desc&vote_count.gte=8`, + 'horror', + 'horror-pagination', + 'horror-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=27&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "documentary", - "documentary-pagination", - "documentary-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=99&sort_by=popularity.desc&vote_count.gte=8`, + 'documentary', + 'documentary-pagination', + 'documentary-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=99&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "animation", - "animation-pagination", - "animation-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=16&sort_by=popularity.desc&vote_count.gte=8`, + 'animation', + 'animation-pagination', + 'animation-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=16&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "sci-fi", - "sci-fi-pagination", - "sci-fi-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=878&sort_by=popularity.desc&vote_count.gte=8`, + 'sci-fi', + 'sci-fi-pagination', + 'sci-fi-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=878&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "romantic", - "romantic-pagination", - "romantic-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10749&sort_by=popularity.desc&vote_count.gte=8`, + 'romantic', + 'romantic-pagination', + 'romantic-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10749&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "thriller", - "thriller-pagination", - "thriller-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=53&sort_by=popularity.desc&vote_count.gte=8`, + 'thriller', + 'thriller-pagination', + 'thriller-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=53&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "mystery", - "mystery-pagination", - "mystery-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=9648&sort_by=popularity.desc&vote_count.gte=8`, + 'mystery', + 'mystery-pagination', + 'mystery-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=9648&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "comedy", - "comedy-pagination", - "comedy-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=35&sort_by=popularity.desc&vote_count.gte=8`, + 'comedy', + 'comedy-pagination', + 'comedy-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=35&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "fantasy", - "fantasy-pagination", - "fantasy-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=14&sort_by=popularity.desc&vote_count.gte=8`, + 'fantasy', + 'fantasy-pagination', + 'fantasy-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=14&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "family", - "family-pagination", - "family-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10751&sort_by=popularity.desc&vote_count.gte=8`, + 'family', + 'family-pagination', + 'family-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10751&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "tv-series", - "tv-series-pagination", - "tv-series-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10770&sort_by=popularity.desc&vote_count.gte=8`, + 'tv-series', + 'tv-series-pagination', + 'tv-series-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=10770&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "crime", - "crime-pagination", - "crime-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=80&sort_by=popularity.desc&vote_count.gte=8`, + 'crime', + 'crime-pagination', + 'crime-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&with_genres=80&sort_by=popularity.desc&vote_count.gte=8` ); setupPagination( - "classic", - "classic-pagination", - "classic-div", - `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&sort_by=popularity.desc&release_date.lte=1980`, + 'classic', + 'classic-pagination', + 'classic-div', + `https://${getMovieVerseData()}/3/discover/movie?${generateMovieNames()}${getMovieCode()}&sort_by=popularity.desc&release_date.lte=1980` ); -document.addEventListener("DOMContentLoaded", function () { +document.addEventListener('DOMContentLoaded', function () { updateSignInButtonState(); - document - .getElementById("googleSignInBtn") - .addEventListener("click", handleSignInOut); + document.getElementById('googleSignInBtn').addEventListener('click', handleSignInOut); }); function handleSearch() { - const searchQuery = document.getElementById("search").value; + const searchQuery = document.getElementById('search').value; - localStorage.setItem("searchQuery", searchQuery); - window.location.href = "MovieVerse-Frontend/html/search.html"; + localStorage.setItem('searchQuery', searchQuery); + window.location.href = 'MovieVerse-Frontend/html/search.html'; } -document.addEventListener("DOMContentLoaded", () => { - const notificationBtn = document.getElementById("notificationBtn"); +document.addEventListener('DOMContentLoaded', () => { + const notificationBtn = document.getElementById('notificationBtn'); - notificationBtn.addEventListener("click", () => { - window.location.href = "MovieVerse-Frontend/html/notifications.html"; + notificationBtn.addEventListener('click', () => { + window.location.href = 'MovieVerse-Frontend/html/notifications.html'; }); }); diff --git a/sitemap.xml b/sitemap.xml index 88ce0be4..74730b44 100644 --- a/sitemap.xml +++ b/sitemap.xml @@ -2,137 +2,137 @@ https://movie-verse.com/ - 2024-09-30 + 2024-11-15 1.00 https://movie-verse.com/MovieVerse-Frontend/html/about.html - 2024-09-30 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/favorites.html - 2024-09-30 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/movie-match.html - 2024-09-30 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/movie-timeline.html - 2024-09-30 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/notifications.html - 2024-09-30 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/chatbot.html - 2024-09-30 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/trivia.html - 2024-09-30 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/settings.html - 2024-09-30 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/chat.html - 2024-09-30 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/movie-details.html - 2024-09-30 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/director-details.html - 2024-09-30 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/actor-details.html - 2024-09-30 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/company-details.html - 2024-09-30 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/sign-in.html - 2024-09-30 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/create-account.html - 2024-09-30 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/reset-password.html - 2024-09-30 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/privacy-policy.html - 2024-09-30 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/terms-of-service.html - 2024-09-30 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/search.html - 2024-09-30 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/analytics.html - 2024-09-30 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/feedback.html - 2024-09-30 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/support.html - 2024-09-30 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/inception.html - 2024-09-30 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/user-profile.html - 2024-09-30 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/leonardo-dicaprio.html - 2024-09-30 + 2024-11-15 0.80 https://movie-verse.com/MovieVerse-Frontend/html/christopher-nolan.html - 2024-09-30 + 2024-11-15 0.80 From 4fd40f29c547d877cd206904558f17acbddcd101 Mon Sep 17 00:00:00 2001 From: Son Nguyen Date: Thu, 14 Nov 2024 09:18:10 -0500 Subject: [PATCH 2/2] Final: Enhanced app frontend --- .idea/dataSources.local.xml | 2 +- MovieVerse-Frontend/js/favorites.js | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.idea/dataSources.local.xml b/.idea/dataSources.local.xml index c3868c4f..bb108c86 100644 --- a/.idea/dataSources.local.xml +++ b/.idea/dataSources.local.xml @@ -1,6 +1,6 @@ - + #@ diff --git a/MovieVerse-Frontend/js/favorites.js b/MovieVerse-Frontend/js/favorites.js index 6e4206e5..133db635 100644 --- a/MovieVerse-Frontend/js/favorites.js +++ b/MovieVerse-Frontend/js/favorites.js @@ -1499,7 +1499,7 @@ async function displayFavoritesSection(titleText, items, displaySection) { if (items.length > 0) { const favoritesDiv = document.createElement('div'); favoritesDiv.className = 'watchlist'; - favoritesDiv.id = titleText.toLowerCase().replace(' ', '-'); + favoritesDiv.id = titleText.toLowerCase().replace(/\s+/g, '-'); const title = document.createElement('h3'); title.textContent = titleText; @@ -1509,8 +1509,10 @@ async function displayFavoritesSection(titleText, items, displaySection) { favoritesDiv.scrollIntoView({ behavior: 'smooth' }); }); + const titleTextNew = titleText === 'Favorite Movies' ? 'favorite movies' : 'favorite TV series'; + const description = document.createElement('p'); - description.textContent = `A collection of your ${titleText.toLowerCase()}.`; + description.textContent = `A collection of your ${titleTextNew}.`; description.className = 'watchlist-description'; favoritesDiv.appendChild(title); @@ -1527,8 +1529,9 @@ async function displayFavoritesSection(titleText, items, displaySection) { } else { const favoritesDiv = document.createElement('div'); favoritesDiv.className = 'watchlist'; - favoritesDiv.id = titleText.toLowerCase().replace(' ', '-'); - favoritesDiv.innerHTML = `

${titleText}

No ${titleText.toLowerCase()} added yet.

`; + favoritesDiv.id = titleText.toLowerCase().replace(/\s+/g, '-'); + const titleTextNew = titleText === 'Favorite Movies' ? 'favorite movies' : 'favorite TV series'; + favoritesDiv.innerHTML = `

${titleText}

No ${titleTextNew} added yet.

`; displaySection.appendChild(favoritesDiv); } }