diff --git a/index.js b/index.js index e915780..e8bd322 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,6 @@ const express = require("express"); const fs = require("fs"); const bodyParser = require("body-parser"); -const countdown = require("countdown") const app = express(); @@ -18,8 +17,10 @@ app.use( currentState = { mode: "clock", - countdownGoal: new Date(), - changed: true + countdownGoal: new Date().getTime(), + changed: true, + showMilliSeconds: true, + defaultFullScreen: true }; app.get("/", function (req, res) { @@ -40,11 +41,7 @@ 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) { @@ -52,12 +49,20 @@ app.get("/api/v1/set/mode", function (req, res) { res.json({ status: "ok" }); }); -app.get("/api/v1/set/timerGoal", function (req, res) { - currentState.countdownGoal = req.query.time; - currentState.changed = true +app.get("/api/v1/set/showMillis", function (req, res) { + currentState.showMilliSeconds = (req.query.show === 'true'); res.json({ status: "ok" }); }); -console.log(countdown( new Date(2022, 1, 24) ).toString()) +app.get("/api/v1/set/timerGoal", function (req, res) { + currentState.countdownGoal = new Date(parseInt(req.query.time)).getTime(); + res.json({ status: "ok" }); +}); + +app.get("/api/v1/set/addMillisToTimer", function (req, res) { + console.log(req.query.time) + currentState.countdownGoal = new Date().getTime() + parseInt(req.query.time) + res.json({ status: "ok" }); +}); app.listen(3005); diff --git a/static/css/smallerTextMod.css b/static/css/smallerTextMod.css new file mode 100644 index 0000000..1b5f4ab --- /dev/null +++ b/static/css/smallerTextMod.css @@ -0,0 +1,3 @@ +body { + font-size:0.5em; +} \ No newline at end of file diff --git a/static/css/styles.css b/static/css/styles.css index 7e189ae..ed5f7e8 100644 --- a/static/css/styles.css +++ b/static/css/styles.css @@ -23,11 +23,14 @@ html, body { } .timer { - font-size: 200px; + font-size: 20em; text-align: center; + font-variant-numeric: tabular-nums; + font-family: sans-serif; } .testImg{ height: 100%; width: 100%; -} \ No newline at end of file +} + diff --git a/static/js/interface.js b/static/js/interface.js new file mode 100644 index 0000000..a3ea68e --- /dev/null +++ b/static/js/interface.js @@ -0,0 +1,8 @@ +function convertTimeOffset(){ + selTime = new Date().getTime() + document.getElementById('time2').valueAsNumber + document.getElementById("time").value = selTime +} + +function updateHiddenForm(){ + document.getElementById("time").value = document.getElementById('time2').valueAsNumber +} \ No newline at end of file diff --git a/static/js/script.js b/static/js/script.js index 488d61a..088625a 100644 --- a/static/js/script.js +++ b/static/js/script.js @@ -1,32 +1,71 @@ var newDateObj = new Date(); newDateObj = new Date(newDateObj.getTime() + 1000*20) +function enterFullscreen(element) { + if(element.requestFullscreen) { + element.requestFullscreen(); + } else if(element.msRequestFullscreen) { // for IE11 (remove June 15, 2022) + element.msRequestFullscreen(); + } else if(element.webkitRequestFullscreen) { // iOS Safari + element.webkitRequestFullscreen(); + } +} + +function updateFullscreen(){ + if(JSON.parse(document.getElementById("incomeData").innerHTML).defaultFullScreen){ + enterFullscreen(document.documentElement) + } +} + +function msToTime(s, data) { + isSmallerThenZero = false + if(s < 0){ + isSmallerThenZero = true + } + + var ms = s % 1000; + s = (s - ms) / 1000; + var secs = s % 60; + s = (s - secs) / 60; + var mins = s % 60; + var hrs = (s - mins) / 60; + let out = "" + + if(!data.showMilliSeconds){ + out = ('00' + Math.abs(hrs)).slice(-2) + ':' + ('00'+Math.abs(mins)).slice(-2) + ':' + ('00'+Math.abs(secs)).slice(-2) + }else { + out = ('00' + Math.abs(hrs)).slice(-2) + ':' + ('00'+Math.abs(mins)).slice(-2) + ':' + ('00'+Math.abs(secs)).slice(-2) + '.' + ('000'+Math.abs(ms)).slice(-3) + } + + if(isSmallerThenZero){ + out = "-" + out + } + return out; +} + function handleUpdate() { resp = httpGet("/api/v1/data?markRead=mark"); var data = JSON.parse(resp); - if(data.changed){ - newDateObj = data.countdownGoal; + document.getElementById("incomeData").innerHTML = JSON.stringify(data) + + if(data.defaultFullScreen && document.getElementById("initalDate").innerHTML.includes("true")){ + enterFullscreen(document.documentElement); + document.getElementById("initalDate").innerHTML = "false" } + if (data.mode == "clock") { document.getElementById("timer").innerHTML = getTime(); document.getElementById("testImg").style.display = "none"; } else if (data.mode == "timer") { + const now = new Date() + const diff = data.countdownGoal - now.getTime() + + - 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("timer").innerHTML = msToTime(diff, data); document.getElementById("testImg").style.display = "none"; } else if (data.mode == "black") { @@ -60,4 +99,12 @@ function getTime() { return time; } -setInterval(handleUpdate, 50); +setInterval(handleUpdate, 200); + +let temp = new URLSearchParams(window.location.search).get("smaller"); + + +if (temp == "true") { + var cssURL = '/css/smallerTextMod.css'; + document.head.innerHTML +='' +} diff --git a/templates/adminPanel.html b/templates/adminPanel.html index 098f354..7606dea 100644 --- a/templates/adminPanel.html +++ b/templates/adminPanel.html @@ -1,10 +1,49 @@ -
\ No newline at end of file + +