Skip to content

Commit 0dbe6fc

Browse files
author
0adri3n
committed
storing completed pb in cookie for 1 year
1 parent 123fa23 commit 0dbe6fc

File tree

4 files changed

+65
-11
lines changed

4 files changed

+65
-11
lines changed

how2play.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<title>How to Play - BPP</title>
77
<link rel="icon" href="src/img/logo_bpp_ico.ico">
8+
9+
<!-- Stylesheets -->
810
<link rel="stylesheet" href="src/css/style.css">
11+
<link rel="stylesheet" href="src/css/header.css">
12+
<link rel="stylesheet" href="src/css/problems.css">
13+
<link rel="stylesheet" href="src/css/solve_area.css">
14+
<link rel="stylesheet" href="src/css/pop_up.css">
15+
<link rel="stylesheet" href="src/css/footer.css">
16+
917
</head>
1018
<body>
1119

index.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<meta property="og:description" content="bpp : challenge your skills and solve Python problems." />
2424
<meta name="theme-color" content="#3b2c52">
2525

26+
<!-- Stylesheets -->
2627
<link rel="stylesheet" href="src/css/style.css">
2728
<link rel="stylesheet" href="src/css/header.css">
2829
<link rel="stylesheet" href="src/css/problems.css">
@@ -31,7 +32,6 @@
3132
<link rel="stylesheet" href="src/css/footer.css">
3233

3334

34-
3535
</head>
3636
<body onload="brython()">
3737

@@ -153,8 +153,9 @@ <h2>BPP Problems list</h2>
153153
valid = False
154154

155155
if valid :
156-
window.showSuccessPopup()
157-
156+
157+
window.showSuccessPopup(document["pb-title"].text)
158+
158159

159160
sys.stdout = sys.__stdout__
160161
sys.stderr = sys.__stderr__
@@ -165,6 +166,7 @@ <h2>BPP Problems list</h2>
165166
</script>
166167

167168
<script>
169+
168170
// Init & Edit editor
169171

170172
var editor = ace.edit("editor");

src/css/problems.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,11 @@
188188
transform: translate(2px, -2px);
189189
}
190190
}
191+
192+
193+
/* Completed badge */
194+
.completed-badge {
195+
margin-left: 10px;
196+
font-size: 1.2em;
197+
color: green;
198+
}

src/js/load_problems.js

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
143179
window.addEventListener("beforeunload", function (event) {
144180
if (document.getElementById("main-container").style.display === "flex") {
145181
event.preventDefault();

0 commit comments

Comments
 (0)