From 350bec7cfe55385a4e3cf03dd547820c05aa7b0d Mon Sep 17 00:00:00 2001 From: johan Date: Sat, 7 Jan 2023 17:46:33 +0100 Subject: [PATCH] Comment est votre blanquette ? --- index.js | 17 +++++++++++++++ static/css/main.css | 4 ++++ static/index.html | 4 ++++ static/js/anim.js | 4 ++-- static/js/main.js | 50 ++++++++++++++++++++++++++++++++++++++++++--- 5 files changed, 74 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 9c3bf9f..12ed066 100644 --- a/index.js +++ b/index.js @@ -608,6 +608,23 @@ fastify.post('/isGolden', async (request, reply) => { } }) +fastify.get('/lastActivity', async (request, reply) => { + let curr_date = new Date() + for(acti in ActivityData) { + if(acti.type == "event" && curr_date < acti.start) { + return { + success: true, + activity: acti + } + } + } + + return { + success: false, + why: "No next activity" + } +}) + function saveData(path, data) { fs.writeFileSync(path, JSON.stringify(data)); } diff --git a/static/css/main.css b/static/css/main.css index bf317bd..5dc2c3d 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -262,6 +262,10 @@ button[type="submit"]:hover { margin-left: 10px; } +#error-message { + color: red; +} + @media screen and (max-width: 800px) { .bg-full { display: none; diff --git a/static/index.html b/static/index.html index 334810e..d424540 100644 --- a/static/index.html +++ b/static/index.html @@ -39,6 +39,7 @@

Prochaine activité

00:00:10 +

Mongolfière

Lorem ipsum dolor sit, amet consectetur adipisicing elit. Dicta tenetur tempora similique. A id esse expedita atque dolor eum itaque fugiat enim nisi dicta. Architecto mollitia quasi sed voluptatibus? Veniam.


@@ -102,6 +103,9 @@
+
+

+

diff --git a/static/js/anim.js b/static/js/anim.js index 4863aa3..66e1dc5 100644 --- a/static/js/anim.js +++ b/static/js/anim.js @@ -1,4 +1,4 @@ -var $animation_elements = $("#prank-desc, #activite-desc, #chasse-desc, #notice-espion"); +var $animation_elements = $("#prank-desc, #chasse-desc, #notice-espion"); var $window = $(window) function check_if_in_view() { @@ -18,7 +18,7 @@ function check_if_in_view() { if(!$element.hasClass('animated')) { $element.addClass('animated'); var a = new TypeIt('#' + $element.attr('id'), { - speed: 30, + speed: 50, lifeLike: true, }) .go(); diff --git a/static/js/main.js b/static/js/main.js index bf2a370..4e34ab8 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -27,6 +27,8 @@ function show_page(id, historyPush) { } } +//show_page("#demande-page"); + $("#login-button").click(function (e) { var data = JSON.stringify({ user: $("#login").val(), @@ -52,9 +54,24 @@ $("#login-button").click(function (e) { show_page('#demande-page'); } } else { - alert(data.why); + $('#error-message').empty(); + t = new TypeIt('#error-message', { + speed: 110, + lifeLike: true + }) + .type(data.why) + .go(); } + }, + error: function(e, status, i) { + $('#error-message').empty(); + t = new TypeIt('#error-message', { + speed: 110, + lifeLike: true + }) + .type(status) + .go(); } }); @@ -498,7 +515,6 @@ function refreshListener() { } $(window).on("load", function() { - /* Register the Service Worker */ if ('serviceWorker' in navigator) { navigator.serviceWorker.register('./js/sw.js'); @@ -508,6 +524,33 @@ $(window).on("load", function() { $(page[i]).css('z-index', page.length - i); } + $.ajax({ + type: "GET", + url: base_url + "lastActivity", + contentType: "application/json; charset=utf-8", + dataType: "json", + success: (data) => { + if(data.success) { + opt = {speed: 100, likeLike: true}; + new TypeIt("#activite-title", opt) + .type(data.activity.title) + .go(); + new TypeIt("#activite-desc", opt) + .type(data.activity.desc) + .go(); + let diff = Math.ceil( (data.activity.start - new Date()) / 1000 ) + let h = Math.round(diff / 3600) + let m = Math.round(diff / 60) - h*60 + let s = diff - m*60 + $("#timer").text((new Date('December 17, 1995 ' + [h, m, s].join(':'))).toLocaleTimeString('default', { + hour: '2-digit', + minute: '2-digit', + second: '2-digit' + })); + } + } + }) + /* load timer */ window.setInterval(function() { var time = $("#timer").text(); @@ -526,11 +569,12 @@ $(window).on("load", function() { t[1] = 0; t[2] = 0; } - $("#timer").text((new Date('December 17, 1995 ' + t.join(':'))).toLocaleTimeString('default', { + $('#timer').text((new Date('December 17, 1995 ' + t.join(':'))).toLocaleTimeString('default', { hour: '2-digit', minute: '2-digit', second: '2-digit' })); + }, 1000); });