From a37d2dd58a39d699770e3a375bacc9026dc6b2fc Mon Sep 17 00:00:00 2001 From: grey Date: Wed, 23 Feb 2022 22:17:12 +0100 Subject: [PATCH] EoD --- index.js | 17 +++++++++++------ static/js/countdown.js | 1 + static/js/script.js | 23 +++++++++++++++++++++-- templates/timerPage.html | 2 +- 4 files changed, 34 insertions(+), 9 deletions(-) create mode 120000 static/js/countdown.js diff --git a/index.js b/index.js index 26498ad..e915780 100644 --- a/index.js +++ b/index.js @@ -18,8 +18,8 @@ app.use( currentState = { mode: "clock", - timeLeft: "00:00:00", - timerInternal: 0, + countdownGoal: new Date(), + changed: true }; app.get("/", function (req, res) { @@ -30,7 +30,7 @@ app.get("/", function (req, res) { app.post("/", function (req, res) { console.log(req.body); currentState.mode = req.body.mode; - currentState.timeLeft = req.body.timeLeft; + currentState.countdownGoal = req.body.countdownGoal; res.send("OK"); }); @@ -40,7 +40,11 @@ app.get("/timer", function (req, res) { }); app.get("/api/v1/data", function (req, res) { + res.json(currentState); + if(req.query.markRead == "mark"){ + currentState.changed = false + } }); app.get("/api/v1/set/mode", function (req, res) { @@ -48,11 +52,12 @@ app.get("/api/v1/set/mode", function (req, res) { res.json({ status: "ok" }); }); -app.get("/api/v1/set/timeLeft", function (req, res) { - currentState.timerInternal = req.query.time; +app.get("/api/v1/set/timerGoal", function (req, res) { + currentState.countdownGoal = req.query.time; + currentState.changed = true res.json({ status: "ok" }); }); console.log(countdown( new Date(2022, 1, 24) ).toString()) -app.listen(3000); +app.listen(3005); diff --git a/static/js/countdown.js b/static/js/countdown.js new file mode 120000 index 0000000..71edd1e --- /dev/null +++ b/static/js/countdown.js @@ -0,0 +1 @@ +../../node_modules/countdown/countdown.js \ No newline at end of file diff --git a/static/js/script.js b/static/js/script.js index 16bbcb9..488d61a 100644 --- a/static/js/script.js +++ b/static/js/script.js @@ -1,13 +1,32 @@ +var newDateObj = new Date(); +newDateObj = new Date(newDateObj.getTime() + 1000*20) + function handleUpdate() { - resp = httpGet("/api/v1/data"); + resp = httpGet("/api/v1/data?markRead=mark"); var data = JSON.parse(resp); + if(data.changed){ + newDateObj = data.countdownGoal; + } + if (data.mode == "clock") { document.getElementById("timer").innerHTML = getTime(); document.getElementById("testImg").style.display = "none"; } else if (data.mode == "timer") { - document.getElementById("timer").innerHTML = data.timeLeft; + + countdown( + newDateObj, + function(ts) { + // console.log(ts) + if(ts.value <= 0){ + document.getElementById("timer").innerHTML = ('00'+ts.hours).slice(-2) + ":" + ('00'+ts.minutes).slice(-2) + ":" + ('00'+ts.seconds).slice(-2); + }else{ + document.getElementById("timer").innerHTML = "00:00:00" + } + + }, + countdown.HOURS|countdown.MINUTES|countdown.SECONDS); document.getElementById("testImg").style.display = "none"; } else if (data.mode == "black") { diff --git a/templates/timerPage.html b/templates/timerPage.html index ba2fb4d..6f8d751 100644 --- a/templates/timerPage.html +++ b/templates/timerPage.html @@ -11,7 +11,6 @@ - @@ -22,6 +21,7 @@ 00:00:00 +