Skip to content

Commit

Permalink
Merge pull request #263 from NymexData/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
felipealfonsog authored Aug 1, 2023
2 parents dec2238 + 096a315 commit cb20ac2
Show file tree
Hide file tree
Showing 15 changed files with 160 additions and 82 deletions.
Binary file modified extension/.DS_Store
Binary file not shown.
Binary file removed extension/Theatherflix.zip
Binary file not shown.
Binary file added extension/Theatherflix_v1.1.0.zip
Binary file not shown.
Binary file modified images/.DS_Store
Binary file not shown.
Binary file added images/128x128_icon_logotflx.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/logo_rect.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/screenshots/.DS_Store
Binary file not shown.
Binary file added images/screenshots/sshot_bottom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/screenshots/sshot_top.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 3 additions & 9 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
{
"manifest_version": 3,
"name": "Theaterflix Extension",
"version": "1.0",
"version": "1.1.0",
"description": "Extension to display personalized recommendations for movies and series.",
"action": {
"default_popup": "popup/index.html"
"default_popup": "popup/index.html"
},
"icons": {
"48": "assets/icon.png"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["scripts/content.js"]
}
]
}
}
48 changes: 36 additions & 12 deletions popup/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,51 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Theaterflix Extension</title>
<link rel="stylesheet" href="styles/styles.css">
<link rel="stylesheet" href="../styles/styles.css">
<link rel="stylesheet" href="../styles/popup.css">
</head>
<body>
<h1>Personalized Recommendations</h1>
<div id="recommendations-list">
<!-- Recommendations will be displayed here -->
</div>
<div class="accordion">
<button class="accordion-header">Configure API Key</button>
<div class="accordion-content" style="display: none;">
<label for="api-key">Enter your TMDb API Key:</label>
<input type="text" id="api-key" placeholder="Type your API Key here">
<button id="save-button">Save</button>
</div>
<div class="accordion-header">Configure API Key</div>
<div id="config-section" class="active">
<label for="api-key">Enter your TMDb API Key:</label>
<input type="text" id="api-key" placeholder="Type your API Key here">
<button id="save-button">Save</button>
<p id="status-message"></p>
</div>

<!-- Add link to jQuery -->
<script src="scripts/jquery-3.6.0.min.js"></script>
<!-- Add links to jQuery and Axios -->
<script src="../scripts/jquery-3.6.0.min.js"></script>
<script src="../scripts/axios.min.js"></script>

<!-- Load the external api.js file -->
<script src="scripts/api.js"></script>
<script src="scripts/popup.js"></script>
<script src="../scripts/api.js"></script>

<!-- Load the popup.js script -->
<script src="../popup/popup.js"></script>

<!-- Developer's information -->
<div class="developer-info">
Developed by <a href="mailto:f.alfonso@res-ear.ch">Felipe Alfonso Gonzalez</a>, Computer Science Engineer
<br>
in collaboration with other members of Nymex Data Research.
<br>
This project is licensed under the MIT License.
<br>
<a href="https://github.com/felipealfonso" target="_blank" rel="noopener">
<img src="https://img.shields.io/badge/GitHub-Felipe%20Alfonso-blue.svg" alt="GitHub Felipe Alfonso">
</a>
&nbsp;|&nbsp;
<a href="https://github.com/NymexData" target="_blank" rel="noopener">
<img src="https://img.shields.io/badge/GitHub-Nymex%20Data-blue.svg" alt="GitHub Nymex Data">
</a>
&nbsp;|&nbsp;
<a href="https://github.com/NymexData/Theaterflix" target="_blank" rel="noopener">
<img src="https://img.shields.io/badge/GitHub-Repository-blue.svg" alt="GitHub Repository">
</a>
</div>
</body>
</html>
30 changes: 18 additions & 12 deletions popup/popup.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
// popup.js
// popup/popup.js

$(document).ready(function() {
// Add accordion behavior using jQuery
$('.accordion-header').click(function() {
$('.accordion-content').slideToggle();
// Add a click event listener to toggle the configuration section
document.addEventListener('DOMContentLoaded', () => {
const configButton = document.querySelector('.accordion-header');
const configSection = document.getElementById('config-section');

configButton.addEventListener('click', () => {
configSection.classList.toggle('active');
});

// Add a click event listener to save the API key
$('#save-button').click(function() {
const apiKey = $('#api-key').val();
const saveButton = document.getElementById('save-button');
const apiKeyInput = document.getElementById('api-key');
const statusMessage = document.getElementById('status-message');

saveButton.addEventListener('click', () => {
const apiKey = apiKeyInput.value;
if (apiKey) {
// Save the API key to local storage or wherever you need to store it
// For simplicity, let's store it in local storage
// Save the API key to local storage
localStorage.setItem('tmdb_api_key', apiKey);
// Optionally, you can display a success message to the user
alert('API Key saved successfully!');
// Display a success message to the user
statusMessage.textContent = 'API Key saved successfully!';
} else {
alert('Please enter a valid API Key.');
statusMessage.textContent = 'Please enter a valid API Key.';
}
});
});
93 changes: 44 additions & 49 deletions scripts/api.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,53 @@
// scripts/api.js
const recommendationsContainer = document.getElementById('recommendations');
// api.js

// Function to fetch recommendations from the TMDB API using the user's API key
async function fetchRecommendations(apiKey) {
// Function to fetch movie recommendations using the provided API key
async function fetchMovieRecommendations(apiKey) {
try {
// Fetch recommendations data from the TMDB API using the user's API key
const response = await axios.get('https://api.themoviedb.org/3/discover/movie', {
params: {
api_key: apiKey,
language: 'en-US',
sort_by: 'popularity.desc',
include_adult: false,
include_video: false,
page: 1,
},
});

const recommendationsData = response.data.results;
// Process the data and display recommendations in the popup
displayRecommendations(recommendationsData);
const response = await axios.get(`https://api.themoviedb.org/3/movie/popular?api_key=${apiKey}`);
return response.data.results;
} catch (error) {
console.error('Error fetching recommendations:', error);
console.error('Error fetching movie recommendations:', error);
return [];
}
}

// Function to display the recommendations in the popup
function displayRecommendations(recommendationsData) {
recommendationsContainer.innerHTML = '';

recommendationsData.forEach((recommendation) => {
const { title, poster_path, vote_average } = recommendation;
const poster = `https://image.tmdb.org/t/p/w200${poster_path}`;
const rating = vote_average.toFixed(1);

const recommendationElement = document.createElement('div');
recommendationElement.classList.add('recommendation');
recommendationElement.innerHTML = `
<img src="${poster}" alt="${title}">
<h3>${title}</h3>
<p>Rating: ${rating}/10</p>
<hr>
`;

recommendationsContainer.appendChild(recommendationElement);
// Function to render movie recommendations in the popup
function renderMovieRecommendations(recommendations) {
const recommendationsList = document.getElementById('recommendations-list');

recommendationsList.innerHTML = ''; // Clear previous recommendations

recommendations.forEach((movie) => {
const movieBox = document.createElement('div');
movieBox.className = 'movie-box';

const moviePoster = document.createElement('img');
moviePoster.className = 'movie-poster';
moviePoster.src = `https://image.tmdb.org/t/p/w185${movie.poster_path}`;
movieBox.appendChild(moviePoster);

const movieInfo = document.createElement('div');
movieInfo.className = 'movie-info';

const movieTitle = document.createElement('h2');
movieTitle.textContent = movie.title;
movieInfo.appendChild(movieTitle);

const movieOverview = document.createElement('p');
movieOverview.textContent = movie.overview;
movieInfo.appendChild(movieOverview);

movieBox.appendChild(movieInfo);
recommendationsList.appendChild(movieBox);
});
}

// Fetch the user's API key from local storage
chrome.storage.local.get(['apiKey'], (result) => {
const apiKey = result.apiKey;
if (apiKey) {
fetchRecommendations(apiKey);
} else {
// Display a message to prompt the user to enter their API key
console.log('Please enter your API key.');
}
});
// Check if the API key is already saved in local storage
const apiKey = localStorage.getItem('tmdb_api_key');

// If the API key is already saved, fetch and render movie recommendations
if (apiKey) {
fetchMovieRecommendations(apiKey)
.then((recommendations) => renderMovieRecommendations(recommendations))
.catch((error) => console.error('Error fetching movie recommendations:', error));
}
42 changes: 42 additions & 0 deletions styles/popup.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* styles/popup.css */
/* popup.css */
body {
width: 600px; /* Set the width of the popup */
margin: 20px auto; /* Center the popup horizontally */
padding: 20px;
}

#recommendations-list {
list-style: none;
padding: 0;
}

.movie-box {
border: 1px solid #ccc;
padding: 10px;
margin-bottom: 10px;
display: flex;
}

.movie-poster {
width: 100px;
height: 150px;
object-fit: cover;
margin-right: 10px;
}

.movie-info {
flex: 1;
}


/* CSS styles for the configuration section */
#config-section {
display: none;
border: 1px solid #ccc;
padding: 10px;
margin-bottom: 10px;
}
#config-section.active {
display: block;
}
17 changes: 17 additions & 0 deletions styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,20 @@ h1 {
.accordion.active .accordion-content {
display: block;
}


/* Add CSS for the accordion */
.accordion-header {
cursor: pointer;
padding: 15px;
background-color: #f1f1f1;
border: 1px solid #ccc;
border-radius: 5px;
}

.accordion-content {
display: none;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}

0 comments on commit cb20ac2

Please sign in to comment.