// ==UserScript== // @name 广开大学英语1(专)4-5 // @namespace http://tampermonkey.net/ // @version 5.20 // @description 自动填写英语试题答案并自动跳转下一页 // @author XCJY // @match *://course.ougd.cn/* // @grant none // ==/UserScript== (function() { 'use strict'; // 完整答案配置 - 包含所有题目 const answerConfig = { "Mrs. Browers told her children": "A", "I was wet all through": "A", "an old musical instrument": "D", "A new road.*outside my house": "A", "Open your exercise books": "A", "When they have.*new building.*spoil the view": "C", "They.*the fire and crept": "A", "I.*my coat and left the house": "D", "I can't.*him any longer": "A", "The tables in the office.*wood": "C", "The only games.*I play": "B", "You can't remember his name": "A", "Do you.*that cats eat grass": "A", "The man.*I served was wearing": "D", "I've been a doctor.*1989": "B", "This bus is going.*slowly": "A", "Did he.*you a gift last Sunday": "D", "The secretary.*that she has stolen": "C", "I.*the picture last month": "A", "It can land on a.*field": "B", "Fans are necessary in.*hot country": "A", "Which river is.*shortest, the Nile": "C", "crossed the ocean on.*raft": "A", "Why is America called.*United States": "C", "Tell Lily to call me as soon as she": "A", "He has.*for three days": "C", "You have failed two tests. You’d better": "D", "There isn't.*water in the bottle": "A", "George left the house and was soon.*sight": "A", "The story was.*interesting that I told it": "B", "fast the boy ran": "A", "They saved the girl.*the fire": "A", "I.*the CDs to you if I have time tomorrow": "B", "I've a lot of.*to do during the holiday": "A", "He.*when the door opened and the manager": "A", "day, a woman came to his house": "B", "The thief is.*arrest now": "A", "I made the model better.*you did": "A", "I have sent you as much money as": "A", "The temptation.*is strong for him": "A" }; // 面板状态管理 let panelState = { isDragging: false, dragOffset: { x: 0, y: 0 }, scale: 1, position: { x: 20, y: 20 } }; // 自动跳转定时器 let autoJumpTimer = null; let autoJumpCountdown = 0; // 自动填写答案 function autoFillAnswers() { console.log("=== 开始自动填写答案 ==="); let filledCount = 0; // 查找所有题目输入框 const answerInputs = document.querySelectorAll('input[id^="q"][id$="answer"]'); console.log(`找到 ${answerInputs.length} 个答案输入框`); answerInputs.forEach((input, index) => { const questionId = input.id; console.log(`\n处理第 ${index + 1} 题: ${questionId}`); const questionText = findQuestionText(input); console.log(`题目文本: ${questionText ? questionText.substring(0, 100) + '...' : '未找到'}`); if (questionText) { const answer = findAnswer(questionText); console.log(`匹配到的答案: ${answer}`); if (answer) { input.value = answer; // 触发事件以确保表单检测到变化 const events = ['input', 'change', 'blur']; events.forEach(eventType => { input.dispatchEvent(new Event(eventType, { bubbles: true })); }); filledCount++; markAsFilled(input); console.log(`✅ 题目 ${questionId}: 填写答案 ${answer}`); } else { console.log(`❌ 题目 ${questionId}: 未找到匹配答案`); } } }); console.log(`=== 完成 ${filledCount} 道题的自动填写 ===`); // 显示完成通知 if (filledCount > 0) { showNotification(`已自动填写 ${filledCount} 道题`, 'success'); } return filledCount; } // 查找题目文本 function findQuestionText(inputElement) { // 方法1: 查找最近的.formulation容器 let container = inputElement.closest('.formulation'); if (container) { const qtextElement = container.querySelector('.qtext'); if (qtextElement) { const text = qtextElement.textContent || ''; // 移除"回答"并清理多余空格 return text.replace(/回答/g, '').replace(/\s+/g, ' ').trim(); } } // 方法2: 查找.que容器 const parentFormulation = inputElement.closest('.que'); if (parentFormulation) { const qtextElements = parentFormulation.querySelectorAll('.qtext, p'); let fullText = ''; qtextElements.forEach(el => { const text = el.textContent || ''; if (text.trim() && !text.includes('答案:')) { fullText += text.replace(/回答/g, '').replace(/\s+/g, ' ') + ' '; } }); return fullText.trim(); } return ''; } // 根据题目文本查找答案 function findAnswer(questionText) { // 清理题目文本 const cleanText = questionText.replace(/回答/g, '').replace(/\s+/g, ' ').trim(); console.log(`清理后的文本: "${cleanText}"`); for (const [keyword, answer] of Object.entries(answerConfig)) { const regex = new RegExp(keyword, 'i'); if (regex.test(cleanText)) { console.log(`匹配成功! 关键词: "${keyword}", 答案: ${answer}`); return answer; } } return null; } // 标记已填写的题目 function markAsFilled(inputElement) { inputElement.style.backgroundColor = '#e8f5e9'; inputElement.style.borderColor = '#4caf50'; inputElement.style.fontWeight = 'bold'; inputElement.style.color = '#2e7d32'; } // 自动跳转到下一页 function goToNextPage() { const nextButton = document.querySelector('input[name="next"]'); if (nextButton) { console.log("找到下一页按钮,正在跳转..."); nextButton.click(); } else { console.log("未找到下一页按钮"); // 尝试查找提交按钮 const submitButton = document.querySelector('input[type="submit"]'); if (submitButton) { console.log("找到提交按钮,尝试点击..."); submitButton.click(); } } } // 开始自动跳转 function startAutoJump() { // 清除现有的定时器 if (autoJumpTimer) { clearInterval(autoJumpTimer); } autoJumpCountdown = 5; updateAutoJumpStatus(); autoJumpTimer = setInterval(() => { autoJumpCountdown--; updateAutoJumpStatus(); if (autoJumpCountdown <= 0) { clearInterval(autoJumpTimer); console.log("自动跳转时间到,正在跳转..."); goToNextPage(); } }, 1000); } // 停止自动跳转 function stopAutoJump() { if (autoJumpTimer) { clearInterval(autoJumpTimer); autoJumpTimer = null; } autoJumpCountdown = 0; updateAutoJumpStatus(); } // 更新自动跳转状态显示 function updateAutoJumpStatus() { const statusText = document.getElementById('statusText'); const autoJumpBtn = document.getElementById('autoJumpBtn'); if (autoJumpTimer) { statusText.textContent = `${autoJumpCountdown}秒后自动跳转`; statusText.style.color = '#2196f3'; autoJumpBtn.textContent = '停止自动跳转'; autoJumpBtn.style.background = '#f44336'; } else { statusText.textContent = '等待操作'; statusText.style.color = '#666'; autoJumpBtn.textContent = '开始自动跳转'; autoJumpBtn.style.background = '#2196f3'; } } // 面板拖动功能 function makePanelDraggable(panel) { const header = panel.querySelector('.panel-header'); header.addEventListener('mousedown', startDrag); function startDrag(e) { if (e.target.closest('.panel-controls')) return; // 防止控制按钮触发拖动 panelState.isDragging = true; const rect = panel.getBoundingClientRect(); panelState.dragOffset.x = e.clientX - rect.left; panelState.dragOffset.y = e.clientY - rect.top; document.addEventListener('mousemove', onDrag); document.addEventListener('mouseup', stopDrag); panel.style.cursor = 'grabbing'; e.preventDefault(); } function onDrag(e) { if (!panelState.isDragging) return; panelState.position.x = e.clientX - panelState.dragOffset.x; panelState.position.y = e.clientY - panelState.dragOffset.y; updatePanelPosition(); } function stopDrag() { panelState.isDragging = false; document.removeEventListener('mousemove', onDrag); document.removeEventListener('mouseup', stopDrag); panel.style.cursor = 'grab'; // 保存位置到本地存储 savePanelState(); } // 恢复拖动光标 header.style.cursor = 'grab'; } // 更新面板位置 function updatePanelPosition() { const panel = document.getElementById('autoAnswerPanel'); if (panel) { panel.style.left = panelState.position.x + 'px'; panel.style.top = panelState.position.y + 'px'; } } // 更新面板缩放 function updatePanelScale() { const panel = document.getElementById('autoAnswerPanel'); if (panel) { panel.style.transform = `scale(${panelState.scale})`; panel.style.transformOrigin = 'top left'; } } // 缩放面板 function zoomPanel(direction) { if (direction === 'in') { panelState.scale = Math.min(panelState.scale + 0.1, 1.5); } else { panelState.scale = Math.max(panelState.scale - 0.1, 0.5); } updatePanelScale(); savePanelState(); } // 保存面板状态 function savePanelState() { const state = { position: panelState.position, scale: panelState.scale }; localStorage.setItem('englishAnswerPanelState', JSON.stringify(state)); } // 加载面板状态 function loadPanelState() { const saved = localStorage.getItem('englishAnswerPanelState'); if (saved) { try { const state = JSON.parse(saved); panelState.position = state.position || panelState.position; panelState.scale = state.scale || panelState.scale; } catch (e) { console.log('加载面板状态失败:', e); } } } // 创建控制面板 function createControlPanel() { // 移除已存在的控制面板 const existingPanel = document.getElementById('autoAnswerPanel'); if (existingPanel) { existingPanel.remove(); } // 加载保存的状态 loadPanelState(); const panel = document.createElement('div'); panel.id = 'autoAnswerPanel'; panel.style.cssText = ` position: fixed; left: ${panelState.position.x}px; top: ${panelState.position.y}px; background: #fff; border: 2px solid #4caf50; border-radius: 8px; padding: 15px; box-shadow: 0 4px 12px rgba(0,0,0,0.15); z-index: 10000; font-family: Arial, sans-serif; min-width: 250px; transform: scale(${panelState.scale}); transform-origin: top left; transition: transform 0.2s ease; user-select: none; `; panel.innerHTML = `