js在线检测打字速度和输入字符准确性实用工具

所属分类: 网页特效-实用工具    2023-11-29 01:32:38

js在线检测打字速度和输入字符准确性实用工具 ie兼容6
 查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

js在线检测打字速度和输入字符准确性实用工具(共3个文件)

    • index.html

使用方法

const testWrapper = document.querySelector(".test-wrapper");
const testArea = document.querySelector("#test-area");
const originText = document.querySelector("#origin-text p").innerHTML;
const resetButton = document.querySelector("#reset");
const theTimer = document.querySelector(".timer");


var timer = [0,0,0,0];
var interval;
var timerRunning = false;

// Add leading zero to numbers 9 or below (purely for aesthetics):
function leadingZero(time) {
    
    if (time <= 9) {
        
        time = "0" + time;
    }
    
    return time;
}

// Run a standard minute/second/hundredths timer:
function runTimer() {
    
    let currentTime = leadingZero(timer[0]) + ":" + leadingZero(timer[1]) + ":" + leadingZero(timer[2]);
    
    theTimer.innerHTML = currentTime;
    timer[3]++;
    
    timer[0] = Math.floor((timer[3]/100)/60);
    timer[1] = Math.floor((timer[3]/100) - (timer[0] * 60));
    timer[2] = Math.floor(timer[3] - (timer[1] * 100) - (timer[0] * 6000));
}

// Match the text entered with the provided text on the page:
function spellCheck() {
    
    let textEntered = testArea.value;
    let originTextMatch = originText.substring(0, textEntered.length);
    
    if(textEntered == originText) {
        
        clearInterval(interval);
        
        testWrapper.style.borderColor = "#339900";
        
    } else {
        
        if(textEntered  == originTextMatch) {
            
            testWrapper.style.borderColor = "#E55400";
        } else {
            
            testWrapper.style.borderColor = "#FF0000";
        }
    }
    
}

// Start the timer:
function start() {
    
    let textEnteredLength = testArea.value.length;
    
    if (textEnteredLength === 0 && !timerRunning ){
        
        timerRunning = true;
        interval = setInterval(runTimer, 10);
    }
    
    console.log(textEnteredLength);
}

// Reset everything:
function reset() {
    
    clearInterval(interval);
    interval = null;
    
    timer = [0,0,0,0];
    timerRunning = false;
    
    testArea.value = "";
    theTimer.innerHTML = "00:00:00";
    testWrapper.style.borderColor = "grey";
}


// Event listeners for keyboard input and the reset button:
testArea.addEventListener("keypress", start, false);
testArea.addEventListener("keyup", spellCheck, false );
resetButton.addEventListener("click", reset, false);

站长提示:
1. 苦力吧素材官方QQ群:950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励2K币
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 实用工具

jquery功能丰富的颜色选择器插件

一款集成多种风格的颜色选择器插件,支持多种风格,弹出层选取、直接点选、获取选中值等。
  实用工具
 3922  0

jquery中文转拼音带唯一编号计算

一款中文在线转拼音插件,用户在文本框输入中文,点击确定按钮,将自动生成拼音,并且计算出这个姓名对应的唯一编号。
  实用工具
 8826  0

jquery禁止审查元素修改前端代码插件

一款轻量级前端页面内容屏蔽修改插件,在谷歌浏览器中,一般我们会使用审查元素,开启开发者工具去调试一下脚本或CSS,此插件就是要实现屏蔽此功能。
  实用工具
 5610  0

jquery检测客户端浏览器及系统版本插件

一款浏览器和平台检测插件,用户代理检测客户端浏览器(类型和版本)、操作系统、设备类型和其他util信息。
  实用工具
 1731  0

评论数(0) 回复有机会获得K币 用户协议

^_^ 还没有人评论,快来抢个沙发!
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论