Skip to content

Commit 5c112f3

Browse files
committed
Added dynamic stats display feature & Enhanced UI
1 parent 7d6eab1 commit 5c112f3

38 files changed

+8576
-2665
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Upon launching The MovieVerse, you'll be greeted with a user-friendly interface
6060
- View detailed information about an actor by clicking the 'Details' button on any actor in a movie's details page.
6161
- Create a movie timeline by clicking the 'Timeline' button on the navigation bar.
6262
- View a list of movies from a specific time period by clicking on the corresponding year in the timeline.
63+
- View all your interesting statistics with a dynamically updating display that will work best on a desktop. On mobile, you can click the 'About' button on the top navbar to view your statistics.
6364
- And more!
6465

6566
## Technologies

index.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ <h1 id="my-heading" style="margin-bottom: -10px">
5555
</h1>
5656
</a>
5757

58-
<div id="local-time">
59-
<p id="time-label">Your Current Time:</p>
60-
<h1 id="clock" class="clock"></h1>
58+
<div id="local-time" style="cursor: pointer">
59+
<p id="stats-label" class="clock" style="font-size: 16px"></p>
60+
<h1 id="stats-display" class="clock"></h1>
6161
</div>
6262

6363
<!-- Create a button to toggle the side navigation bar -->

index.js

+184-16
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,189 @@ function showMovies(movies, mainElement) {
9696

9797
movieEl.addEventListener('click', () => {
9898
localStorage.setItem('selectedMovieId', id);
99+
updateUniqueMoviesViewed(id);
99100
window.location.href = 'src/html/movie-details.html';
101+
updateMovieVisitCount(id, title);
100102
});
101103

102104
mainElement.appendChild(movieEl);
103105
});
104106
applySettings();
105107
}
106108

109+
function updateUniqueMoviesViewed(movieId) {
110+
let viewedMovies = JSON.parse(localStorage.getItem('uniqueMoviesViewed')) || [];
111+
if (!viewedMovies.includes(movieId)) {
112+
viewedMovies.push(movieId);
113+
localStorage.setItem('uniqueMoviesViewed', JSON.stringify(viewedMovies));
114+
}
115+
}
116+
107117
clearButton.addEventListener('click', () => {
108118
window.location.reload();
109119
});
110120

121+
function rotateUserStats() {
122+
const stats = [
123+
{
124+
label: "Your Current Time",
125+
getValue: () => {
126+
const now = new Date();
127+
let hours = now.getHours();
128+
let minutes = now.getMinutes();
129+
hours = hours < 10 ? '0' + hours : hours;
130+
minutes = minutes < 10 ? '0' + minutes : minutes;
131+
return `${hours}:${minutes}`;
132+
}
133+
},
134+
{ label: "Most Visited Movie", getValue: getMostVisitedMovie },
135+
{ label: "Your Most Visited Director", getValue: getMostVisitedDirector },
136+
{ label: "Your Most Visited Actor", getValue: getMostVisitedActor },
137+
{
138+
label: "Your Unique Movies Discovered",
139+
getValue: () => {
140+
const viewedMovies = JSON.parse(localStorage.getItem('uniqueMoviesViewed')) || [];
141+
return viewedMovies.length;
142+
}
143+
},
144+
{
145+
label: "Your Favorited Movies",
146+
getValue: () => {
147+
const favoritedMovies = JSON.parse(localStorage.getItem('favorites')) || [];
148+
return favoritedMovies.length;
149+
}
150+
},
151+
{
152+
label: "Your Most Common Favorited Genre",
153+
getValue: getMostCommonGenre
154+
},
155+
{ label: "Your Created Watchlists", getValue: () => localStorage.getItem('watchlistsCreated') || 0 },
156+
{ label: "Your Average Movie Rating", getValue: () => localStorage.getItem('averageMovieRating') || 'Not Rated' },
157+
{
158+
label: "Your Unique Directors Discovered",
159+
getValue: () => {
160+
const viewedDirectors = JSON.parse(localStorage.getItem('uniqueDirectorsViewed')) || [];
161+
return viewedDirectors.length;
162+
}
163+
},
164+
{
165+
label: "Your Unique Actors Discovered",
166+
getValue: () => {
167+
const viewedActors = JSON.parse(localStorage.getItem('uniqueActorsViewed')) || [];
168+
return viewedActors.length;
169+
}
170+
},
171+
{
172+
label: "Your Unique Production Companies Discovered",
173+
getValue: () => {
174+
const viewedCompanies = JSON.parse(localStorage.getItem('uniqueCompaniesViewed')) || [];
175+
return viewedCompanies.length;
176+
}
177+
},
178+
{ label: "Your Trivia Accuracy", getValue: getTriviaAccuracy }
179+
];
180+
181+
let currentStatIndex = 0;
182+
183+
function updateStatDisplay() {
184+
const currentStat = stats[currentStatIndex];
185+
document.getElementById('stats-label').textContent = currentStat.label + ':';
186+
document.getElementById('stats-display').textContent = currentStat.getValue();
187+
currentStatIndex = (currentStatIndex + 1) % stats.length;
188+
}
189+
190+
updateStatDisplay();
191+
192+
const localTimeDiv = document.getElementById('local-time');
193+
let statRotationInterval = setInterval(updateStatDisplay, 3000);
194+
195+
localTimeDiv.addEventListener('click', () => {
196+
clearInterval(statRotationInterval);
197+
updateStatDisplay();
198+
statRotationInterval = setInterval(updateStatDisplay, 3000);
199+
});
200+
}
201+
202+
function updateMovieVisitCount(movieId, movieTitle) {
203+
let movieVisits = JSON.parse(localStorage.getItem('movieVisits')) || {};
204+
if (!movieVisits[movieId]) {
205+
movieVisits[movieId] = { count: 0, title: movieTitle };
206+
}
207+
movieVisits[movieId].count += 1;
208+
localStorage.setItem('movieVisits', JSON.stringify(movieVisits));
209+
}
210+
211+
function getMostVisitedMovie() {
212+
const movieVisits = JSON.parse(localStorage.getItem('movieVisits')) || {};
213+
let mostVisitedMovie = '';
214+
let maxVisits = 0;
215+
216+
for (const movieId in movieVisits) {
217+
if (movieVisits[movieId].count > maxVisits) {
218+
mostVisitedMovie = movieVisits[movieId].title;
219+
maxVisits = movieVisits[movieId].count;
220+
}
221+
}
222+
223+
return mostVisitedMovie || 'Not Available';
224+
}
225+
226+
function getMostVisitedActor() {
227+
const actorVisits = JSON.parse(localStorage.getItem('actorVisits')) || {};
228+
let mostVisitedActor = '';
229+
let maxVisits = 0;
230+
231+
for (const actorId in actorVisits) {
232+
if (actorVisits[actorId].count > maxVisits) {
233+
mostVisitedActor = actorVisits[actorId].name;
234+
maxVisits = actorVisits[actorId].count;
235+
}
236+
}
237+
238+
return mostVisitedActor || 'Not Available';
239+
}
240+
241+
function getMostVisitedDirector() {
242+
const directorVisits = JSON.parse(localStorage.getItem('directorVisits')) || {};
243+
let mostVisitedDirector = '';
244+
let maxVisits = 0;
245+
246+
for (const directorId in directorVisits) {
247+
if (directorVisits[directorId].count > maxVisits) {
248+
mostVisitedDirector = directorVisits[directorId].name;
249+
maxVisits = directorVisits[directorId].count;
250+
}
251+
}
252+
253+
return mostVisitedDirector || 'Not Available';
254+
}
255+
256+
function getTriviaAccuracy() {
257+
let triviaStats = JSON.parse(localStorage.getItem('triviaStats')) || { totalCorrect: 0, totalAttempted: 0 };
258+
if (triviaStats.totalAttempted === 0) {
259+
return 'No trivia attempted';
260+
}
261+
let accuracy = (triviaStats.totalCorrect / triviaStats.totalAttempted) * 100;
262+
return `${accuracy.toFixed(1)}% accuracy`;
263+
}
264+
265+
function getMostCommonGenre() {
266+
const favoriteGenres = JSON.parse(localStorage.getItem('favoriteGenres')) || {};
267+
let mostCommonGenre = '';
268+
let maxCount = 0;
269+
270+
for (const genre in favoriteGenres) {
271+
if (favoriteGenres[genre] > maxCount) {
272+
mostCommonGenre = genre;
273+
maxCount = favoriteGenres[genre];
274+
}
275+
}
276+
277+
return mostCommonGenre || 'Not Available';
278+
}
279+
280+
document.addEventListener('DOMContentLoaded', rotateUserStats);
281+
111282
/**
112283
* Fetches a random movie from the specified URL and redirects to the movie-details page.
113284
* @returns {Promise<void>} A promise that resolves when the movie is fetched
@@ -458,6 +629,7 @@ function showMoviesDirectorSpotlight(movies) {
458629
movieE1.addEventListener('click', () => {
459630
localStorage.setItem('selectedMovieId', id);
460631
window.location.href = 'src/html/movie-details.html';
632+
updateMovieVisitCount(id, title);
461633
});
462634

463635
main20.appendChild(movieE1);
@@ -517,22 +689,6 @@ document.addEventListener("DOMContentLoaded", function() {
517689
applySettings();
518690
});
519691

520-
/**
521-
* Updates the clock.
522-
*/
523-
function updateClock() {
524-
var now = new Date();
525-
var hours = now.getHours();
526-
var minutes = now.getMinutes();
527-
hours = hours < 10 ? '0' + hours : hours;
528-
minutes = minutes < 10 ? '0' + minutes : minutes;
529-
var timeString = hours + ':' + minutes;
530-
document.getElementById('clock').innerHTML = timeString;
531-
}
532-
533-
setInterval(updateClock, 1000);
534-
window.onload = updateClock;
535-
536692
function checkAndClearLocalStorage() {
537693
const hasCleared = localStorage.getItem('hasUserClearedMovieVerseData');
538694
if (!hasCleared) {
@@ -551,6 +707,18 @@ function clearMovieVerseLocalStorage() {
551707
localStorage.removeItem('selectedActorId');
552708
localStorage.removeItem('selectedCompanyId');
553709
localStorage.removeItem('movieRatings');
710+
localStorage.removeItem('triviaStats');
711+
localStorage.removeItem('uniqueMoviesViewed');
712+
localStorage.removeItem('uniqueDirectorsViewed');
713+
localStorage.removeItem('uniqueActorsViewed');
714+
localStorage.removeItem('uniqueCompaniesViewed');
715+
localStorage.removeItem('favoriteGenres');
716+
localStorage.removeItem('watchlistsCreated');
717+
localStorage.removeItem('averageMovieRating');
718+
localStorage.removeItem('backgroundImage');
719+
localStorage.removeItem('textColor');
720+
localStorage.removeItem('fontSize');
721+
localStorage.removeItem('moviesFavorited');
554722
}
555723

556724
function applySettings() {

manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
"purpose": "any maskable"
2525
}
2626
]
27-
}
27+
}

0 commit comments

Comments
 (0)