Skip to content

Commit 6e12331

Browse files
committed
feat: add birthday easter egg
1 parent b7076a6 commit 6e12331

File tree

2 files changed

+95
-1
lines changed

2 files changed

+95
-1
lines changed

src/website/src/views/layout/base.ejs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
<!-- Theme -->
6565
<link href="/stylesheets/style.css"
6666
rel="stylesheet">
67+
<!-- Confetti -->
68+
<script src="https://cdn.jsdelivr.net/npm/canvas-confetti@1.9.3/dist/confetti.browser.min.js"></script>
6769
<!-- Google -->
6870
<script async
6971
src="https://www.googletagmanager.com/gtag/js?id=G-B4HH4VHYV9"></script>

src/website/src/views/pages/homepage/homepage.ejs

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,101 @@
206206
</div>
207207
</main>
208208
<%- include("../../partials/_footer.ejs") %>
209+
<div class="modal fade"
210+
id="birthdayModal"
211+
tabindex="-1"
212+
role="dialog"
213+
aria-labelledby="birthdayModalLabel"
214+
aria-hidden="true">
215+
<div class="modal-dialog modal-dialog-centered"
216+
role="document">
217+
<div class="modal-content">
218+
<div class="modal-header">
219+
<h5 class="modal-title"
220+
id="birthdayModalLabel">Feliz Aniversário António!</h5>
221+
<button type="button"
222+
class="close"
223+
data-dismiss="modal"
224+
aria-label="Close">
225+
<span aria-hidden="true">&times;</span>
226+
</button>
227+
</div>
228+
</div>
229+
</div>
230+
</div>
209231
</div>
210232

211233
<script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>
212234
<script>
213-
AOS.init()
235+
AOS.init()
236+
</script>
237+
238+
<script>
239+
$(document).ready(() => {
240+
const today = new Date();
241+
const isBirthday = today.getDate() === 21 && today.getMonth() === 9;
242+
243+
if (!isBirthday) {
244+
return;
245+
}
246+
247+
const birthdayCanvas = document.createElement('canvas');
248+
birthdayCanvas.style.position = 'fixed';
249+
birthdayCanvas.style.top = 0;
250+
birthdayCanvas.style.left = 0;
251+
birthdayCanvas.style.width = '100vw';
252+
birthdayCanvas.style.height = '100vh';
253+
birthdayCanvas.style.zIndex = 1045;
254+
document.body.appendChild(birthdayCanvas);
255+
256+
const animation = confetti.create(birthdayCanvas, {
257+
resize: true,
258+
useWorker: true
259+
});
260+
261+
let duration = 10000;
262+
let animationEnd = Date.now() + duration;
263+
let defaults = { startVelocity: 30, spread: 360, ticks: 60, zIndex: 1045 };
264+
265+
function randomInRange(min, max) {
266+
return Math.random() * (max - min) + min;
267+
}
268+
269+
let interval;
270+
function startConfetti() {
271+
interval = setInterval(function () {
272+
let timeLeft = animationEnd - Date.now();
273+
274+
if (timeLeft <= 0) {
275+
stopAndCleanup();
276+
return;
277+
}
278+
279+
let particleCount = 50 * (timeLeft / duration);
280+
animation({ ...defaults, particleCount, origin: { x: randomInRange(0.1, 0.3), y: Math.random() - 0.2 } });
281+
animation({ ...defaults, particleCount, origin: { x: randomInRange(0.7, 0.9), y: Math.random() - 0.2 } });
282+
}, 250);
283+
}
284+
285+
function stopAndCleanup() {
286+
if (interval) {
287+
clearInterval(interval);
288+
}
289+
$('#birthdayModal').modal('hide');
290+
if (document.body.contains(birthdayCanvas)) {
291+
document.body.removeChild(birthdayCanvas);
292+
}
293+
}
294+
295+
$('#birthdayModal').on('hidden.bs.modal', function () {
296+
stopAndCleanup();
297+
});
298+
299+
$('#birthdayModal').modal('show');
300+
startConfetti();
301+
302+
setTimeout(() => {
303+
$('#birthdayModal').modal('hide');
304+
}, duration);
305+
});
214306
</script>

0 commit comments

Comments
 (0)