版本比较
键盘测试
正文
增加 172 行删除 172 行
8 行未改动9101112131415161711 行未改动2930313233343536379 行未改动47484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141157 行未改动12312412512612712812913013110 行未改动1421431441451461471481491501511521531541551561571581591601611621631642 行未改动1671681691701711721731741751761777 行未改动18518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022111 行未改动2332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063075 行未改动3133143153163173183193203212 行未改动3243253263273283293303313323333343353363373388 行未改动3473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903914 行未改动39639739839940040140240340440540640740840941041141241341441541641741841942042142213 行未改动43643743843944044144244344417 行未改动46246346446546646746846947018 行未改动48949049149249349449549649724 行未改动52252352452552652752852953015 行未改动5465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066075 行未改动6136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896908 行未改动69970070170270370470570670715 行未改动7237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248255 行未改动8318328338348358368378388398408418428438442 行未改动84784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787816 行未改动8958968978988999009019029039049054 行未改动9109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103411 行未改动1046104710481049105010511052105310544 行未改动105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411352 行未改动11381139114011411142114311441145114611471148114911502 行未改动1153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011913 行未改动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><inputtype="text"id="student-name-input"requiredminlength="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><buttontype="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><textareaid="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',description: '全选文本 (Ctrl + A)',action: 'selectAll',successMsg: '已成功全选文本!'},{key: 'c',modifier: 'ctrl',description: '复制选中的文本 (Ctrl + C)',action: 'copy',successMsg: '已成功复制文本!'},{key: 'v',modifier: 'ctrl',description: '粘贴复制的文本 (Ctrl + V)',action: 'paste',successMsg: '已成功粘贴文本!'},{key: 'x',modifier: 'ctrl',description: '剪切选中的文本 (Ctrl + X)',action: 'cut',successMsg: '已成功剪切文本!'},{key: 'z',modifier: 'ctrl',description: '撤销上一步操作 (Ctrl + Z)',action: 'undo',successMsg: '已成功撤销操作!'},{key: 'f',modifier: 'ctrl',description: '查找文本内容 (Ctrl + F)',action: 'find',successMsg: '已成功打开查找功能!'},{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 = '';// 拆分文本为单个字符并添加到DOMfor (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? 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? Math.round((correctChars / typedChars) * 100): 0;// 计算每分钟字数 (WPM)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? Math.round((correctChars / typedChars) * 100): 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 行未改动8 行未改动9101112131415161711 行未改动2930313233343536379 行未改动47484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141157 行未改动12312412512612712812913013110 行未改动1421431441451461471481491501511521531541551561571581591601611621631642 行未改动1671681691701711721731741751761777 行未改动18518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022111 行未改动2332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063075 行未改动3133143153163173183193203212 行未改动3243253263273283293303313323333343353363373388 行未改动3473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903914 行未改动39639739839940040140240340440540640740840941041141241341441541641741841942042142213 行未改动43643743843944044144244344417 行未改动46246346446546646746846947018 行未改动48949049149249349449549649724 行未改动52252352452552652752852953015 行未改动5465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066075 行未改动6136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896908 行未改动69970070170270370470570670715 行未改动7237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248255 行未改动8318328338348358368378388398408418428438442 行未改动84784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787816 行未改动8958968978988999009019029039049054 行未改动9109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103411 行未改动1046104710481049105010511052105310544 行未改动105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411352 行未改动11381139114011411142114311441145114611471148114911502 行未改动1153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011913 行未改动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><inputtype="text"id="student-name-input"requiredminlength="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><buttontype="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><textareaid="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',description: '全选文本 (Ctrl + A)',action: 'selectAll',successMsg: '已成功全选文本!'},{key: 'c',modifier: 'ctrl',description: '复制选中的文本 (Ctrl + C)',action: 'copy',successMsg: '已成功复制文本!'},{key: 'v',modifier: 'ctrl',description: '粘贴复制的文本 (Ctrl + V)',action: 'paste',successMsg: '已成功粘贴文本!'},{key: 'x',modifier: 'ctrl',description: '剪切选中的文本 (Ctrl + X)',action: 'cut',successMsg: '已成功剪切文本!'},{key: 'z',modifier: 'ctrl',description: '撤销上一步操作 (Ctrl + Z)',action: 'undo',successMsg: '已成功撤销操作!'},{key: 'f',modifier: 'ctrl',description: '查找文本内容 (Ctrl + F)',action: 'find',successMsg: '已成功打开查找功能!'},{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 = '';// 拆分文本为单个字符并添加到DOMfor (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? 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? Math.round((correctChars / typedChars) * 100): 0;// 计算每分钟字数 (WPM)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? Math.round((correctChars / typedChars) * 100): 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 行未改动