| |
| const API_KEY = 'api_key=1cf50e6248dc270629e802686245c2c8'; |
| const BASE_URL = 'https://api.themoviedb.org/3'; |
| const API_URL = BASE_URL + '/discover/movie?sort_by=popularity.desc&' + API_KEY; |
| const IMG_URL = 'https://image.tmdb.org/t/p/w500'; |
|
|
| |
| document.addEventListener('DOMContentLoaded', async () => { |
| const rows = document.querySelectorAll('custom-row'); |
| |
| rows.forEach(async (row) => { |
| const category = row.getAttribute('category'); |
| let url; |
| |
| switch(category) { |
| case 'popular': |
| url = BASE_URL + '/movie/popular?' + API_KEY; |
| break; |
| case 'trending': |
| url = BASE_URL + '/trending/movie/week?' + API_KEY; |
| break; |
| case 'top_rated': |
| url = BASE_URL + '/movie/top_rated?' + API_KEY; |
| break; |
| default: |
| url = API_URL; |
| } |
| |
| try { |
| const res = await fetch(url); |
| const data = await res.json(); |
| row.setMovies(data.results); |
| } catch (error) { |
| console.error('Error fetching movies:', error); |
| } |
| }); |
| }); |
|
|
| |
| function searchMovies() { |
| const searchInput = document.getElementById('search-input').value; |
| if(searchInput) { |
| window.location.href = `search.html?query=${encodeURIComponent(searchInput)}`; |
| } |
| } |