<html><head><title>jsTypingTutor</title>
<!-- jsTypingTutor_lib.js -->
<script language="JavaScript">
/*
#-----------------------------------------------------------------------------
# Name: jsTypingTutor
# Purpose: To help build typing speed in users
# and in developers.
#
# Author: Jason Don Stracner
#
# Created: 2001/10/06
# RCS-ID: $Id: jsTypingTutor_lib.js $
# Copyright: (c) Little Rock Technology Consulting
# Licence: GPL
#-----------------------------------------------------------------------------
jsTypingTutor - Source Code Documentation
This file is the JavaScript code for jsTypingTutor. This
project is intended to help users develop faster typing
by simply re-typing text. The sample text files that are
included are mainly computer code. Computer code is thought
to make fuller use of the keyboard. It is a simple matter
to add your own text to the HTML file and have any text
displayed.
*/
var objTimer=null;
var rStartTime=0;
var rSecondsPassed_=0;
var rPauseStart_=0;
var iStrLen_=0;
var sStatMsg="";
/**
* Sets text in txtStats_ on the HTML page on a timed interval.
*
*
**/
function timer() {
var dtNow_ = new Date();
rSecondsPassed_ = dtNow_.getTime();
rSecondsPassed_ = rSecondsPassed_ / 1000;
rSecondsPassed_ = Math.round(rSecondsPassed_ - rStartTime);
iStrLen_ = document.frmTyping_.txtTop_.value.length;
iStrLen_ = iStrLen_ + document.frmTyping_.txtTypeHere_.value.length;
sStatMsg="Characters: " + iStrLen_;
sStatMsg += " Seconds Passed:" + rSecondsPassed_;
sStatMsg += " Word per minute:" + Math.round((iStrLen_ / rSecondsPassed_)/ (6 / 60));
document.frmTyping_.txtStats_.value=sStatMsg;
}
/**
* Called by button in HTML to start running the
* 'timer' function on a timed interval.
*
**/
function startTimer() {
rStartTime = parseInt((new Date).getTime()/1000);
rSecondsPassed_=0;
endTimer();
objTimer = setInterval("timer();",1000);
}
/**
* Called by button in HTML to pause the running
* of the 'timer' function on a timed interval.
*
**/
function pauseTimer() {
rPauseStart_ = parseInt((new Date).getTime()/1000);
if (objTimer != null) {
clearInterval(objTimer);
objTimer = null;
}
}
/**
* Called by button in HTML to resume the running
* of the 'timer' function on a timed interval.
*
**/
function resumeTimer() {
rStartTime=rStartTime+(parseInt((new Date).getTime()/1000)-rPauseStart_);
if (objTimer != null) {
clearInterval(objTimer);
objTimer = null;
}
objTimer = setInterval("timer();",1000);
}
/**
* Called by button in HTML to stop running the
* 'timer' function on a timed interval.
*
**/
function endTimer() {
rSecondsPassed_ = 0;
if (objTimer != null) {
clearInterval(objTimer);
objTimer = null;
}
}
/**
* Checks the content of the textbox 'txtTypeHere_'
* and eleminates any incorrect characters.
*
**/
function validateTyping(e) {
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
if (isNN) {
sChar = String.fromCharCode(e.which);
} else {
sChar = String.fromCharCode(event.keyCode);
}
var iTypedLength = document.frmTyping_.txtTypeHere_.value.length;
var sInitialValue = document.frmTyping_.txtBottom_.value.substring(0,iTypedLength);
var sTestChunk = document.frmTyping_.txtTypeHere_.value.substring(0,iTypedLength) + sChar;
var sCorrectChunk = document.frmTyping_.txtBottom_.value.substring(0,iTypedLength+1);
if (sTestChunk != sCorrectChunk) {
document.frmTyping_.txtTypeHere_.value=sInitialValue;
} else {
document.frmTyping_.txtTypeHere_.value=sCorrectChunk;
}
if (escape(document.frmTyping_.txtBottom_.value.charAt(iTypedLength))=="%0D") {
document.frmTyping_.txtTop_.value+= "\n" +
document.frmTyping_.txtBottom_.value.substring(0,iTypedLength);
document.frmTyping_.txtBottom_.value=
document.frmTyping_.txtBottom_.value.substring(iTypedLength+2,document.frmTyping_.txtBottom_.value.length);
document.frmTyping_.txtTypeHere_.value="";
}
//There should never be a return character at the end.
if (escape(document.frmTyping_.txtTypeHere_.value.charAt(iTypedLength-1))=="%0A") {
// Remove return character.
document.frmTyping_.txtTypeHere_.value=
document.frmTyping_.txtTypeHere_.value.substring(0,iTypedLength-2);
}
}
</script>
</head>
<body text="#0000ff">
<strong><center><font size="+2">jsTypingTutor</font></center></strong>
<hr align="center" size="2" width="25%">
<br>
<br>
<center>
<form name="frmTyping_"><b>T</b>yping statistics:<br>
<textarea name="txtStats_" rows="1" cols="80"></textarea><br>
<input onclick="startTimer()" value="Start" name="cmdStartTimer_" type="button">
<input onclick="pauseTimer()" value="Pause" name="cmdPauseTimer_" type="button">
<input onclick="resumeTimer()" value="Resume" name="cmdResumeTimer_" type="button">
<input onclick="endTimer()" value="Stop" name="cmdEndTimer_" type="button"><br>
<textarea name="txtTop_" rows="8" cols="80"></textarea><br>
<small><b>T</b>ype text into this area:</small><br>
<textarea name="txtTypeHere_" rows="1" cols="80" onkeypress="validateTyping(event);return false;"></textarea>
<textarea name="txtBottom_" rows="8" cols="80">Instructions:
Paste some text into this area then press the 'Start button'.
</textarea><br>
</form>
</center>
</body></html>
|