-
Notifications
You must be signed in to change notification settings - Fork 0
/
exerese.html
337 lines (292 loc) · 14.6 KB
/
exerese.html
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<!DOCTYPE html>
<!-- saved from url=(0029)http://101.96.128.94:9999/dz/ -->
<html lang="zh-cn"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>键速测试</title>
<script>
var arrayHTML = ["big", "blockquote", "body", "br", "button", "canvas", "caption", "center", "cite", "code", "col", "colgroup", "command", "datalist", "dd", "del", "details", "dir", "div", "dfn", "dialog", "dl", "dt", "em", "embed", "fieldset", "figcaption", "figure", "font", "footer", "form", "frame", "frameset", "h1 to h6", "head", "header", "hr", "html", "i", "iframe", "img", "input", "keygen", "label", "legend", "li", "link", "map", "mark", "menu", "menuitem", "meta", "meter", "nav", "noframes", "noscript", "object", "ol", "optgroup", "option", "output", "p", "param", "pre", "progress", "s", "samp", "script", "section", "select", "small", "source", "span", "strike", "strong", "style", "sub", "summary", "sup", "table", "tbody", "td", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "track", "tt", "u", "ul", "var", "video"];
var arrayCSS = ["background", "background-attachment", "background-color", "background-image", "background-position", "background-repeat", "border", "border-bottom", "border-bottom-color", "border-bottom-style", "border-bottom-width", "border-color", "border-left", "border-left-color", "border-left-style", "border-left-width", "border-right", "border-right-color", "border-right-style", "border-right-width", "border-style", "border-top", "border-top-color", "border-top-style", "border-top-width", "border-width", "outline", "outline-color", "outline-style", "outline-width", "color", "direction", "letter-spacing", "line-height", "text-align", "text-decoration", "text-indent", "text-shadow", "text-transform", "unicode-bidi", "white-space", "word-spacing", "font", "font-family", "font-size", "font-size-adjust", "font-stretch", "font-style", "font-variant", "font-weight", "margin", "margin-bottom", "margin-left", "margin-right", "margin-top", "padding", "padding-bottom", "padding-left", "padding-right", "padding-top", "list-style", "list-style-image", "list-style-position", "list-style-type", "marker-offset", "content", "counter-increment", "counter-reset", "quotes", "height", "max-height", "max-width", "min-height", "min-width", "width", "bottom", "clear", "clip", "cursor", "display", "float", "left", "overflow", "position", "right", "top", "vertical-align", "visibility", "z-index", "border-collapse", "border-spacing", "caption-side", "empty-cells", "table-layout", ":active", ":hover", ":link", ":visited"];
var arraySQL = ["action","add","all","alter","analyze","and","as","asc","asensitive","before","between","bigint","binary","bit","blob","both","by","call","cascade","case","change","char","character","check","collate","column","condition","connection","constraint","continue","convert","create","cross","current_date","current_time","current_timestamp","current_user","cursor","database","databases","date","day_hour","day_microsecond","day_minute","day_second","dec","decimal","declare","default","delayed","delete","desc","describe","deterministic","distinct","distinctrow","div","double","drop","dual","each","else","elseif","enclosed","enum","escaped","exists","exit","explain","false","fetch","float","float4","float8","for","force","foreign","from","fulltext","goto","grant","group","having","high_priority","hour_microsecond","hour_minute","hour_second","if","ignore","in","index","infile","inner","inout","insensitive","insert","int","int1","int2","int3","int4","int8","integer","interval","into","is","iterate","join","key","keys","kill","label","leading","leave","left","like","limit","linear","lines","load","localtime","localtimestamp","lock","long","longblob","longtext","loop","low_priority","match","mediumblob","mediumint","mediumtext","middleint","minute_microsecond","minute_second","mod","modifies","natural not","no","no_write_to_binlog","null","numeric","on","optimize","option","optionally","or","order","out","outer","outfile","precision","primary","procedure","purge","raid0","range","read","reads","real","references","regexp","release","rename","repeat","replace","require","restrict","return","revoke","right","rlike","schema","schemas","second_microsecond","select","sensitive","separator","set","show","smallint","spatial","specific","sql","sqlexception","sqlstate","sqlwarning","sql_big_result","sql_calc_found_rows","sql_small_result","ssl","starting","straight_join","table","terminated","text","then","time","timestamp","tinyblob","tinyint","tinytext","to","trailing","trigger","true","undo","union","unique","unlock","unsigned","update","usage","use","using","utc_date","utc_time","utc_timestamp","values","varbinary","varchar","varcharacter","varying","when","where","while","with","write","x509","xor","year_month","zerofill","action","add","all","alter","analyze","and","as","asc","asensitive","before","between","bigint","binary","bit","blob","both","by","call","cascade","case","change","char","character","check","collate","column","condition","connection","constraint","continue","convert","create","cross","current_date","current_time","current_timestamp","current_user","cursor","database","databases","date","day_hour","day_microsecond","day_minute","day_second","dec","decimal","declare","default","delayed","delete","desc","describe","deterministic","distinct","distinctrow","div","double","drop","dual","each","else","elseif","enclosed","enum","escaped","exists","exit","explain","false","fetch","float","float4","float8","for","force","foreign","from","fulltext","goto","grant","group","having","high_priority","hour_microsecond","hour_minute","hour_second","if","ignore","in","index","infile","inner","inout","insensitive","insert","int","int1","int2","int3","int4","int8","integer","interval","into","is","iterate","join","key","keys","kill","label","leading","leave","left","like","limit","linear","lines","load","localtime","localtimestamp","lock","long","longblob","longtext","loop","low_priority","match","mediumblob","mediumint","mediumtext","middleint","minute_microsecond","minute_second","mod","modifies","natural not","no","no_write_to_binlog","null","numeric","on","optimize","option","optionally","or","order","out","outer","outfile","precision","primary","procedure","purge","raid0","range","read","reads","real","references","regexp","release","rename","repeat","replace","require","restrict","return","revoke","right","rlike","schema","schemas","second_microsecond","select","sensitive","separator","set","show","smallint","spatial","specific","sql","sqlexception","sqlstate","sqlwarning","sql_big_result","sql_calc_found_rows","sql_small_result","ssl","starting","straight_join","table","terminated","text","then","time","timestamp","tinyblob","tinyint","tinytext","to","trailing","trigger","true","undo","union","unique","unlock","unsigned","update","usage","use","using","utc_date","utc_time","utc_timestamp","values","varbinary","varchar","varcharacter","varying","when","where","while","with","write","x509","xor","year_month","zerofill"];
var resultArray = arrayHTML; //最终保存数据的数组
var startTime = 0, stopTime = 0;
var status = "STOP";
var userTotal = 0;
function $(selector) {
return document.getElementById(selector);
}
/**
* 生成一个随机数组
* */
function getRandom(total) {
var wordsArray = [];
for (var i = 0; i < total; i++) {
wordsArray.push(resultArray[Math.floor(Math.random() * resultArray.length)]);
}
return wordsArray;
}
/**
* 创建结束按钮函数
* */
function createBtnStop() {
var btnStop = document.createElement("button");
btnStop.setAttribute("id", "btnStop");
btnStop.className = "btnStop";
btnStop.innerHTML = "结束测试";
btnStop.onclick = stopFunction;
$("content").appendChild(btnStop);
}
function initial() {
if (status == "START") {
alert("测试已经开始了...");
return;
}
var sum = 0;
var num = $("txtNum").value;
var line = $("txtLine").value;
var total = num * line;
var wordsArray = getRandom(total);
$("content").innerHTML = "";
for (var i = 1; i <= line; i++) {
if (sum >= wordsArray.length) {
break;
}
var start = (i - 1) * num;
var p = document.createElement("p");
var str = "";
for (var j = start; j < num * i; j++) {
sum += 1;
if (sum > wordsArray.length) {
break;
}
str += wordsArray[j];
if (j < num * i - 1) {
str += " ";
}
}
p.innerHTML = str;
$("content").appendChild(p);
var input = document.createElement("input");
$("content").appendChild(input);
}
//记录开始时间
status = "START";
startTime = getTimeNow();
//创建结束按钮并添加到打字区域最后
createBtnStop();
$("time").innerHTML = "测速中...";
$("avgSpeed").innerHTML = "测速中...";
$("correct").innerHTML = "测速中...";
$("content").firstElementChild.nextSibling.focus();
}
/*结束打字*/
function stopFunction() {
if (status == "STOP") {
alert("尚未开始!无法结束!");
return;
} else {
stopTime = getTimeNow();
var duration = stopTime - startTime;
var minute = parseInt(duration / 1000 / 60);
var second = parseInt(duration / 1000 % 60);
status = "STOP";
//计算正确率
var rate = calCorrect();
var speed = calSpeed(duration);
var info = "共耗时:" + minute + "分" + second + "秒\n正确率为:" + rate + "%\n击键速度:" + speed + "次/分钟";
$("time").innerHTML = minute + "分" + second + "秒";
$("correct").innerHTML = rate + "%";
$("avgSpeed").innerHTML = speed + "次/分钟";
// alert(info);
}
}
/**
* 计算速度
* */
function calSpeed(duration) {
//获取用户输入的总字符数
var inputs = $("content").getElementsByTagName("input");
var userTotals = 0;
for (var i = 0; i < inputs.length; i++) {
var input = inputs[i];
if (input.value != "") {
userTotals += input.value.length;
}
}
var speed = userTotals / (duration / 1000 / 60);
return parseInt(speed);
}
function bindEnter() {
// var inputs = $("content").getElementsByTagName("input");
// for(var i in inputs){
// var input = inputs[i];
// input.onkeypress = function(e){
// if(e.keyCode == 13){
//
// }
// }
// }
document.body.onkeydown = function (e) {
if (e.keyCode == 13) {
e.keyCode = 9;
}
}
}
/**
* 获取当前时间
* */
function getTimeNow() {
var date = new Date();
var time = date.getTime();
return time;
}
/**
* 计算正确率
* */
function calCorrect() {
var total = 0;
var correct = 0;
var pArray = $("content").getElementsByTagName("p");
var inputArray = $("content").getElementsByTagName("input");
for (var i = 0; i < pArray.length; i++) {
var p = pArray[i];
var input = inputArray[i];
var pText = p.innerHTML;
var inputText = input.value;
for (var j = 0; j < pText.length; j++) {
total++;
if (pText[j] == inputText[j]) {
correct++;
}
}
}
var rate = ((correct / total) * 100).toFixed(2);
return rate;
}
function setFocus() {
$("btnStart").focus();
}
/**
*
* */
function changeSelect() {
var val = $("selCourse").value;
switch (val) {
case "0":
resultArray = arrayHTML;
break;
case "1":
resultArray = arrayCSS;
break;
case "2":
resultArray = arraySQL;
break;
}
}
window.onload = function () {
$("btnStart").onclick = initial;
//$("btnStop").onclick = stopFunction;
setFocus();
$("selCourse").onchange = changeSelect;
}
</script>
<style>
#container {
width: 95%;
min-height: 50px;
margin: 20px auto;
border: 1px solid #333;
padding: 0 15px;
}
#container p.setting label {
display: inline-block;
width: 180px;
text-align: right;
}
#container p.setting button {
margin-left: 50px;
}
#content {
border-top: 2px solid #e4393c;
margin-top: 15px;
padding: 15px 0;
}
#content p, #content input {
font-size: 20px;
font-family: "Arial";
box-sizing: border-box;
padding: 2px;
width: 100%;
}
#content p {
border: 1px solid transparent;
}
#container .left-side p, #container .left-side input, #container .left-side button, #container select {
font-size: 20px;
}
#container div.left-side {
float: left;
}
.btnStop {
font-size: 20px;
margin-top: 20px;
}
#container div.right-side {
float: left;
margin-left: 35px;
}
#container div.right-side span {
display: inline-block;
width: 100px;
text-align: right;
}
#container div.right-side b {
color: #ff0000;
}
</style>
</head>
<body>
<div id="container">
<div class="left-side">
<p class="setting">
<label for="">请选择打字内容:</label>
<select id="selCourse">
<option value="0">HTML</option>
<option value="1">CSS</option>
<option value="2">MYSQL</option>
</select>
</p>
<p class="setting">
<label for="">每行显示几个单词:</label>
<input type="number" id="txtNum" value="5">
</p>
<p class="setting">
<label for="">共测试几行:</label>
<input type="number" id="txtLine" value="5">
</p>
<p class="setting">
<button type="button" id="btnStart">开始测试</button>
<!--<button type="button" id="btnStop">结束测试</button>-->
</p><pre> 用TAB键切换到下一行的输入框和“结束按钮”,
用空格键点击“结束按钮”——测试全程不要用动鼠标——否则会影响自己的键速
</pre>
<p></p>
<!-- <p>
</p> -->
</div>
<div class="right-side">
<p>
<span>耗时:</span>
<b id="time"></b>
</p>
<p>
<span>正确率:</span>
<b id="correct"></b>
</p>
<p>
<span>击键速度:</span>
<b id="avgSpeed"></b>
</p>
</div>
<div id="content" style="clear:both;">
</div>
</div>
</body></html>