-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
186 lines (164 loc) · 5.04 KB
/
Program.cs
File metadata and controls
186 lines (164 loc) · 5.04 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Typing Speed Test</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 50px auto;
max-width: 900px;
padding: 40px;
background: linear-gradient(to right, #141e30, #243b55);
color: #ffffff;
font-size: 22px;
box-shadow: 0 0 30px rgba(0,0,0,0.3);
border-radius: 16px;
}
h1 {
text-align: center;
font-size: 42px;
color: #00e5ff;
text-shadow: 2px 2px #000;
}
#quote {
margin-bottom: 30px;
font-size: 28px;
font-weight: bold;
line-height: 1.8;
user-select: none;
-webkit-user-select: none;
-moz-user-select: none;
background: rgba(255, 255, 255, 0.1);
padding: 20px;
border-radius: 12px;
white-space: pre-wrap;
}
#quote span.correct {
color: #76ff03;
}
#quote span.incorrect {
color: #ff5252;
}
textarea {
width: 100%;
height: 150px;
font-size: 22px;
padding: 20px;
background: #1a1a1a;
color: #ffffff;
border: 2px solid #00e5ff;
border-radius: 12px;
box-shadow: 0 0 10px #00e5ff;
}
button, select, label {
padding: 16px 28px;
font-size: 20px;
margin-top: 20px;
cursor: pointer;
background-color: #00e5ff;
color: #000;
border: none;
border-radius: 10px;
margin-right: 15px;
transition: all 0.3s ease;
}
button:hover, select:hover {
background-color: #00bcd4;
transform: scale(1.05);
box-shadow: 0 0 10px #00e5ff;
}
#result {
margin-top: 30px;
font-size: 26px;
color: #76ff03;
font-weight: bold;
text-shadow: 1px 1px #000;
}
</style>
</head>
<body>
<h1>🚀 Typing Speed Test</h1>
<label for="wordCount">Choose word count:</label>
<select id="wordCount">
<option value="25">25 words</option>
<option value="50">50 words</option>
<option value="100">100 words</option>
</select>
<div id="quote">Loading sentence...</div>
<textarea id="typed" placeholder="Start typing here..." disabled></textarea><br />
<button onclick="startTest()">Start New Test</button>
<button onclick="submitTest()">Submit</button>
<div id="result"></div>
<script>
let startTime, sentence = "";
async function startTest() {
const wordCount = document.getElementById("wordCount").value;
const res = await fetch(`http://localhost:5041/TypingTest/quote?words=${wordCount}`);
const data = await res.json();
sentence = data.sentence;
document.getElementById("typed").value = "";
document.getElementById("typed").disabled = false;
document.getElementById("typed").focus();
document.getElementById("result").innerText = "";
startTime = new Date().getTime();
renderSentence();
}
function renderSentence() {
const quoteEl = document.getElementById("quote");
quoteEl.innerHTML = "";
for (let i = 0; i < sentence.length; i++) {
const span = document.createElement("span");
span.innerText = sentence[i];
quoteEl.appendChild(span);
}
}
function updateLiveFeedback() {
const typed = document.getElementById("typed").value;
const quoteSpans = document.getElementById("quote").querySelectorAll("span");
for (let i = 0; i < quoteSpans.length; i++) {
const char = typed[i];
if (char == null) {
quoteSpans[i].className = "";
} else if (char === sentence[i]) {
quoteSpans[i].className = "correct";
} else {
quoteSpans[i].className = "incorrect";
}
}
}
async function submitTest() {
const typed = document.getElementById("typed").value;
const endTime = new Date().getTime();
const seconds = (endTime - startTime) / 1000;
const res = await fetch("http://localhost:5041/TypingTest/result", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
sentence: sentence,
typed: typed,
timeInSeconds: seconds
})
});
const result = await res.json();
document.getElementById("result").innerText =
`🧠 WPM: ${result.wpm.toFixed(2)}\n🎯 Accuracy: ${result.accuracy.toFixed(2)}%`;
}
document.addEventListener('DOMContentLoaded', () => {
const typedEl = document.getElementById('typed');
// Disable copy-paste & right click
document.getElementById('quote').addEventListener('contextmenu', e => e.preventDefault());
document.addEventListener('copy', e => e.preventDefault());
typedEl.addEventListener('paste', e => e.preventDefault());
// Ctrl + Enter to submit
typedEl.addEventListener("keydown", function(e) {
if (e.ctrlKey && e.key === "Enter") {
submitTest();
}
});
// Real-time character feedback
typedEl.addEventListener("input", updateLiveFeedback);
});
</script>
</body>
</html>