@@ -55,6 +55,45 @@ document.addEventListener('DOMContentLoaded', async () => {
5555 showSection ( 'home' ) ;
5656 populateFilters ( ) ;
5757 displayPopularContent ( ) ;
58+
59+ const exportBtn = document . getElementById ( 'exportWatchedBtn' ) ;
60+ const importInput = document . getElementById ( 'importWatchedInput' ) ;
61+ if ( exportBtn ) {
62+ exportBtn . addEventListener ( 'click' , ( ) => {
63+ const data = localStorage . getItem ( 'watchedContent' ) || '{"films":{},"series":{}}' ;
64+ const blob = new Blob ( [ data ] , { type : 'application/json' } ) ;
65+ const url = URL . createObjectURL ( blob ) ;
66+ const a = document . createElement ( 'a' ) ;
67+ a . href = url ;
68+ a . download = 'streamit_progression.json' ;
69+ document . body . appendChild ( a ) ;
70+ a . click ( ) ;
71+ document . body . removeChild ( a ) ;
72+ URL . revokeObjectURL ( url ) ;
73+ } ) ;
74+ }
75+ if ( importInput ) {
76+ importInput . addEventListener ( 'change' , ( e ) => {
77+ const file = e . target . files [ 0 ] ;
78+ if ( ! file ) return ;
79+ const reader = new FileReader ( ) ;
80+ reader . onload = function ( evt ) {
81+ try {
82+ const imported = JSON . parse ( evt . target . result ) ;
83+ if ( imported . films && imported . series ) {
84+ localStorage . setItem ( 'watchedContent' , JSON . stringify ( imported ) ) ;
85+ alert ( 'Progression importée avec succès !' ) ;
86+ location . reload ( ) ;
87+ } else {
88+ alert ( 'Fichier invalide.' ) ;
89+ }
90+ } catch {
91+ alert ( 'Erreur lors de l\'import.' ) ;
92+ }
93+ } ;
94+ reader . readAsText ( file ) ;
95+ } ) ;
96+ }
5897} ) ;
5998
6099async function loadData ( ) {
0 commit comments