-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
172 lines (143 loc) · 4.93 KB
/
Copy pathscript.js
File metadata and controls
172 lines (143 loc) · 4.93 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// realtime date and time function
function updateDateTime() {
const dateElement = document.querySelector("#dateTime .date");
const timeElement = document.querySelector("#dateTime .time");
const now = new Date();
const dateString = now.toLocaleDateString();
const timeString = now.toLocaleTimeString();
dateElement.innerText = dateString;
timeElement.innerText = timeString;
}
//loading screen animation
if (sessionStorage.getItem("loadingAnimationShown") !== "true") {
sessionStorage.setItem("loadingAnimationShown", "true");
window.addEventListener("load", () => {
const loadingWrapper = document.getElementById("loadingWrapper");
const loadingPercentage = document.getElementById("loadingPercentage");
const progressCircle = document.querySelector(".progress-ring__circle");
const radius = progressCircle.getAttribute("r");
const circumference = 2 * Math.PI * radius;
progressCircle.style.strokeDasharray = `${circumference} ${circumference}`;
progressCircle.style.strokeDashoffset = circumference;
let count = 0;
const loadingInterval = setInterval(() => {
count++;
loadingPercentage.innerText = `${count}%`;
const progress = (count / 100) * circumference;
progressCircle.style.strokeDashoffset = circumference - progress;
if (count === 100) {
clearInterval(loadingInterval);
loadingWrapper.style.transition = "opacity 1s";
loadingWrapper.style.opacity = "0";
setTimeout(() => {
loadingWrapper.style.display = "none";
}, 1000);
}
}, 20);
});
} else {
const loadingWrapper = document.getElementById("loadingWrapper");
loadingWrapper.style.display = "none";
}
function disablePageInteraction() {
const formElements = document.querySelectorAll("form input, form button");
for (const element of formElements) {
element.disabled = true;
}
}
function enablePageInteraction() {
const formElements = document.querySelectorAll("form input, form button");
for (const element of formElements) {
element.disabled = false;
}
}
function openCaptchaModal() {
const captchaModal = document.getElementById("captchaModal");
captchaModal.style.display = "block";
captchaModal.style.zIndex = 1001;
disablePageInteraction();
}
const operators = ["+", "-", "*"];
function generateCaptcha() {
const num1 = Math.floor(Math.random() * 10) + 1;
const num2 = Math.floor(Math.random() * 10) + 1;
const operator = operators[Math.floor(Math.random() * operators.length)];
const captchaDiv = document.getElementById("captcha");
captchaDiv.innerHTML = `${num1} ${operator} ${num2} = `;
captchaDiv.insertAdjacentHTML(
"beforeend",
'<input type="number" id="captchaAnswer" placeholder="Answer" required style="width: 150px; margin-left: 10px;" />'
);
let result;
switch (operator) {
case "+":
result = num1 + num2;
break;
case "-":
result = num1 - num2;
break;
case "*":
result = num1 * num2;
break;
}
captchaDiv.dataset.result = result;
}
if (sessionStorage.getItem("attempts") === null) {
sessionStorage.setItem("attempts", "0");
}
const loginForm = document.querySelector("#login-form");
let captchaRequired = false;
loginForm.addEventListener("submit", (event) => {
event.preventDefault();
let attempts = parseInt(sessionStorage.getItem("attempts"));
attempts++;
if (attempts > 3 && !captchaRequired) {
captchaRequired = true;
openCaptchaModal();
generateCaptcha();
} else if (captchaRequired) {
checkCaptcha();
} else {
loginForm.submit();
}
sessionStorage.setItem("attempts", attempts);
});
document.getElementById("captchaSubmit").addEventListener("click", () => {
let validCaptcha = checkCaptcha();
if (validCaptcha) {
sessionStorage.setItem("attempts", "0");
loginForm.submit();
}
});
function checkCaptcha() {
const captchaDiv = document.getElementById("captcha");
const result = parseInt(captchaDiv.dataset.result);
const userInput = parseInt(document.getElementById("captchaAnswer").value);
if (userInput === result) {
const captchaModal = document.getElementById("captchaModal");
captchaModal.style.display = "none";
enablePageInteraction();
captchaRequired = false;
return true;
} else {
alert("Incorrect captcha. Please try again.");
generateCaptcha();
return false;
}
}
const showHideIcon = document.querySelector(".show-hide-icon");
const passwordInput = document.querySelector('input[type="password"]');
function togglePasswordVisibility() {
if (passwordInput.type === "password") {
passwordInput.type = "text";
showHideIcon.classList.remove("fa-eye");
showHideIcon.classList.add("fa-eye-slash");
} else {
passwordInput.type = "password";
showHideIcon.classList.remove("fa-eye-slash");
showHideIcon.classList.add("fa-eye");
}
}
showHideIcon.addEventListener("click", togglePasswordVisibility);
updateDateTime();
setInterval(updateDateTime, 1000);