Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
56 lines (52 loc) · 1.69 KB
/
Copy pathindex.js
File metadata and controls
56 lines (52 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const toast = document.getElementById("toast");
const body = document.querySelector("body");
let toastTimeout;
function showToast(message) {
clearTimeout(toastTimeout)
toast.textContent = message;
toast.classList.add("show");
toastTimeout = setTimeout(() => {
toast.classList.remove("show");
}, 3000);
}
const username = document.getElementById("name");
const initimer = document.getElementById("initimer");
const submitBtn = document.getElementById("submit")
let name;
let timer = [];
submitBtn.addEventListener("click", () => {
if ((username.value.trim() === "") || (initimer.value.trim() === "")) {
showToast("Kindly fill the details properly!");
}
else {
name = username.value;
const timerobj = {
id: Date.now(),
seconds: initimer.value
}
timer[0] = timerobj;
localStorage.setItem("name", name);
localStorage.setItem("timer", JSON.stringify(timer));
showToast("Successfully Submitted!");
username.value = "";
initimer.value = "";
showToast("Loading,Please wait!")
setTimeout(() => {
window.location.href = "dashboard.html";
}, 3000);
}
})
body.addEventListener("keyup", (event) => {
if (event.key === "Enter") {
submitBtn.click();
}
})
const getname = localStorage.getItem("name");
const gettimer = localStorage.getItem("timer");
const path = window.location.pathname;
if (getname &&gettimer &&(path === "/" || path.endsWith("index.html"))){
showToast("Redirecting to Dashboard");
setTimeout(() => {
window.location.href = "dashboard.html";
}, 2000);
}