EoD
This commit is contained in:
parent
52347d357d
commit
a37d2dd58a
17
index.js
17
index.js
@ -18,8 +18,8 @@ app.use(
|
|||||||
|
|
||||||
currentState = {
|
currentState = {
|
||||||
mode: "clock",
|
mode: "clock",
|
||||||
timeLeft: "00:00:00",
|
countdownGoal: new Date(),
|
||||||
timerInternal: 0,
|
changed: true
|
||||||
};
|
};
|
||||||
|
|
||||||
app.get("/", function (req, res) {
|
app.get("/", function (req, res) {
|
||||||
@ -30,7 +30,7 @@ app.get("/", function (req, res) {
|
|||||||
app.post("/", function (req, res) {
|
app.post("/", function (req, res) {
|
||||||
console.log(req.body);
|
console.log(req.body);
|
||||||
currentState.mode = req.body.mode;
|
currentState.mode = req.body.mode;
|
||||||
currentState.timeLeft = req.body.timeLeft;
|
currentState.countdownGoal = req.body.countdownGoal;
|
||||||
res.send("OK");
|
res.send("OK");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -40,7 +40,11 @@ app.get("/timer", function (req, res) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.get("/api/v1/data", function (req, res) {
|
app.get("/api/v1/data", function (req, res) {
|
||||||
|
|
||||||
res.json(currentState);
|
res.json(currentState);
|
||||||
|
if(req.query.markRead == "mark"){
|
||||||
|
currentState.changed = false
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/api/v1/set/mode", function (req, res) {
|
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" });
|
res.json({ status: "ok" });
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/api/v1/set/timeLeft", function (req, res) {
|
app.get("/api/v1/set/timerGoal", function (req, res) {
|
||||||
currentState.timerInternal = req.query.time;
|
currentState.countdownGoal = req.query.time;
|
||||||
|
currentState.changed = true
|
||||||
res.json({ status: "ok" });
|
res.json({ status: "ok" });
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(countdown( new Date(2022, 1, 24) ).toString())
|
console.log(countdown( new Date(2022, 1, 24) ).toString())
|
||||||
|
|
||||||
app.listen(3000);
|
app.listen(3005);
|
||||||
|
1
static/js/countdown.js
Symbolic link
1
static/js/countdown.js
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../node_modules/countdown/countdown.js
|
@ -1,13 +1,32 @@
|
|||||||
|
var newDateObj = new Date();
|
||||||
|
newDateObj = new Date(newDateObj.getTime() + 1000*20)
|
||||||
|
|
||||||
function handleUpdate() {
|
function handleUpdate() {
|
||||||
resp = httpGet("/api/v1/data");
|
resp = httpGet("/api/v1/data?markRead=mark");
|
||||||
|
|
||||||
var data = JSON.parse(resp);
|
var data = JSON.parse(resp);
|
||||||
|
if(data.changed){
|
||||||
|
newDateObj = data.countdownGoal;
|
||||||
|
}
|
||||||
|
|
||||||
if (data.mode == "clock") {
|
if (data.mode == "clock") {
|
||||||
document.getElementById("timer").innerHTML = getTime();
|
document.getElementById("timer").innerHTML = getTime();
|
||||||
document.getElementById("testImg").style.display = "none";
|
document.getElementById("testImg").style.display = "none";
|
||||||
|
|
||||||
} else if (data.mode == "timer") {
|
} 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";
|
document.getElementById("testImg").style.display = "none";
|
||||||
|
|
||||||
} else if (data.mode == "black") {
|
} else if (data.mode == "black") {
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
<meta name="author" content="TheGreydiamond">
|
<meta name="author" content="TheGreydiamond">
|
||||||
|
|
||||||
<link rel="stylesheet" href="css/styles.css?v=1.1">
|
<link rel="stylesheet" href="css/styles.css?v=1.1">
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
@ -22,6 +21,7 @@
|
|||||||
00:00:00
|
00:00:00
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<script src="js/countdown.js"></script>
|
||||||
<script src="js/script.js"></script>
|
<script src="js/script.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user