Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 5, 2019. It is now read-only.

Commit 0dc9acc

Browse files
timer half done.
1 parent 6eeb0f0 commit 0dc9acc

File tree

6 files changed

+167
-2
lines changed

6 files changed

+167
-2
lines changed

‎app.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const cookieParser = require('cookie-parser');
66
const logger = require('morgan');
77

88
const indexRouter = require('./routes/index');
9+
const timerRouter = require("./routes/timer");
910

1011
require('dotenv').config();
1112

@@ -25,6 +26,7 @@ app.use(cookieParser());
2526
app.use(express.static(path.join(__dirname, 'public')));
2627

2728
app.use('/', indexRouter);
29+
app.use("/timer", timerRouter);
2830

2931
// catch 404 and forward to error handler
3032
app.use(function (req, res, next) {

‎public/stylesheets/timer.css‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
body {
2+
background-color: #ffffff;
3+
}
4+
5+
button:hover {
6+
background-color: #7e3a9d;
7+
}
8+
9+
button {
10+
position: absolute;
11+
left: 50%;
12+
top: 75%;
13+
transform: translateX(-50%) translateY(-50%);
14+
width: auto;
15+
height: auto;
16+
font-size: 40px;
17+
background-color: #883eaa;
18+
cursor: pointer;
19+
border: none;
20+
color: white;
21+
padding: 30px 52px;
22+
text-align: center;
23+
text-decoration: none;
24+
display: inline-block;
25+
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
26+
}
27+
28+
.img {
29+
position: absolute;
30+
top: 15%;
31+
left: 50%;
32+
transform: translateX(-50%) translateY(-10%);
33+
max-width: 100%;
34+
height: auto;
35+
}
36+
37+
p {
38+
text-align: center;
39+
height: auto;
40+
width: auto;
41+
font-size: 200px;
42+
}

‎routes/timer.js‎

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,41 @@
11
const express = require('express');
22
const router = express.Router();
3+
const timer = require("./../services/timer");
34

4-
router.get('/', function(req, res,next) {
5-
res.render('index', {title: 'Express'});
5+
router.get('/', (req, res)=> {
6+
res.render('timer', {title: 'Express'});
67
});
8+
9+
router.get("/start/check", async (req, res) => {
10+
const response = {};
11+
try {
12+
let ans = await timer.checkStart();
13+
if (ans === false) {
14+
response["started"] = true;
15+
response["startTime"] = ans;
16+
}
17+
} catch (e) {
18+
response["started"] = false;
19+
}
20+
res.json(response);
21+
});
22+
23+
router.get("/start", async (req, res) => {
24+
25+
try {
26+
await timer.start(req.body.time);
27+
} catch (e) {
28+
29+
}
30+
31+
});
32+
33+
router.get("/get", (req, res) => {
34+
try {
35+
36+
} catch (e) {
37+
38+
}
39+
});
40+
41+
module.exports = router;

‎services/timer/index.js‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const fs = require("fs");
2+
const jsonFile = require("jsonfile");
3+
4+
const dataFile = __dirname + "./../../data.json";
5+
6+
const startKey = "started";
7+
const timeKey = "startTime";
8+
9+
const timer = {
10+
11+
get: () => {
12+
13+
},
14+
15+
start: async (timeInSeconds) => {
16+
let json;
17+
try {
18+
fs.accessSync(dataFile, fs.constants.F_OK);
19+
json = jsonFile.readFileSync(dataFile);
20+
} catch (e) {
21+
json = {};
22+
}
23+
json[timeKey] = timeInSeconds;
24+
json[startKey] = true;
25+
await jsonFile.writeFileSync(dataFile, json);
26+
},
27+
28+
checkStart: async () => {
29+
try {
30+
fs.accessSync(dataFile, fs.constants.F_OK);
31+
let json = jsonFile.readFileSync(dataFile);
32+
let started = json[startKey];
33+
if (started === true) {
34+
return json[timeKey];
35+
}
36+
return false;
37+
} catch (e) {
38+
let obj = {};
39+
obj[startKey] = false;
40+
await jsonFile.writeFileSync(dataFile, obj);
41+
return false;
42+
}
43+
}
44+
45+
};
46+
47+
module.exports = timer;

‎views/layout.hbs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
</head>
77
<body>
88
{{{body}}}
9+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
910
</body>
1011
</html>

‎views/timer.hbs‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<p id="countdown"></p>
2+
<button id="startBtn" onclick="startCountDown()">Start</button>
3+
<script>
4+
//let timeInSec;
5+
const secondsToTime = (seconds) => {
6+
const arr = new Date(seconds * 1000).toISOString().substr(11, 8).split(':');
7+
const days = Math.floor(seconds / 86400);
8+
arr[0] = parseInt(arr[0], 10) + days * 24;
9+
return arr.join(':');
10+
};
11+
12+
$(document).ready(() => {
13+
14+
});
15+
16+
const timeInSec = 30 * 60 * 60;
17+
const startCountDown = () => {
18+
startTimer(timeInSec)
19+
};
20+
21+
const startTimer = (timeToCount) => {
22+
document.getElementById('startBtn').style.display = "none";
23+
document.getElementById('imgOnLoad').style.display = "none";
24+
25+
let x = setInterval(() => {
26+
let timeInWords = secondsToTime(timeToCount);
27+
console.log(timeInWords);
28+
document.getElementById('countdown').innerHTML = timeInWords;
29+
if (timeToCount < 0) {
30+
clearInterval(x);
31+
document.getElementById("countdown").innerHTML = "Hacking Ends";
32+
}
33+
timeToCount--;
34+
}, 1000);
35+
};
36+
37+
38+
</script>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /