This repository was archived by the owner on Jul 8, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
84 lines (73 loc) · 2.01 KB
/
Copy pathscript.js
File metadata and controls
84 lines (73 loc) · 2.01 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
var isButtonClicked = false;
var isDarkMode = false;
$(document).ready(function () {
$("#submit").click(function (e) {
e.preventDefault();
var input = $("#dob-input").val();
if (!input) return; // Prevent empty submit
var dob = new Date(input);
save(dob);
isButtonClicked = true;
window.location.href = "timer.html";
});
$("#dob-input").keyup(function (e) {
if (e.keyCode === 13 && !isButtonClicked) {
e.preventDefault();
var input = $("#dob-input").val();
if (!input) return;
var dob = new Date(input);
save(dob);
window.location.href = "timer.html";
}
});
function toggleTheme() {
const icon = $("#toggleTheme i");
if (isDarkMode) {
document.body.classList.remove("dark-mode");
document.body.classList.add("light-mode");
icon.removeClass("fa-sun").addClass("fa-moon");
} else {
document.body.classList.remove("light-mode");
document.body.classList.add("dark-mode");
icon.removeClass("fa-moon").addClass("fa-sun");
}
isDarkMode = !isDarkMode;
localStorage.setItem("theme", isDarkMode ? "dark" : "light");
}
$("#toggleTheme").click(function () {
toggleTheme();
});
function save(dob) {
localStorage.dob = dob.getTime();
}
function load() {
var dob;
if ((dob = localStorage.getItem("dob"))) {
return new Date(parseInt(dob));
}
return -1;
}
function renderChoose() {
$("#choose").css("display", "flex");
}
function main() {
// Theme initialization
var theme = localStorage.getItem("theme");
isDarkMode = theme === "dark";
const icon = $("#toggleTheme i");
if (isDarkMode) {
$("body").addClass("dark-mode");
icon.removeClass("fa-moon").addClass("fa-sun");
} else {
$("body").removeClass("dark-mode");
icon.removeClass("fa-sun").addClass("fa-moon");
}
// Redirection check
if (load() !== -1) {
window.location.href = "timer.html";
} else {
renderChoose();
}
}
main();
});