-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
79 lines (71 loc) · 2.9 KB
/
index.php
File metadata and controls
79 lines (71 loc) · 2.9 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
<html>
<head>
<title>Typing Test</title>
<link rel="stylesheet" href="style.css">
<script src="jquery-3.1.1.min.js"></script>
</head>
<body>
<?php
$text = file_get_contents('scripts/text_file.txt');
$new_txt = '';
$length = strlen($text);
for($i=0;$i<$length;$i++){
if(!isset($text[$i])) {
break;
}
if($i==0) {
$new_txt .= '<span class="letter active">'.$text[$i].'</span>';
} else {
$new_txt .= '<span class="letter">'.$text[$i].'</span>';
}
}
?>
<div class="container">
<form action="upload.php" method="post" enctype="multipart/form-data">
<b>Change Text File</b>
<br />
<input type="file" name="file">
<br />
<input type="submit" name="submit">
</form>
<div class="cont1" id="text_container">
<input type="hidden" name="lengthOfChars" class="lengthOfChars" value="<?=$length?>">
<?php
echo $new_txt;
?>
</div>
</div>
<script>
$('document').ready(function(){
length = $('.lengthOfChars').val();
count = 0;
window.addEventListener("keydown", checkKeyPressed, false);
function checkKeyPressed(e) {
if(count == length-1) {
alert('You are done!');
document.reload();
}
var char = $('.active');
var charVal = $('.active').html();
if(e.key != undefined) {
if (e.key.charCodeAt() == charVal.charCodeAt()) {
// pressed right button
// remove active from current
char.removeClass('active');
// and set active class to it's next
char.next().attr('class',' active');
// also remove wrong class if exists
char.removeClass('wrong');
// set recent class (typed character)
char.addClass('recent');
// update counter
count = count + 1;
} else {
char.addClass('wrong');
}
}
}
});
</script>
</body>
</html>