版本比较
键盘测试
正文
增加 172 行删除 172 行
8 行未改动910111213131415161711 行未改动293031323333343536379 行未改动47484950515152535455565757585960616162636465666768697070717273747475767778798081818283848586868788899091919293949596969798991001011011021031041051051061071081091101111111121131141157 行未改动12312412512612712712812913013110 行未改动1421431441451461461471481491501511521531511521531541551561571581591601601611621631642 行未改动1671681691701711721731711721731741751761777 行未改动18518618718818918919019119219319419519619719819919920020120220320420520620720820820921021121221321421521621721721821922022111 行未改动2332342352362372372382392402412422432432442452462472482482492502512522532542552552562572582592602612622632632642652662672682692702712712722732742752742752762772782792802812822832842852852862872882892902912922932942942952962972982982993003013023033033043053063075 行未改动3133143153163173173183193203212 行未改动3243253263273283283293303313323333343343353363373388 行未改动3473483493503513513523533543553563573583583593603613623633633643653663673683683693703713723733743743753763773783793803813823823833843853863873873883893903914 行未改动39639739839940040040140240340440540640740740840941041141241241341441541641741841841942042142213 行未改动43643743843944044044144244344417 行未改动46246346446546646646746846947018 行未改动48949049149249349349449549649724 行未改动52252352452552652652752852953015 行未改动5465475485495505505515525535545555535545555565575585595605615625605615625635645655665675685695675685695705715725735745755765745755765775785795805815825835815825835845855865875885895905885895905915925935945955965975955965975985996006016026036036046056066075 行未改动6136146156166176176186196206216226236246256256266276286296306316316326336346346356366376386396396406416426426436446456466476476486496506516526536536546556566576586596606616616626636646656666676686686696706716716726736746756756766776786796806816826826836846856866866876886896908 行未改动69970070170270370370470570670715 行未改动7237247257267277277287297307317327337347347357367377377387397407407417427437447457467477487487497507517527537547547557567577587597597607617627627637647657667667677687697707707717727737747757767767777787797807817827837847857857867877887897907907917927937937947957967967977987998008018028038048048058068078088098108108118128138138148158168178178188198208218218228238248255 行未改动8318328338348358358368378388398408408418428438442 行未改动84784884985085185185285385485585685685785885986086186286386386486586686786886986987087187287387487487587687787816 行未改动8958968978988998999009019019029039049054 行未改动91091191291391491491591691791891891992092192292292392492592692792892892993093193293393393493593693793793893994094194294394394494594694794894894995095195295295395495595595695795895895996096196296396496596596696796896896997097097197297397397497597697797897897998098198298298398498598698798898998999099199299399499499599699799799899910001001100210031004100510061007100610071008100910101011101010111012101310141014101510161017101810191020102110211022102310241025102610271028102910301030103110321033103411 行未改动10461047104810491050105010511052105310544 行未改动1059106010611062106310631064106510661066106710681069107010711072107310731074107510761077107710781079108010811082108310841085108510861087108810891090109110911092109310941095109610971098109911001100110111021103110411041105110611071108110911101110111111121113111311141115111611171118111811191120112111211122112311241125112611271128112911301131113111321133113411352 行未改动1138113911401141114211421143114411451146114611471148114911502 行未改动115311541155115611571157115811591160116111621163116311641165116611671168116911701171117211731173117411751176117711781179118011811181118211831184118511861187118711881189119011913 行未改动8 行未改动 <!-- 引入Tailwind CSS --> <script src="https://cdn.tailwindcss.com"></script> <!-- 引入Font Awesome --> <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
<!-- 配置Tailwind自定义颜色和字体 --> <script> tailwind.config = { theme: {11 行未改动 }, } } </script>
<!-- 自定义工具类 --> <style type="text/tailwindcss"> @layer utilities { .content-auto {9 行未改动 @apply bg-gray-100 dark:bg-gray-800 border border-gray-300 dark:border-gray-700 rounded-md px-3 py-2 text-sm font-medium shadow-sm hover:bg-gray-200 dark:hover:bg-gray-700 transition-all duration-200; } } </style>
<style> /* 基础动画和全局样式 */ body { scroll-behavior: smooth; }
.pulse { animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.7; } }
.bounce-in { animation: bounce-in 0.6s cubic-bezier(0.215, 0.610, 0.355, 1.000); }
@keyframes bounce-in { 0% { transform: scale(0.3); opacity: 0; } 50% { transform: scale(1.05); } 70% { transform: scale(0.9); } 100% { transform: scale(1); opacity: 1; } }
/* 打字区域样式 */ .typing-correct { color: #10B981; }
.typing-current { background-color: rgba(59, 130, 246, 0.2); border-bottom: 2px solid #3B82F6; }
.typing-error { color: #EF4444; text-decoration: underline wavy; }
/* 进度条动画 */ @keyframes progress { 0% { width: 0%; } }
.progress-animation { animation: progress 1s linear; }
/* 快捷键测试相关样式 */ #shortcut-content { min-height: 80px; transition: all 0.3s ease; }
.shortcut-highlight { background-color: rgba(59, 130, 246, 0.2); padding: 0 2px; }7 行未改动 <div class="flex items-center space-x-2"> <i class="fa fa-keyboard-o text-primary text-2xl"></i> <h1 class="text-xl font-bold text-primary">键盘技能测试平台</h1> </div>
<div id="user-info" class="hidden items-center space-x-3"> <span id="student-name" class="font-medium"></span> <div class="w-8 h-8 rounded-full bg-primary/10 flex items-center justify-center"> <i class="fa fa-user text-primary"></i>10 行未改动 <i class="fa fa-keyboard-o text-6xl text-primary mb-4"></i> <h2 class="text-[clamp(1.8rem,5vw,2.5rem)] font-bold text-dark dark:text-white mb-2">键盘技能测试</h2> <p class="text-neutral text-lg">测试你的键盘操作能力,包括打字速度、准确率和快捷键使用</p> </div>
<div class="bg-white dark:bg-gray-800 rounded-xl shadow-lg p-6 md:p-8"> <form id="name-form" class="space-y-4"> <div> <label for="student-name-input" class="block text-left mb-2 font-medium">请输入你的姓名</label> <input type="text" id="student-name-input" <input type="text" id="student-name-input" required minlength="2" class="w-full px-4 py-3 rounded-lg border border-gray-300 dark:border-gray-700 bg-gray-50 dark:bg-gray-900 focus:ring-2 focus:ring-primary focus:border-primary transition-all outline-none" placeholder="请输入姓名开始测试" > </div>
<div class="p-4 bg-blue-50 dark:bg-blue-900/30 rounded-lg text-left"> <h4 class="font-medium flex items-center mb-2"> <i class="fa fa-info-circle text-primary mr-2"></i>测试说明 </h4>2 行未改动 <li>• 禁止复制粘贴,否则将被视为作弊</li> <li>• 请确保网络连接稳定</li> </ul> </div> <button type="submit"
<button type="submit" class="w-full bg-primary hover:bg-primary/90 text-white font-medium py-3 px-4 rounded-lg transition-all duration-300 transform hover:scale-[1.02] active:scale-[0.98] shadow-md hover:shadow-lg flex items-center justify-center" > <span>开始测试</span> <i class="fa fa-arrow-right ml-2"></i>7 行未改动 <div class="text-center mb-8"> <h2 class="text-2xl md:text-3xl font-bold mb-2">选择测试类型</h2> <p class="text-neutral">请选择你要进行的键盘技能测试</p> </div>
<div class="grid md:grid-cols-2 lg:grid-cols-4 gap-6"> <!-- 基础打字测试 --> <div class="bg-white dark:bg-gray-800 rounded-xl shadow-md p-6 hover:shadow-lg transition-all duration-300 transform hover:-translate-y-1 cursor-pointer test-card" data-test="basic"> <div class="w-14 h-14 bg-blue-100 dark:bg-blue-900/30 rounded-full flex items-center justify-center mb-4"> <i class="fa fa-font text-primary text-2xl"></i> </div> <h3 class="text-xl font-semibold mb-2">基础打字</h3> <p class="text-neutral text-sm">测试打字速度和准确率,输入指定文本内容</p> </div>
<!-- 大小写切换测试 --> <div class="bg-white dark:bg-gray-800 rounded-xl shadow-md p-6 hover:shadow-lg transition-all duration-300 transform hover:-translate-y-1 cursor-pointer test-card" data-test="case"> <div class="w-14 h-14 bg-green-100 dark:bg-green-900/30 rounded-full flex items-center justify-center mb-4"> <i class="fa fa-arrow-up text-secondary text-2xl"></i> </div> <h3 class="text-xl font-semibold mb-2">大小写切换</h3> <p class="text-neutral text-sm">测试大小写切换能力,按要求输入大小写字母</p> </div>
<!-- 标点符号测试 --> <div class="bg-white dark:bg-gray-800 rounded-xl shadow-md p-6 hover:shadow-lg transition-all duration-300 transform hover:-translate-y-1 cursor-pointer test-card" data-test="punctuation"> <div class="w-14 h-14 bg-amber-100 dark:bg-amber-900/30 rounded-full flex items-center justify-center mb-4"> <i class="fa fa-pencil text-amber-600 dark:text-amber-400 text-2xl"></i> </div> <h3 class="text-xl font-semibold mb-2">标点符号</h3> <p class="text-neutral text-sm">测试各种标点符号的输入和应用能力</p> </div>
<!-- 快捷键测试 --> <div class="bg-white dark:bg-gray-800 rounded-xl shadow-md p-6 hover:shadow-lg transition-all duration-300 transform hover:-translate-y-1 cursor-pointer test-card" data-test="shortcut"> <div class="w-14 h-14 bg-purple-100 dark:bg-purple-900/30 rounded-full flex items-center justify-center mb-4"> <i class="fa fa-key text-purple-600 dark:text-purple-400 text-2xl"></i>11 行未改动 <div> <h2 id="test-title" class="text-2xl font-bold"></h2> <p id="test-description" class="text-neutral"></p> </div>
<div class="flex gap-4 w-full md:w-auto"> <div class="bg-white dark:bg-gray-800 rounded-lg shadow p-3 flex-1 md:flex-none md:w-32"> <p class="text-sm text-neutral">速度 (WPM)</p> <p id="wpm-counter" class="text-xl font-bold text-primary">0</p> </div>
<div class="bg-white dark:bg-gray-800 rounded-lg shadow p-3 flex-1 md:flex-none md:w-32"> <p class="text-sm text-neutral">准确率</p> <p id="accuracy-counter" class="text-xl font-bold text-secondary">0%</p> </div>
<div class="bg-white dark:bg-gray-800 rounded-lg shadow p-3 flex-1 md:flex-none md:w-32"> <p class="text-sm text-neutral">用时</p> <p id="timer" class="text-xl font-bold text-dark dark:text-white">00:00</p> </div> </div> </div>
<!-- 防作弊警告 --> <div class="bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 rounded-lg p-3 mb-6 flex items-start"> <i class="fa fa-exclamation-triangle text-amber-500 mt-0.5 mr-3"></i> <p class="text-sm text-amber-800 dark:text-amber-300"> <strong>防作弊监测中:</strong>禁止复制粘贴,系统将自动检测作弊行为并记录。 </p> </div>
<!-- 测试内容区域 --> <div class="bg-white dark:bg-gray-800 rounded-xl shadow-lg p-6 mb-6"> <!-- 基础打字、大小写和标点符号测试内容 --> <div id="text-test-container" class="hidden"> <div id="text-to-type" class="text-lg md:text-xl leading-relaxed mb-6 p-4 bg-gray-50 dark:bg-gray-900 rounded-lg min-h-[120px]"> <!-- 动态生成的测试文本 --> </div>
<div> <label for="user-input" class="block text-sm font-medium mb-2">请在此输入</label> <textarea id="user-input" <textarea id="user-input" class="w-full p-4 border border-gray-300 dark:border-gray-700 rounded-lg bg-gray-50 dark:bg-gray-900 focus:ring-2 focus:ring-primary focus:border-primary transition-all outline-none min-h-[100px] resize-none" placeholder="开始输入..." autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" ></textarea> </div> </div>
<!-- 快捷键测试内容 --> <div id="shortcut-test-container" class="hidden"> <div class="mb-6"> <p class="text-sm font-medium mb-2">操作文本:</p> <div id="shortcut-content" class="p-4 bg-gray-50 dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-700"> 键盘快捷键是提高电脑操作效率的重要技巧,熟练掌握能大幅提升工作学习速度。 </div> </div>
<div id="shortcut-instruction" class="text-lg md:text-xl text-center p-6 bg-gray-50 dark:bg-gray-900 rounded-lg mb-8"> <!-- 动态生成的快捷键指令 --> </div>
<div class="text-center"> <div id="shortcut-status" class="mb-6 py-4 rounded-lg border-2 border-gray-200 dark:border-gray-700"> <p class="text-neutral">请按提示的快捷键</p> </div>
<div class="flex flex-wrap justify-center gap-3 mb-4"> <span class="keyboard-key">Ctrl</span> <span class="keyboard-key">Shift</span> <span class="keyboard-key">Alt</span>5 行未改动 </div> </div> </div> </div>
<!-- 进度条 --> <div class="mb-6"> <div class="flex justify-between text-sm mb-1"> <span>测试进度</span>2 行未改动 <div class="w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2.5"> <div id="progress-bar" class="bg-primary h-2.5 rounded-full progress-animation" style="width: 0%"></div> </div> </div>
<!-- 按钮区域 --> <div class="flex justify-between"> <button id="back-to-selection" class="px-5 py-2.5 bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 rounded-lg transition-all duration-200"> <i class="fa fa-arrow-left mr-2"></i>返回选择 </button>
<button id="submit-test" class="px-5 py-2.5 bg-primary hover:bg-primary/90 text-white rounded-lg transition-all duration-200 hidden"> 提交测试 <i class="fa fa-check ml-2"></i> </button>8 行未改动 </div> <h2 class="text-2xl md:text-3xl font-bold mb-2">测试完成!</h2> <p class="text-neutral">以下是你的测试结果</p> </div>
<div class="bg-white dark:bg-gray-800 rounded-xl shadow-lg p-6 md:p-8 mb-6"> <div class="flex flex-col md:flex-row justify-center gap-8 mb-8"> <div> <p class="text-neutral mb-1">测试类型</p> <p id="result-test-type" class="text-xl font-bold"></p> </div>
<div> <p class="text-neutral mb-1">用时</p> <p id="result-time" class="text-xl font-bold"></p> </div>
<div> <p class="text-neutral mb-1">速度</p> <p id="result-wpm" class="text-xl font-bold text-primary"></p> </div>
<div> <p class="text-neutral mb-1">准确率</p> <p id="result-accuracy" class="text-xl font-bold text-secondary"></p> </div> </div>
<div class="border-t border-gray-200 dark:border-gray-700 pt-6"> <h3 class="text-lg font-semibold mb-4">详细分析</h3> <div id="detailed-analysis" class="text-left space-y-3"> <!-- 动态生成的详细分析 --> </div> </div> </div>
<div class="flex flex-col sm:flex-row gap-4 justify-center"> <button id="new-test" class="px-6 py-3 bg-primary hover:bg-primary/90 text-white font-medium rounded-lg transition-all duration-300"> 进行新测试 </button>
<button id="view-summary" class="px-6 py-3 bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 font-medium rounded-lg transition-all duration-300"> 查看总览 </button> </div>4 行未改动 <div class="text-center mb-8"> <h2 class="text-2xl md:text-3xl font-bold mb-2">测试总览</h2> <p class="text-neutral">你的所有测试记录和表现分析</p> </div>
<div class="bg-white dark:bg-gray-800 rounded-xl shadow-lg p-6 mb-6"> <div class="grid md:grid-cols-3 gap-6 mb-8"> <div class="p-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg"> <p class="text-neutral text-sm mb-1">已完成测试</p> <p id="total-tests" class="text-3xl font-bold text-primary">0</p> </div>
<div class="p-4 bg-green-50 dark:bg-green-900/20 rounded-lg"> <p class="text-neutral text-sm mb-1">平均准确率</p> <p id="avg-accuracy" class="text-3xl font-bold text-secondary">0%</p> </div>
<div class="p-4 bg-purple-50 dark:bg-purple-900/20 rounded-lg"> <p class="text-neutral text-sm mb-1">平均速度</p> <p id="avg-wpm" class="text-3xl font-bold text-purple-600 dark:text-purple-400">0 WPM</p> </div> </div>
<h3 class="text-lg font-semibold mb-4">测试历史</h3> <div class="overflow-x-auto"> <table class="min-w-full divide-y divide-gray-200 dark:divide-gray-700"> <thead>13 行未改动 </tbody> </table> </div> </div>
<div class="text-center"> <button id="back-to-tests" class="px-6 py-3 bg-primary hover:bg-primary/90 text-white font-medium rounded-lg transition-all duration-300"> 返回测试 </button>17 行未改动 </div> <h3 class="text-xl font-bold text-danger mb-2">检测到作弊行为</h3> <p class="text-neutral">复制粘贴操作已被禁止。请使用键盘手动输入完成测试。</p> </div>
<div class="text-center"> <button id="close-cheat-modal" class="px-5 py-2.5 bg-danger hover:bg-danger/90 text-white rounded-lg transition-all duration-200"> 我知道了 </button>18 行未改动 shortcutAttempts: [], shortcutSuccess: 0 }; let testHistory = JSON.parse(localStorage.getItem('keyboardTestHistory')) || [];
// DOM元素 const welcomeScreen = document.getElementById('welcome-screen'); const testSelection = document.getElementById('test-selection'); const testScreen = document.getElementById('test-screen');24 行未改动 const viewSummary = document.getElementById('view-summary'); const backToTests = document.getElementById('back-to-tests'); const cheatModal = document.getElementById('cheat-modal'); const closeCheatModal = document.getElementById('close-cheat-modal');
// 测试文本数据 const testTexts = { basic: [ "计算机键盘是计算机的重要输入设备,熟练掌握键盘操作是提高计算机使用效率的基础。多加练习能进步更快。",15 行未改动 "北京(中国首都)是一座美丽的城市,有着3000多年的历史。", "她买了苹果5个,香蕉10根,橘子15斤,总共花了88元。" ] };
// 快捷键测试数据 const shortcutTests = [ { key: 'a', modifier: 'ctrl', { key: 'a', modifier: 'ctrl', description: '全选文本 (Ctrl + A)', action: 'selectAll', successMsg: '已成功全选文本!' }, { key: 'c', modifier: 'ctrl', { key: 'c', modifier: 'ctrl', description: '复制选中的文本 (Ctrl + C)', action: 'copy', successMsg: '已成功复制文本!' }, { key: 'v', modifier: 'ctrl', { key: 'v', modifier: 'ctrl', description: '粘贴复制的文本 (Ctrl + V)', action: 'paste', successMsg: '已成功粘贴文本!' }, { key: 'x', modifier: 'ctrl', { key: 'x', modifier: 'ctrl', description: '剪切选中的文本 (Ctrl + X)', action: 'cut', successMsg: '已成功剪切文本!' }, { key: 'z', modifier: 'ctrl', { key: 'z', modifier: 'ctrl', description: '撤销上一步操作 (Ctrl + Z)', action: 'undo', successMsg: '已成功撤销操作!' }, { key: 'f', modifier: 'ctrl', { key: 'f', modifier: 'ctrl', description: '查找文本内容 (Ctrl + F)', action: 'find', successMsg: '已成功打开查找功能!' }, { key: 's', modifier: 'ctrl', { key: 's', modifier: 'ctrl', description: '保存当前内容 (Ctrl + S)', action: 'save', successMsg: '已成功执行保存操作!' } ];
// 初始化事件监听 function initEventListeners() { // 姓名表单提交 nameForm.addEventListener('submit', (e) => {5 行未改动 userInfo.classList.add('flex'); showScreen(testSelection); } });
// 测试类型选择 testCards.forEach(card => { card.addEventListener('click', () => { const testType = card.getAttribute('data-test'); startTest(testType); }); });
// 返回测试选择 backToSelection.addEventListener('click', () => { endTest(); showScreen(testSelection); });
// 提交测试 submitTest.addEventListener('click', calculateResults);
// 新测试 newTest.addEventListener('click', () => { showScreen(testSelection); });
// 查看总览 viewSummary.addEventListener('click', showSummary);
// 返回测试 backToTests.addEventListener('click', () => { showScreen(testSelection); });
// 关闭作弊警告 closeCheatModal.addEventListener('click', () => { cheatModal.classList.remove('flex'); cheatModal.classList.add('hidden'); });
// 防复制粘贴 document.addEventListener('copy', (e) => { if (testScreen.classList.contains('flex')) { e.preventDefault(); showCheatWarning(); } });
document.addEventListener('paste', (e) => { if (testScreen.classList.contains('flex')) { e.preventDefault(); showCheatWarning(); } });
// 输入监听 userInput.addEventListener('input', handleTextInput);
// 快捷键监听 document.addEventListener('keydown', handleKeyDown); }
// 显示指定屏幕 function showScreen(screen) { [welcomeScreen, testSelection, testScreen, resultsScreen, summaryScreen].forEach(s => { s.classList.add('hidden'); s.classList.remove('flex', 'flex-col'); });
screen.classList.remove('hidden'); screen.classList.add('flex', 'flex-col'); }
// 开始测试 function startTest(testType) { currentTest = testType; testData = {8 行未改动 shortcutSuccess: 0, currentShortcutIndex: 0, originalContent: '键盘快捷键是提高电脑操作效率的重要技巧,熟练掌握能大幅提升工作学习速度。' };
// 设置测试标题和描述 switch(testType) { case 'basic': testTitle.textContent = '基础打字测试';15 行未改动 testDescription.textContent = '根据提示对下方文本执行相应的快捷键操作'; setupShortcutTest(); break; }
// 重置计数器 wpmCounter.textContent = '0'; accuracyCounter.textContent = '0%'; timer.textContent = '00:00'; progressBar.style.width = '0%'; progressPercentage.textContent = '0%';
// 开始计时 startTimer();
// 显示测试屏幕 showScreen(testScreen);
// 自动聚焦到输入框 if (testType !== 'shortcut') { userInput.focus(); } else { shortcutContent.focus(); } }
// 设置文本测试 function setupTextTest(type) { // 显示文本测试容器,隐藏快捷键容器 textTestContainer.classList.remove('hidden'); shortcutTestContainer.classList.add('hidden');
// 随机选择一个测试文本 const textIndex = Math.floor(Math.random() * testTexts[type].length); testData.text = testTexts[type][textIndex]; testData.totalChars = testData.text.length;
// 渲染测试文本 renderTestText();
// 清空输入框 userInput.value = ''; }
// 渲染测试文本 function renderTestText() { textToType.innerHTML = '';
// 拆分文本为单个字符并添加到DOM for (let i = 0; i < testData.text.length; i++) { const charSpan = document.createElement('span'); charSpan.textContent = testData.text[i]; charSpan.classList.add('inline-block');
// 已输入的字符 if (i < testData.userInput.length) { // 正确或错误的字符 if (testData.userInput[i] === testData.text[i]) { charSpan.classList.add('typing-correct'); } else { charSpan.classList.add('typing-error'); } } } // 当前需要输入的字符 else if (i === testData.userInput.length) { charSpan.classList.add('typing-current'); }
textToType.appendChild(charSpan); }
// 更新进度 updateProgress();
// 检查是否完成 if (testData.userInput.length === testData.text.length) { submitTest.classList.remove('hidden'); } else { submitTest.classList.add('hidden'); } }
// 设置快捷键测试 function setupShortcutTest() { // 显示快捷键测试容器,隐藏文本容器 textTestContainer.classList.add('hidden'); shortcutTestContainer.classList.remove('hidden');
// 初始化文本内容 shortcutContent.textContent = testData.originalContent;
// 打乱快捷键测试顺序 testData.shortcutTests = [...shortcutTests].sort(() => Math.random() - 0.5); testData.currentShortcutIndex = 0;
// 显示第一个快捷键测试 showCurrentShortcut(); }
// 显示当前快捷键测试 function showCurrentShortcut() { if (testData.currentShortcutIndex < testData.shortcutTests.length) { const current = testData.shortcutTests[testData.currentShortcutIndex];5 行未改动 shortcutStatus.innerHTML = `<p class="text-secondary"><i class="fa fa-check-circle mr-1"></i> 全部完成</p>`; submitTest.classList.remove('hidden'); } }
// 处理文本输入 function handleTextInput() { const input = userInput.value; testData.userInput = input;
// 计算错误数量 let errors = 0; for (let i = 0; i < input.length; i++) { if (i >= testData.text.length) {2 行未改动 errors++; } } testData.errors = errors;
// 更新显示 renderTestText(); updateStats(); }
// 处理按键事件 function handleKeyDown(e) { // 只在快捷键测试中处理 if (currentTest !== 'shortcut' || testData.currentShortcutIndex >= testData.shortcutTests.length) { return; }
const current = testData.shortcutTests[testData.currentShortcutIndex]; const isCtrl = e.ctrlKey; const isShift = e.shiftKey; const isAlt = e.altKey; const key = e.key.toLowerCase();
// 检查是否匹配当前快捷键 if (current.modifier === 'ctrl' && isCtrl && !isShift && !isAlt && key === current.key) { e.preventDefault(); testData.shortcutSuccess++;
// 根据不同快捷键执行相应的视觉反馈 switch(current.action) { case 'selectAll': // 模拟全选效果16 行未改动 shortcutContent.textContent = testData.originalContent; break; // 其他操作不需要改变文本,只需要反馈 }
shortcutStatus.innerHTML = `<p class="text-secondary"><i class="fa fa-check-circle mr-1"></i> ${current.successMsg}</p>`;
// 延迟显示下一个快捷键 setTimeout(() => { testData.currentShortcutIndex++; showCurrentShortcut();4 行未改动 // 只按了字母键,没有按修饰键 shortcutStatus.innerHTML = `<p class="text-danger"><i class="fa fa-times-circle mr-1"></i> 请同时按下 ${current.modifier.toUpperCase()} 键</p>`; } }
// 开始计时器 function startTimer() { testStartTime = Date.now();
if (timerInterval) { clearInterval(timerInterval); }
timerInterval = setInterval(() => { const elapsedTime = Math.floor((Date.now() - testStartTime) / 1000); const minutes = Math.floor(elapsedTime / 60).toString().padStart(2, '0'); const seconds = (elapsedTime % 60).toString().padStart(2, '0'); timer.textContent = `${minutes}:${seconds}`;
// 更新统计数据 updateStats(); }, 1000); }
// 更新进度 function updateProgress() { let progress = 0;
if (currentTest === 'shortcut') { progress = (testData.currentShortcutIndex / testData.shortcutTests.length) * 100; } else { progress = (testData.userInput.length / testData.text.length) * 100; }
progress = Math.min(100, Math.round(progress)); progressBar.style.width = `${progress}%`; progressPercentage.textContent = `${progress}%`; }
// 更新统计数据 function updateStats() { const elapsedMinutes = (Date.now() - testStartTime) / (1000 * 60);
if (currentTest === 'shortcut') { // 快捷键测试统计 const accuracy = testData.shortcutTests.length > 0 const accuracy = testData.shortcutTests.length > 0 ? Math.round((testData.shortcutSuccess / testData.shortcutTests.length) * 100) : 0;
accuracyCounter.textContent = `${accuracy}%`; wpmCounter.textContent = 'N/A'; // 快捷键测试不计算WPM } else { // 文本测试统计 const typedChars = testData.userInput.length; const correctChars = typedChars - testData.errors; const accuracy = typedChars > 0 const accuracy = typedChars > 0 ? Math.round((correctChars / typedChars) * 100) : 0;
// 计算每分钟字数 (WPM) const wpm = elapsedMinutes > 0 const wpm = elapsedMinutes > 0 ? Math.round(typedChars / 5 / elapsedMinutes) // 平均5个字符一个词 : 0;
accuracyCounter.textContent = `${accuracy}%`; wpmCounter.textContent = wpm.toString(); } }
// 计算并显示测试结果 function calculateResults() { endTest();
// 记录结束时间 testData.endTime = Date.now(); const elapsedTimeMs = testData.endTime - testData.startTime; const elapsedMinutes = elapsedTimeMs / (1000 * 60); const elapsedSeconds = Math.floor(elapsedTimeMs / 1000); const timeDisplay = `${Math.floor(elapsedSeconds / 60)}分${elapsedSeconds % 60}秒`;
// 计算结果 let wpm = 0; let accuracy = 0; let analysis = '';
if (currentTest === 'shortcut') { accuracy = Math.round((testData.shortcutSuccess / testData.shortcutTests.length) * 100);
analysis = ` <p>• 共完成 ${testData.shortcutTests.length} 个快捷键测试</p> <p>• 正确操作: ${testData.shortcutSuccess} 个</p> <p>• 错误操作: ${testData.shortcutTests.length - testData.shortcutSuccess} 个</p> `; } else { const typedChars = testData.userInput.length; const correctChars = typedChars - testData.errors; accuracy = typedChars > 0
accuracy = typedChars > 0 ? Math.round((correctChars / typedChars) * 100) : 0; wpm = elapsedMinutes > 0
wpm = elapsedMinutes > 0 ? Math.round(typedChars / 5 / elapsedMinutes) : 0;
// 针对标点符号测试的特殊分析 if (currentTest === 'punctuation') { // 统计标点符号错误 const punctuationMarks = ['.', ',', ';', ':', '!', '?', '"', "'", '(', ')', '《', '》', '「', '」', ',', '。', ';', ':', '!', '?']; let punctuationErrors = 0; let totalPunctuation = 0;
for (let i = 0; i < Math.min(testData.text.length, testData.userInput.length); i++) { if (punctuationMarks.includes(testData.text[i])) { totalPunctuation++; if (testData.text[i] !== testData.userInput[i]) { punctuationErrors++; } } }
analysis = ` <p>• 总输入字符: ${typedChars} 个</p> <p>• 正确字符: ${correctChars} 个</p> <p>• 错误字符: ${testData.errors} 个</p>11 行未改动 <p>• 准确率评估: ${getAccuracyRating(accuracy)}</p> `; } }
// 保存测试结果 const testResult = { studentName, type: currentTest,4 行未改动 accuracy: `${accuracy}%`, accuracyValue: accuracy, date: new Date().toISOString() };
testHistory.push(testResult); localStorage.setItem('keyboardTestHistory', JSON.stringify(testHistory));
// 更新结果界面 document.getElementById('result-test-type').textContent = getTestTypeName(currentTest); document.getElementById('result-time').textContent = timeDisplay; document.getElementById('result-wpm').textContent = currentTest === 'shortcut' ? 'N/A' : `${wpm} WPM`; document.getElementById('result-accuracy').textContent = `${accuracy}%`; document.getElementById('detailed-analysis').innerHTML = analysis;
// 显示结果界面 showScreen(resultsScreen); }
// 结束测试 function endTest() { if (timerInterval) { clearInterval(timerInterval); timerInterval = null; } }
// 显示作弊警告 function showCheatWarning() { cheatModal.classList.remove('hidden'); cheatModal.classList.add('flex'); }
// 显示总览 function showSummary() { // 计算统计数据 const totalTests = testHistory.length; let totalAccuracy = 0; let accuracyCount = 0; let totalWpm = 0; let wpmCount = 0;
testHistory.forEach(test => { totalAccuracy += test.accuracyValue; accuracyCount++;
if (test.wpm !== 'N/A') { totalWpm += test.wpm; wpmCount++; } });
const avgAccuracy = accuracyCount > 0 ? Math.round(totalAccuracy / accuracyCount) : 0; const avgWpm = wpmCount > 0 ? Math.round(totalWpm / wpmCount) : 0;
// 更新统计数据显示 document.getElementById('total-tests').textContent = totalTests; document.getElementById('avg-accuracy').textContent = `${avgAccuracy}%`; document.getElementById('avg-wpm').textContent = `${avgWpm} WPM`;
// 更新测试历史表格 const testHistoryEl = document.getElementById('test-history');
if (totalTests === 0) { testHistoryEl.innerHTML = ` <tr> <td colspan="5" class="px-4 py-8 text-center text-neutral">暂无测试记录</td> </tr> `; } else { // 按日期排序,最新的在前 const sortedHistory = [...testHistory].sort((a, b) => new Date(b.date) - new Date(a.date));
testHistoryEl.innerHTML = sortedHistory.map(test => ` <tr> <td class="px-4 py-3">${test.typeName}</td> <td class="px-4 py-3">${test.time}</td>2 行未改动 <td class="px-4 py-3">${formatDate(test.date)}</td> </tr> `).join(''); }
// 显示总览界面 showScreen(summaryScreen); }
// 辅助函数:获取测试类型名称 function getTestTypeName(type) { const types = { 'basic': '基础打字',2 行未改动 'shortcut': '快捷键' }; return types[type] || type; }
// 辅助函数:格式化日期 function formatDate(dateString) { const date = new Date(dateString); return `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')}`; }
// 辅助函数:获取速度评级 function getSpeedRating(wpm) { if (wpm < 10) return '入门级,继续练习'; if (wpm < 20) return '初级水平,有提升空间'; if (wpm < 30) return '中等水平,表现不错'; if (wpm < 40) return '良好水平,继续保持'; if (wpm < 50) return '优秀水平,非常出色'; return '专业水平,令人印象深刻'; }
// 辅助函数:获取准确率评级 function getAccuracyRating(accuracy) { if (accuracy < 70) return '需要提高准确性'; if (accuracy < 80) return '良好,继续努力'; if (accuracy < 90) return '优秀,很少出错'; return '非常精准,几乎没有错误'; }
// 初始化应用 function init() { initEventListeners(); showScreen(welcomeScreen); }
// 启动应用 document.addEventListener('DOMContentLoaded', init); </script></body>3 行未改动