-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtyping.html
More file actions
154 lines (130 loc) · 3.39 KB
/
typing.html
File metadata and controls
154 lines (130 loc) · 3.39 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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script>
var questtext =
'A pangram is a sentence using every letter of the alphabet at least once.\n\
"The quick brown fox jumps over the lazy dog." is the most famous English pangram.';
</script>
<style>
body {
font-size: 200%;
}
.unpressed {
color: #CCCCCC;
}
.hit {
color: black;
}
.miss {
color: red;
background-color: #CCCCCC;
}
.current {
color: green;
text-decoration: underline;
font-weight: bold;
}
.current_alter {
color: green;
font-weight: bold;
}
.misscurrent {
color: red;
background-color: #CCCCCC;
font-weight: bold;
}
.misscurrent_alter {
color: red;
background-color: #CCCCCC;
text-decoration: underline;
font-weight: bold;
}
</style>
<script>
function getCharElem(column, row) {
return document.getElementById("char_"+row+"_"+column);
}
function keydown() {
var c = event.which || event.keyCode;
// backspace
if (c == 8) {
getCharElem(x, y).className="unpressed";
x = (x>0)?x-1:0;
if (missmode
&& ((x == 0) || getCharElem(x - 1, y).className == "hit"))
missmode = false;
updateCursor();
return false;
}
}
function keypress() {
if (start == 0) start = new Date().getTime();
var c = event.which || event.keyCode;
if (c == 13 && !missmode && x == quest[y].length) {
document.getElementById("char_"+y+"_"+x).className="hit";
x = 0;
y++;
updateCursor();
if (y == quest.length) result();
return;
}
if (!missmode && c != quest[y].charCodeAt(x)) missmode = true;
document.getElementById("char_"+y+"_"+x).className= missmode? "miss":"hit";
x++;
if (x > quest[y].length) x = quest[y].length + 1;
updateCursor();
}
function updateCursor() {
var curr = getCharElem(x, y);
if (curr)
curr.className = missmode?"misscurrent": "current";
}
function result() {
var elapsed = (new Date().getTime() - start)/1000/60;
var speed = Math.round(total/elapsed);
var area = document.getElementById("area");
area.innerHTML =
"<a onclick='location.reload()'>수고하셨습니다. "
+ speed + "타입니다. 여기를 눌러 다시 한번 시도해 보세요.</a>";
}
</script>
</head>
<body onkeydown="return keydown()" onkeypress="keypress()">
<br />
<div id="area"></div>
<script>
var quest = questtext.split("\n");
var start = 0;
var missmode = false;
var total = 0;
var area = document.getElementById("area");
for (var i = 0; i < quest.length; ++i) {
var l = document.createElement("P");
var lt = quest[i] + "⏎ ";
for (var j = 0; j < lt.length; ++j) {
var c = document.createElement("SPAN");
c.id = "char_"+i+"_"+j;
c.className = "unpressed";
c.innerText = lt.charAt(j);
l.appendChild(c);
total++;
}
area.appendChild(l);
}
// cursor
var x = 0;
var y = 0;
updateCursor();
// blinking
setInterval(function () {
var curr = getCharElem(x, y);
if (curr) {
curr.className = (curr.className.endsWith("_alter"))?curr.className.split("_")[0]: curr.className + "_alter";
}
}, 500);
;
</script>
</body>
</html>