Permalink
Browse files

First pages commit

  • Loading branch information...
1 parent 2b7a5ba commit 6c8005343858f26972ff637f9c3f0a8651bd5fd7 @NV committed Oct 6, 2009
Showing with 3 additions and 31 deletions.
  1. +3 −31 index.html
View
@@ -27,13 +27,6 @@
#done {
color: #CCC;
}
- #correct_letters_counter {
- display: inline-block;
- background: #CCC;
- border-right: 1px solid #999;
- max-width: 100%;
- -webkit-transition: width 2s linear;
- }
</style>
</head>
<body>
@@ -42,42 +35,21 @@
<textarea rows="4" cols="40" id="type_area"></textarea>
-<p>
- Typos: <span id="typos_counter">0</span><br/>
- Speed (letter per minutes): <span id="correct_letters_counter">0</span>
-</p>
-
<script type="text/javascript">
window.onload = function(){
var text = document.getElementById('text');
var type_area = document.getElementById('type_area');
- var typos_counter = document.getElementById('typos_counter');
- var typos = 0;
- var correct_letters = 0;
- var correct_letters_counter = document.getElementById('correct_letters_counter');
- var speed_timer = false;
- var started_at;
-
text.innerHTML = '<div id="done"></div><div id="undone">' + text.innerHTML + '</div>';
type_area.onkeyup = function(){
- if (!speed_timer) {
- started_at = new Date();
- speed_timer = setInterval(function(){
- correct_letters = parseInt(document.getElementById('done').textContent.length / ((new Date() - started_at) / 60000));
- correct_letters_counter.innerHTML = correct_letters;
- correct_letters_counter.style.width = correct_letters + 'px';
- }, 2000);
- }
if (text.textContent.indexOf(type_area.value) == 0) {
text.innerHTML = text.textContent.replace(type_area.value, '<span id="done">'+ type_area.value +'</span><span id="undone">') +'</span>';
} else {
- var errors_count = type_area.value.length - document.getElementById('done').textContent.length;
- if (errors_count) {
+ var errors = type_area.value.length - document.getElementById('done').textContent.length;
+ if (errors) {
var undone = document.getElementById('undone');
- undone.innerHTML = '<del>'+ undone.textContent.substr(0, errors_count) +'</del>' + undone.textContent.substr(errors_count);
- typos_counter.innerHTML = ++typos;
+ undone.innerHTML = '<del>'+ undone.textContent.substr(0, errors) +'</del>' + undone.textContent.substr(errors);
}
}
};

0 comments on commit 6c80053

Please sign in to comment.