@@ -96,18 +96,189 @@ function showMovies(movies, mainElement) {
96
96
97
97
movieEl . addEventListener ( 'click' , ( ) => {
98
98
localStorage . setItem ( 'selectedMovieId' , id ) ;
99
+ updateUniqueMoviesViewed ( id ) ;
99
100
window . location . href = 'src/html/movie-details.html' ;
101
+ updateMovieVisitCount ( id , title ) ;
100
102
} ) ;
101
103
102
104
mainElement . appendChild ( movieEl ) ;
103
105
} ) ;
104
106
applySettings ( ) ;
105
107
}
106
108
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
+
107
117
clearButton . addEventListener ( 'click' , ( ) => {
108
118
window . location . reload ( ) ;
109
119
} ) ;
110
120
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
+
111
282
/**
112
283
* Fetches a random movie from the specified URL and redirects to the movie-details page.
113
284
* @returns {Promise<void> } A promise that resolves when the movie is fetched
@@ -458,6 +629,7 @@ function showMoviesDirectorSpotlight(movies) {
458
629
movieE1 . addEventListener ( 'click' , ( ) => {
459
630
localStorage . setItem ( 'selectedMovieId' , id ) ;
460
631
window . location . href = 'src/html/movie-details.html' ;
632
+ updateMovieVisitCount ( id , title ) ;
461
633
} ) ;
462
634
463
635
main20 . appendChild ( movieE1 ) ;
@@ -517,22 +689,6 @@ document.addEventListener("DOMContentLoaded", function() {
517
689
applySettings ( ) ;
518
690
} ) ;
519
691
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
-
536
692
function checkAndClearLocalStorage ( ) {
537
693
const hasCleared = localStorage . getItem ( 'hasUserClearedMovieVerseData' ) ;
538
694
if ( ! hasCleared ) {
@@ -551,6 +707,18 @@ function clearMovieVerseLocalStorage() {
551
707
localStorage . removeItem ( 'selectedActorId' ) ;
552
708
localStorage . removeItem ( 'selectedCompanyId' ) ;
553
709
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' ) ;
554
722
}
555
723
556
724
function applySettings ( ) {
0 commit comments