This commit is contained in:
Sören Oesterwind 2022-02-23 22:17:12 +01:00
parent 52347d357d
commit a37d2dd58a
4 changed files with 34 additions and 9 deletions

View File

@ -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);

1
static/js/countdown.js Symbolic link
View File

@ -0,0 +1 @@
../../node_modules/countdown/countdown.js

View File

@ -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") {

View File

@ -11,7 +11,6 @@
<meta name="author" content="TheGreydiamond">
<link rel="stylesheet" href="css/styles.css?v=1.1">
</head>
<body>
@ -22,6 +21,7 @@
00:00:00
</div>
</div>
<script src="js/countdown.js"></script>
<script src="js/script.js"></script>
</body>