-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
173 lines (161 loc) · 5.76 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
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
<!DOCTYPE html>
<html>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<div id="app">
<h2>Welcome to the Left/Right shift typing test</h2>
<div v-if="state === 0" id="startup">
<div class="text passage">
<p>This is a simple typing test that does a few very simple things:</p>
<ol>
<li>Tracks how many times you use the left shift key vs. the right shift key.</li>
<li>Tracks how many times you use the backspace key.</li>
<li>How correctly you type.</li>
</ol>
<p>Like most typing tests, you'll get a passage of text to type and a text box to type in. When done, click the "Finish Typing" button to see your results.</p>
</div>
<button @click="start">Get started</button>
</div>
<div v-else-if="state === 1" id="test">
<div class="text type passage">
<span v-html="rawHtmlText"></span>
</div>
<textarea v-on:keyup="trackKeyUps" v-model="userInput" placeholder="Start typing here..." rows="8" cols="80" class="text"></textarea>
</br>
<button @click="finish">Finish Typing</button>
</div>
<div v-else id="results">
<div class="text type passage">
<h4>Expected:</h4>
<ul>
<li>Number of times left shift was used: {{expectedLeftShifts}}</li>
<li>Number of times right shift was used: {{expectedRightShifts}}</li>
<li>Number of times any shift was used: {{expectedTotalShifts}}
<li>Number of times backspace was used: 0</li>
<li>Number of differences: 0</li>
</ul>
<h4>Results:</h4>
<ul>
<li>Number of times left shift was used: {{leftShift}}</li>
<li>Number of times right shift was used: {{rightShift}}</li>
<li>Number of times any shift was used: {{totalShifts}}
<li>Number of times backspace was used: {{backspace}}</li>
<li>Number of differences (simple and inaccurate): {{differences}}
</ul>
</div>
<button @click="restart">Restart Test?</button>
<a href="#" @click="backToBegin">Go Back to the Beginning</a>
</div>
</div>
<script>
var flattenText = function(text) {
return text.match(/[^!\.]+[!\."]+|(\s+)/g).map(s => s.trim()).reduce((a,b) => a + ' ' + b)
}
var simpleDiff = function(expected, actual) {
var testLength = Math.min(expected.length, actual.length)
var diffCount = Math.abs(expected.length - actual.length)
for (var i = 0; i < testLength; i++) {
if (expected.charAt(i) !== actual.charAt(i))
diffCount++;
}
return diffCount
}
var vm = new Vue({
el: '#app',
data: {
state: 0,
text: '"There, just at your feet; don\'t be so nervous, girl!" cried Mrs Rose.\nMatty, in her anxiety not to drop the match, at once dropped it into the waste-paper basket, which was instantly alight. A stamp of the foot might have extinguished it, but this did not occur to either of the domestics. The housekeeper, who was a courageous woman, seized the basket in both hands and rushed with it to the fireplace, thereby fanning the flame into a blaze and endangering her dress and curls. She succeeded, however, in cramming the basket and its contents into the grate; then the two, with the aid of poker, tongs, and shovel, crushed and beat out the fire.\n"There! I said you\'d do it," gasped Mrs Rose, as she flung herself, panting, into Mr Auberly\'s easy-chair; "this comes of bein\' in a hurry."',
rawHtmlText: '<p>"There, just at your feet; don\'t be so nervous, girl!" cried Mrs Rose.</p><p>Matty, in her anxiety not to drop the match, at once dropped it into the waste-paper basket, which was instantly alight. A stamp of the foot might have extinguished it, but this did not occur to either of the domestics. The housekeeper, who was a courageous woman, seized the basket in both hands and rushed with it to the fireplace, thereby fanning the flame into a blaze and endangering her dress and curls. She succeeded, however, in cramming the basket and its contents into the grate; then the two, with the aid of poker, tongs, and shovel, crushed and beat out the fire.</p><p>"There! I said you\'d do it," gasped Mrs Rose, as she flung herself, panting, into Mr Auberly\'s easy-chair; "this comes of bein\' in a hurry."</p>',
userInput: '',
leftShift: 0,
rightShift: 0,
otherShift: 0,
backspace: 0,
expectedLeftShifts: 11,
expectedRightShifts: 9,
expectedTotalShifts: 20
},
methods: {
trackKeyUps: function(e) {
if (e.key === 'Shift') {
if (e.location == 1) {
this.leftShift++
} else if (e.location == 2) {
this.rightShift++
} else {
this.otherShift++
}
} else if (e.key === 'Backspace') {
this.backspace++
}
},
start: function() {
this.state++
},
finish: function() {
this.state++
},
restart: function() {
this.leftShift = 0
this.rightShift = 0
this.otherShift = 0
this.backspace = 0
this.userInput = ''
this.state--
},
backToBegin: function() {
this.restart()
this.state = 0
}
},
computed: {
totalShifts: function() {
return this.leftShift + this.rightShift + this.otherShift
},
flatText: function() {
return flattenText(this.text)
},
flatInput: function() {
return flattenText(this.userInput)
},
differences: function() {
return simpleDiff(this.flatText, this.flatInput)
}
}
})
</script>
<style>
body {
text-align: center;
background-color: #dfdfdf;
padding: 1em;
}
.passage {
max-width: 65em;
margin: auto;
}
.type {
text-align: left;
}
.text {
background-color: #efefef;
border-radius: 2px;
border-color: #333;
border: 1px solid;
padding: 1em;
}
ol {
max-width: 30em;
margin: auto;
}
li {
text-align: left;
}
textarea {
resize: none;
margin-top: 1.25em;
}
button {
margin-top: 1em;
}
</style>
</html>