@@ -62,34 +62,51 @@ document.addEventListener("DOMContentLoaded", function () {
6262 } ) ;
6363 }
6464
65+ function getCookie ( name ) {
66+ let cookies = document . cookie . split ( "; " ) ;
67+ for ( let cookie of cookies ) {
68+ let [ key , value ] = cookie . split ( "=" ) ;
69+ if ( key === name ) return value ;
70+ }
71+ return null ;
72+ }
73+
6574 function loadProblem ( problemData ) {
6675 const problemList = document . getElementById ( "problems" ) ;
67-
76+
6877 const card = document . createElement ( "div" ) ;
6978 card . classList . add ( "problem-card" ) ;
70-
79+
7180 const title = document . createElement ( "h3" ) ;
7281 title . textContent = problemData . title ;
73-
82+
7483 const details = document . createElement ( "p" ) ;
7584 details . innerHTML = `
7685 <strong>Author :</strong> ${ problemData . author } <br>
7786 <strong>Date :</strong>${ problemData . date } <br>
7887 <strong>Difficulty :</strong> <span class="${ problemData . difficulty } " data-text="${ problemData . difficulty } ">${ problemData . difficulty } </span> <br>
7988 <strong>Objective :</strong> <br> ${ problemData . objective }
8089 ` ;
81-
90+
8291 const btn = document . createElement ( "button" ) ;
8392 btn . textContent = "Select" ;
8493 btn . classList . add ( "problem-btn" ) ;
8594 btn . addEventListener ( "click" , ( ) => loadProblemData ( problemData ) ) ;
86-
95+
96+ if ( getCookie ( problemData . title ) === "completed" ) {
97+ const completedBadge = document . createElement ( "span" ) ;
98+ completedBadge . innerHTML = "<br> Completed ✅" ;
99+ completedBadge . classList . add ( "completed-badge" ) ;
100+ details . appendChild ( completedBadge ) ;
101+ }
102+
87103 card . appendChild ( title ) ;
88104 card . appendChild ( details ) ;
89105 card . appendChild ( btn ) ;
90106 problemList . appendChild ( card ) ;
91107 window . scrollTo ( { top : 0 , behavior : "smooth" } ) ;
92108 }
109+
93110
94111 function loadProblemData ( problemData ) {
95112 document . getElementById ( "problem-list" ) . style . display = "none" ;
@@ -105,7 +122,7 @@ document.addEventListener("DOMContentLoaded", function () {
105122 document . getElementById ( "actual-output" ) . textContent = "" ;
106123
107124 document . getElementById ( "inedit-details" ) . innerHTML = `
108- <strong>Title :</strong> ${ problemData . title } <br>
125+ <strong>Title :</strong> <span id="pb-title"> ${ problemData . title } </span> <br>
109126 <strong>Author :</strong> ${ problemData . author } <br>
110127 <strong>Date :</strong> ${ problemData . date } <br>
111128 <strong>Difficulty :</strong> ${ problemData . difficulty } <br>
@@ -116,7 +133,26 @@ document.addEventListener("DOMContentLoaded", function () {
116133 loadProblemList ( ) ;
117134} ) ;
118135
119- function showSuccessPopup ( ) {
136+ function showSuccessPopup ( pb_title ) {
137+ document . cookie = `${ pb_title } =completed; path=/; max-age=31536000` ;
138+
139+ // Chercher la carte du problème correspondant
140+ const problemCards = document . querySelectorAll ( ".problem-card h3" ) ;
141+ problemCards . forEach ( ( title ) => {
142+ if ( title . textContent === pb_title ) {
143+ const details = title . nextElementSibling ; // Le `<p>` contenant les infos du problème
144+
145+ // Vérifier si le badge existe déjà, sinon l'ajouter
146+ if ( ! details . querySelector ( ".completed-badge" ) ) {
147+ const completedBadge = document . createElement ( "span" ) ;
148+ completedBadge . innerHTML = "<br> Completed ✅" ;
149+ completedBadge . classList . add ( "completed-badge" ) ;
150+ details . appendChild ( completedBadge ) ;
151+ }
152+ }
153+ } ) ;
154+
155+ // Affichage du popup de succès
120156 const popup = document . createElement ( "div" ) ;
121157 popup . id = "success-popup" ;
122158 popup . innerHTML = `
@@ -133,13 +169,13 @@ function showSuccessPopup() {
133169 document . getElementById ( "main-container" ) . style . display = "none" ;
134170
135171 popup . classList . add ( "hide" ) ;
136-
137172 setTimeout ( ( ) => {
138173 document . body . removeChild ( popup ) ;
139174 } , 300 ) ;
140175 } ) ;
141176}
142177
178+
143179window . addEventListener ( "beforeunload" , function ( event ) {
144180 if ( document . getElementById ( "main-container" ) . style . display === "flex" ) {
145181 event . preventDefault ( ) ;
0 commit comments