-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
110 lines (100 loc) · 2.68 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>freeclack</title>
<style>
body {
font-family: 'Roboto Slab', serif;
background-color:#2d2d2d;
color: #d3d0c8;
margin: 1em;
}
.current {
background:#515151;
}
.test {
background-color:#2d2d2d;
color: #d3d0c8;
display: block;
width: 100%;
height: 69vh;
border: 0;
font-family: inherit;
font-size: 2em;
}
.results {
margin-bottom: 1em;
color: #ffcc66;
}
.wpm, .time {
display: inline-block;
font-size:4em;
}
</style>
</head>
<body>
<iframe style="float:right;" src="https://ghbtns.com/github-btn.html?user=kavun&repo=freeclack&type=star&count=true&size=large" frameborder="0" scrolling="0" width="160px" height="30px"></iframe>
<div class="results">
<div>WPM <div class="wpm">?</div></div>
<div>Time <div class="time">0:00</div></div>
</div>
<textarea class="test" placeholder="Start clacking away!"></textarea>
<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js"></script>
<script>
var $test = $('.test');
$test.focus();
var $wpm = $('.wpm');
var $time = $('.time');
var currIdx = 0;
$(document).on('keypress', handleKeys);
$(document).on('keydown', handleSpecialKeys);
var startTime = {
moment: null,
date: null
};
function tryStartTimer(startTime) {
if (startTime.moment == null) {
startTime.moment = moment();
startTime.date = +new Date();
}
}
function formattedElapsed(startMoment) {
var nowMoment = moment();
return nowMoment.subtract(startMoment).format('m:ss');
}
function handleKeys(e) {
tryStartTimer(startTime);
$time.html(formattedElapsed(startTime.moment));
$wpm.html(smartWpm(startTime.date));
}
function milliSoFar(startDate) {
return (+new Date()) - startDate;
}
function smartWpm(startDate) {
currIdx++;
if (currIdx > 5) {
var num = wpm(milliSoFar(startDate), currIdx);
var numHTML = num.toFixed(0);
return numHTML;
}
return '?';
}
function wpm(milliElapsed, charactersTyped){
return ((charactersTyped / 5) / (milliElapsed / 60000));
}
function handleSpecialKeys(e) {
if (e.which === 32) {
handleKeys(e);
}
if (e.which === 8) {
if (currIdx > 0) {
currIdx--;
}
}
}
</script>
<link href='//fonts.googleapis.com/css?family=Roboto+Slab' rel='stylesheet' type='text/css'>
</body>
</html>