All pastes #353066 Raw Edit

Typing Test

public html v1 · immutable
#353066 ·published 2007-02-13 04:34 UTC
rendered paste body
<html>    <head>        <title>See how fast you can type!</title>        <script type="text/javascript">            // Preloading is key            image = new Image();            image.src = 'text.php';                        var h = 'is altogether fitting and proper that we should do this. But, in a larger sense, we can not dedicate we can not consecrate we can not hallow this ground. The brave men, living and dead, who struggled here, have consecrated it,';            var timer = 0;            var mistakes = 0;            var mode = 'stopped';            var t;            function initiate ()            {                var img = document.getElementById('img');                                if ( mode == 'stopped' )                {                    mode = 'started';                    img.innerHTML = '<img galleryimg=no  src="text.php" />';                    start();                }            }            function start ()            {                timer += 1;                t = setTimeout ( 'start()', 1000 );            }            function trim ( s )            {                while ( s.substring(0,1) == ' ' )                {                    s = s.substring(1, s.length);                }                while ( s.substring(s.length-1, s.length) == ' ' )                {                    s = s.substring(0,s.length-1);                }                                return s;            }            function monitor ()            {                if ( mode !== 'stopped' && mode !== 'done' )                {                    var input = document.getElementById('test');                    var status = document.getElementById('status');                    var value = input.value.replace(/\.\s\s/gi, '. ');                    var length = value.length;                                        if ( value == h )                    {                        mode = 'done';                        clearTimeout ( t );                        var wpm = ( 49.8172043011 * 60 ) / timer;                        wpm = Math.round ( wpm * 100 ) / 100;                        var cpm = ( h.length * 60 ) / timer;                        cpm = Math.round ( cpm * 100 ) / 100;                        status.innerHTML = '<span class="good">DONE!</span> <a href="http://labs.jphantom.com/wpm/">Again?</a>';                        alert ( "Wow! Your typing speed (with " + mistakes + " mistakes) is:\n\n" + wpm + " wpm\n" + cpm + " cpm" );                    }                    else if ( value == h.substring(0,length) )                    {                        if ( mode == 'mistake' )                        {                            mode = 'started';                        }                                                status.innerHTML = '<span class="good">Good! Keep it up!</span>';                    }                    else if ( value !== h.substring(0,length) )                    {                        status.innerHTML = '<span class="uhoh">Oops! Quickly, you made a mistake!</span>';                                                if ( mode !== 'mistake' )                        {                            mistakes += 1;                            mode = 'mistake';                        }                    }                }            }                        function clear ()            {                var input = document.getElementById('test');                input.value = '';            }        </script>        <style type="text/css">            body { width: 600px; font-family: verdana; font-size: 11px; }            textarea { padding: 2px; font-family: verdana; font-size: 11px; border: 1px solid #000; }            #update { margin-top: 10px; }            .good { font-weight: bold; color: green; }            .uhoh { font-weight: bold; color: red; }        </style>    </head>    <body onContextMenu="return false;" onSelectStart="return false;" onDragStart="return false;" onCopy="return false;" onCut="return false;" onload="clear()">        <h1>See how fast you can type!</h1>        <div id="img" style="height: 110px;">Please wait a few seconds for the image to preload behind the scenes.<br /><br /><b>Note:</b> you must correct any mistakes to complete the test.</div>        <textarea rows="8" cols="68" id="test" onfocus="initiate()" onkeyup="monitor()"></textarea>        <div id="status"><span class="good">Get ready!</span> Once you click inside the text area, the timer will start and the text will appear.</div>        <div id="update"><strong>Update:</strong> This typing test now allows two spaces after a period due to the large amount of requests. However, you may still use a single space after a period as well.</div>        <p align="center">Copyright &copy; 2006 JPhantom.com</p>    </body></html><script language=javascript>function noStatus() {window.status="";setTimeout("noStatus()",100);}noStatus();</script>