// ==UserScript== // @name 广开英语2 // @namespace http://tampermonkey.net/ // @version 5.1 // @description 自动填写英语试题答案并自动跳转下一页 // @author Your Name // @match *://course.ougd.cn/* // @grant none // ==/UserScript== (function() { 'use strict'; // 完整答案配置 - 包含所有题目 const answerConfig = { // 第一批试题答案 (1-20) "half an hour to walk": "B", "holiday next month": "A", "Mary tell you when": "D", "the last bus stop": "A", "ship.*photo": "A", "volunteers for a try": "C", "I can help you": "C", "The car.*Dan": "B", "handle of this suitcase": "C", "hear from you": "A", "made.*worse": "D", "angry with him": "A", "strict.*diet": "C", "should.*report": "A", "bill.*tip": "B", "visit to Jane": "A", "haven't heard from him": "D", "agree with me.*hands": "A", "spare time": "C", "included.*list": "A", // 第二批试题答案 (21-40) "everything in order": "A", "English for eight years": "A", "owned.*mistake": "D", "lives in his.*house": "A", "I'm.*ready": "B", "How long ago.*diet": "A", "sea was very.*this morning": "C", "Where did he.*parcel": "C", "I'm busy preparing": "A", "easy to pass the exam.": "C", "This medicine has": "C", "put.*forest fire": "C", "find.*name": "B", "sure.*cigarette": "A", "discover.*America": "B", "remains of an aeroplane": "A", "wind.*wire.*tree": "A", "got up very": "B", "throw.*cigarette": "D", "cause of the war": "C", "take care of the children.": "C", "don't speak.*French": "B", "children were at.*school": "D", // 第三批试题答案 (41-60) "That's.*what I wanted": "A", "could have been more annoying": "A", "that could have happend": "A", "persuaded him into.*that plan": "B", "We still have.*sugar": "A", "Government.*old are cared for": "C", "looked for my bag": "D", "It had begun before my sister left": "C", "busy.*butter and flour": "C", "recognized the voice": "C", "greatest men": "D", "best dress": "A", "paid him.*in": "C", "If Meimei.*surprise": "B", "remained.*while the manager talked": "A", "Stores.*profit": "C", "profited much.*your advice": "C", "went to New York.*little time": "B", "come here.*see you": "C", "Do not interrupt him": "C", "volunteers to help the old?": "C", "changed.*new dress": "B", // 第四批试题答案 (61-80) "marched.*room": "A", "walked.*in the room": "A", "policemen": "A", "stood.*attention": "B", "enough.*skirt": "A", "How long.*this book": "C", "call me as soon as": "D", "examining.*since yesterday": "B", "clean record": "A", "unfair voting in public places. ": "B", "difficult to stay away from TV. ": "A", "Helen.*voice": "C", "friends of ours": "B", "most annoying thing": "A", "sorry.*so much time": "A", "believed.*Australia": "B", "intended.*him": "C", "claimed.*stolen": "C", "washed away.*floods": "B", "at home": "D", "travelling.*easy": "C", "workers.*strike": "C", // 第五批试题答案 (81-90) "While.*college": "A", "acted as if.*result": "C", "If.*possible": "B", "We still have.*salt": "A", "organization.*old": "C", "Great Exhibition.*1851": "A", "hung up.*receiver": "C", "only passenger.*more": "B", "two brothers.*other": "A", "due.*bad weather": "A", // 新发现的题目答案 - 第二批试卷 "examining the ground.*yesterday": "B", "has a.*record": "A", "clean record": "A", "Helen.*voice": "C", "Helen Bates": "C", "sorry to.*time": "A", "taken up.*time": "A", "claimed.*stolen": "C", "washed away.*floods": "B", "at home": "D", // 新发现的题目答案 - 第三批试卷 "recognized the voice": "C", "put.*forest fire": "C", "put out.*fire": "C", "discover.*America": "B", "remains of an aeroplane": "A", "throw.*cigarette": "D", "cause of the war": "C", "don't speak.*French": "B", "annoying. It was": "A", "spare time": "B", // 需要手动匹配的题目 - 现在内置到配置中 "Whose voice.*Helen": "A", // 第11题 Bates "Helen.*Bates": "C", "He.*stolen.*wallet": "C", // 第17题 claimed "Tom.*stolen.*wallet": "C", "She was.*home": "D", // 第19题 at "home.*morning": "D", "don't speak.*French": "B", // 第20题 much "don't speak.*French": "B", "French.*much": "B", // 其他题目答案 "relieved.*passed the exam": "B", "to.*extent": "C", "helped me.*extent": "C", "some.*extent": "C", "certain extent": "C", "has just.*up the receiver": "C", "just.*up the receiver": "C", "up the receiver": "C", "receiver.*hang": "C", "receiver.*hung": "C", "She has just": "C", // 额外匹配规则(提高匹配成功率) "on strike": "C", "at college": "A", "the old": "C", "In 1851": "A", "hang up": "C", "any more": "B", "the other": "A", "due to": "A", "was relieved": "B", "to some extent": "C", "to a certain extent": "C", "since yesterday": "B", "have taken up": "A", "wash away": "B", "washed away": "B", "put out": "C", "throw away": "D", "much French": "B", "spare time": "B", "Bates": "C", "claimed": "C", "at home": "D" }; // 面板状态管理 let panelState = { isDragging: false, dragOffset: { x: 0, y: 0 }, scale: 1, position: { x: 20, y: 20 } }; // 自动填写答案 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 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 = `
英语自动答题助手 v5.1
状态: 等待操作
已配置: ${Object.keys(answerConfig).length} 道题
缩放: ${Math.round(panelState.scale * 100)}% | 拖动标题移动
按F12查看详细日志
`; document.body.appendChild(panel); // 添加拖动功能 makePanelDraggable(panel); // 添加按钮事件 document.getElementById('autoFillBtn').addEventListener('click', function() { const filledCount = autoFillAnswers(); const statusText = document.getElementById('statusText'); statusText.textContent = `已填写 ${filledCount} 道题`; statusText.style.color = filledCount > 0 ? '#4caf50' : '#f44336'; }); document.getElementById('nextPageBtn').addEventListener('click', function() { document.getElementById('statusText').textContent = '正在跳转...'; document.getElementById('statusText').style.color = '#2196f3'; setTimeout(goToNextPage, 500); }); document.getElementById('debugBtn').addEventListener('click', function() { console.log("=== 调试信息 ==="); const inputs = document.querySelectorAll('input[id^="q"][id$="answer"]'); console.log(`找到 ${inputs.length} 个输入框`); inputs.forEach((input, index) => { console.log(`输入框 ${index + 1}:`, input); console.log(`ID: ${input.id}, 值: ${input.value}`); const text = findQuestionText(input); console.log(`题目文本: ${text}`); console.log(`清理后文本: ${text.replace(/回答/g, '').replace(/\s+/g, ' ').trim()}`); }); }); // 添加缩放按钮事件 panel.querySelector('.zoom-in').addEventListener('click', function(e) { e.stopPropagation(); zoomPanel('in'); updateScaleDisplay(); }); panel.querySelector('.zoom-out').addEventListener('click', function(e) { e.stopPropagation(); zoomPanel('out'); updateScaleDisplay(); }); // 更新缩放显示 function updateScaleDisplay() { const scaleText = panel.querySelector('div:last-child div:nth-child(3)'); if (scaleText) { scaleText.textContent = `缩放: ${Math.round(panelState.scale * 100)}% | 拖动标题移动`; } } } // 显示通知 function showNotification(message, type = 'info') { const notification = document.createElement('div'); notification.style.cssText = ` position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: ${type === 'success' ? '#4caf50' : type === 'error' ? '#f44336' : '#2196f3'}; color: white; padding: 15px 20px; border-radius: 5px; z-index: 10001; font-family: Arial, sans-serif; font-size: 14px; box-shadow: 0 4px 12px rgba(0,0,0,0.3); `; notification.textContent = message; document.body.appendChild(notification); setTimeout(() => { notification.remove(); }, 3000); } // 初始化函数 function init() { console.log("英语试题自动答题助手 v5.1 已加载"); console.log(`已配置 ${Object.keys(answerConfig).length} 道题的答案`); // 创建控制面板 createControlPanel(); // 自动填写答案 setTimeout(() => { const filledCount = autoFillAnswers(); if (filledCount > 0) { showNotification(`已自动填写 ${filledCount} 道题`, 'success'); } }, 2000); } // 页面加载完成后初始化 if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); } })();