// ==UserScript==
// @name U助手-AI版
// @namespace http://tampermonkey.net/
// @version 3.0.6
// @description 支持题库模式和ai模式解决U校园AI版的刷题烦恼,集成自动录音功能,挂机模式支持自动录音
// @author 恶搞之家
// @match *://ucontent.unipus.cn/*
// @match *://birdflock.unipus.cn/*
// @grant GM_xmlhttpRequest
// @connect kimi.moonshot.cn
// @connect eghome.9vvn.com
// @require https://cdn.jsdelivr.net/gh/davidshimjs/qrcodejs/qrcode.min.js
// ==/UserScript==
const API_CONFIG = {
BASE_URL: "https://eghome.9vvn.com/api",
ENDPOINTS: {
SAVE_TRUTH: "/save-truth",
POINTS: "/points",
KIMI_CHAT: "/kimi",
SOLVE: "/solve-question",
SUBMIT_ORDER: "/submit-point-order",
PAY_REQUEST: "/payment-request",
GET_ANSWERS: "/get-answers",
INJECT: "/inject"
}
};
const getApiUrl = (endpoint) => `${API_CONFIG.BASE_URL}${endpoint}`;
const SubmitInterceptor = {
CACHE_KEY: '__UCAMPUS_ANSWER_CACHE__',
init() {
console.log('[拦截器] 初始化网络监听 (支持多Section)...');
this.setupHook();
},
showToast(msg) {
const div = document.createElement('div');
div.innerHTML = msg;
div.style.cssText = `position:fixed;top:60px;left:50%;transform:translateX(-50%);padding:8px 16px;border-radius:4px;color:white;font-weight:bold;font-size:13px;z-index:999999;background:#52c41a;box-shadow:0 4px 12px rgba(0,0,0,0.3);transition:opacity 0.5s;pointer-events:none;`;
document.body.appendChild(div);
setTimeout(() => { div.style.opacity='0'; setTimeout(()=>div.remove(), 500); }, 3000);
},
fillRecursively(targetNode, answerQueue) {
let count = 0;
if (targetNode.children && Array.isArray(targetNode.children)) {
for (const child of targetNode.children) {
count += this.fillRecursively(child, answerQueue);
}
}
else if (targetNode.hasOwnProperty('value')) {
const standard = answerQueue.shift();
if (standard) {
let val = standard.value || standard.answer || standard.answers;
if (val) {
if (!Array.isArray(val)) val = [val];
targetNode.value = val;
count++;
}
}
}
return count;
},
mergeAnswers(payloadStr, answerData) {
try {
const payload = JSON.parse(payloadStr);
let truthObj = answerData;
if (typeof truthObj === 'string') {
try { truthObj = JSON.parse(truthObj); } catch(e) {}
}
if (!truthObj || !truthObj.children) return null;
let answerQueue = JSON.parse(JSON.stringify(truthObj.children));
if (!payload.quesDatas || payload.quesDatas.length === 0) return null;
let totalFilled = 0;
for (let i = 0; i < payload.quesDatas.length; i++) {
const section = payload.quesDatas[i];
if (!section.answer) continue;
let targetAnswerObj = JSON.parse(section.answer);
const filledInThisSection = this.fillRecursively(targetAnswerObj, answerQueue);
totalFilled += filledInThisSection;
if (filledInThisSection > 0) {
section.answer = JSON.stringify(targetAnswerObj);
}
}
if (payload.usedTime !== undefined) {
payload.usedTime = Math.floor(Math.random() * (120 - 60 + 1)) + 60;
}
return { newJson: JSON.stringify(payload), count: totalFilled };
} catch (e) {
console.error('[拦截器] 合并错误:', e);
return null;
}
},
setupHook() {
const XHR = unsafeWindow.XMLHttpRequest;
const originalXHROpen = XHR.prototype.open;
const originalXHRSend = XHR.prototype.send;
const _this = this;
XHR.prototype.open = function(method, url) {
this._method = method;
this._url = url;
originalXHROpen.apply(this, arguments);
};
XHR.prototype.send = function(data) {
const xhr = this;
if (this._method === 'POST' && this._url && this._url.includes('/course/api/v3/newExploration/submit')) {
const cachedAnswer = unsafeWindow[_this.CACHE_KEY];
if (cachedAnswer && typeof data === 'string') {
const result = _this.mergeAnswers(data, cachedAnswer);
if (result) {
_this.showToast(`🚀 答案自动修正成功 (${result.count}空)`);
originalXHRSend.call(xhr, result.newJson);
return;
}
}
}
originalXHRSend.call(this, data);
};
}
};
let loadedQuestionBank = null;
let currentTopicUsedAnswers = new Set();
let lastActiveTopicName = '';
let multiPageMode = {
isActive: false,
exerciseId: null,
pageIndex: 0,
totalAnswers: [],
lastUrl: ''
};
let recordedAudioBlob = null;
let recordedAudioUrl = null;
let currentRecordButton = null;
let currentQuestionContainer = null;
const audioCache = new Map();
const audioBlobCache = new Map();
window.__recordDuration = 3;
let autoRefreshInterval = null;
let autoRefreshEnabled = false;
window.__refreshInterval = 30;
window.isAutoModeRunning = false;
window.__refreshAfterPopupBlock = false;
window.initiatePayFromScript = function(amount, buyType = 'ai_points') {
const uid = localStorage.getItem('userId');
if (!uid) {
alert('获取用户信息失败,请刷新页面后重试');
return;
}
console.log(`🚀 准备发起支付:金额 ${amount}, 类型 ${buyType}`);
const form = document.createElement('form');
form.action = 'https://eghome.9vvn.com/api/points/create-payment-v2';
form.method = 'POST';
form.target = '_blank';
const params = {
userId: uid,
amount: amount,
buyType: buyType
};
for (const key in params) {
const input = document.createElement('input');
input.type = 'hidden';
input.name = key;
input.value = params[key];
form.appendChild(input);
}
document.body.appendChild(form);
form.submit();
setTimeout(() => form.remove(), 1000);
const toast = document.createElement('div');
toast.innerHTML = '✨ 正在打开支付窗口...
支付完成后积分将自动到账';
toast.style.cssText = 'position:fixed;top:20%;left:50%;transform:translateX(-50%);background:rgba(0,0,0,0.8);color:white;padding:15px 25px;border-radius:10px;z-index:100000;text-align:center;font-size:14px;line-height:1.5;';
document.body.appendChild(toast);
setTimeout(() => toast.remove(), 3000);
};
(function setupQuestionInterceptor() {
'use strict';
console.log('🔧 V2脚本: 正在初始化题目数据拦截器...');
const originalXHROpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(method, url) {
this._interceptUrl = url;
this._interceptMethod = method;
originalXHROpen.apply(this, arguments);
};
const originalXHRSend = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.send = function(data) {
const currentXHR = this;
const originalOnReadyStateChange = this.onreadystatechange;
this.onreadystatechange = function() {
if (currentXHR.readyState === 4 && currentXHR.status === 200) {
try {
const responseJson = JSON.parse(currentXHR.responseText);
if (responseJson && responseJson.code === 0 && responseJson.content && responseJson.k) {
if (responseJson.content.startsWith && responseJson.content.startsWith('unipus.')) {
window.__interceptedQuestionData = {
encryptedContent: responseJson.content,
decryptionKey: responseJson.k,
url: currentXHR._interceptUrl,
timestamp: Date.now()
};
window.dispatchEvent(new CustomEvent('questionDataIntercepted', {
detail: window.__interceptedQuestionData
}));
}
}
} catch (e) {
}
}
if (originalOnReadyStateChange) {
originalOnReadyStateChange.apply(currentXHR, arguments);
}
};
originalXHRSend.apply(this, arguments);
};
const originalFetch = window.fetch;
window.fetch = function(...args) {
const [resource] = args;
let url = '';
if (typeof resource === 'string') {
url = resource;
} else if (resource instanceof Request) {
url = resource.url;
}
return originalFetch.apply(this, args).then(async response => {
const clonedResponse = response.clone();
try {
const responseJson = await clonedResponse.json();
if (responseJson && responseJson.code === 0 && responseJson.content && responseJson.k) {
if (responseJson.content.startsWith && responseJson.content.startsWith('unipus.')) {
console.log('🎯 V2脚本 [Fetch]: 拦截到加密题目数据!');
console.log(' - URL:', url);
console.log(' - 密文长度:', responseJson.content.length);
console.log(' - 解密密钥:', responseJson.k);
window.__interceptedQuestionData = {
encryptedContent: responseJson.content,
decryptionKey: responseJson.k,
url: url,
timestamp: Date.now()
};
window.dispatchEvent(new CustomEvent('questionDataIntercepted', {
detail: window.__interceptedQuestionData
}));
}
}
} catch (e) {
}
return response;
});
};
console.log('✅ V2脚本: 题目数据拦截器已启动');
window.addEventListener('questionDataIntercepted', (e) => {
const data = e.detail;
console.log('📢 V2脚本: 收到题目数据拦截事件,已更新 __interceptedQuestionData');
});
})();
(function setupSubmitInterceptor() {
'use strict';
const SERVER_URL = getApiUrl(API_CONFIG.ENDPOINTS.SAVE_TRUTH);
function getPageKey() {
try {
let unitId = window.location.href.split('/').pop().split('?')[0];
let courseId = '';
const hash = window.location.hash;
const hashMatch = hash.match(/course-v2:[^+]+\+([^+]+)\+/);
if (hashMatch && hashMatch[1]) {
courseId = hashMatch[1];
} else {
const urlParams = new URLSearchParams(window.location.search);
courseId = urlParams.get('courseId') || urlParams.get('cid');
}
return courseId ? `${courseId}_${unitId}` : unitId;
} catch (e) {
return 'unknown_key';
}
}
function reportTruthToServer(responseText, sourceUrl) {
if (!responseText || !responseText.includes('unipus.')) return;
const urlKey = getPageKey();
console.log(`📤 [${sourceUrl}] 捕获数据, Key: ${urlKey}`);
GM_xmlhttpRequest({
method: 'POST',
url: SERVER_URL,
headers: { 'Content-Type': 'application/json' },
data: JSON.stringify({
rawResponse: responseText,
pageKey: urlKey
}),
onload: function(res) {
if (res.status === 200) console.log('✅');
}
});
}
const originalXHROpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(method, url) {
this._interceptUrl = url;
originalXHROpen.apply(this, arguments);
};
const originalXHRSend = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.send = function(data) {
const currentXHR = this;
const originalOnReadyStateChange = this.onreadystatechange;
this.onreadystatechange = function() {
if (currentXHR.readyState === 4 && currentXHR.status === 200) {
try {
if (currentXHR._interceptUrl && currentXHR._interceptUrl.includes('/course/api/v3/newExploration/submit')) {
reportTruthToServer(currentXHR.responseText, 'XHR');
}
} catch (e) {}
}
if (originalOnReadyStateChange) originalOnReadyStateChange.apply(currentXHR, arguments);
};
originalXHRSend.apply(this, arguments);
};
const originalFetch = window.fetch;
window.fetch = function(...args) {
let url = args[0] instanceof Request ? args[0].url : args[0];
return originalFetch.apply(this, args).then(async response => {
const cloned = response.clone();
try {
if (url && url.includes('/course/api/v3/newExploration/submit')) {
const text = await cloned.text();
reportTruthToServer(text, 'Fetch');
}
} catch (e) {}
return response;
});
};
console.log('✅ 拦截器就绪');
})();
const POINTS_API_ENDPOINT = getApiUrl(API_CONFIG.ENDPOINTS.POINTS);
const POINTS_PER_QUESTION = 2;
let userPoints = 0;
let userId = localStorage.getItem('userId');
class SimpleKeepAliveSystem {
constructor() {
this.isRunning = false;
this.domTimer = null;
this.networkTimer = null;
this.wsTimer = null;
this.dialogObserver = null;
this.wsConnections = [];
this.config = {
domInterval: 30000,
networkInterval: 45000,
wsInterval: 35000
};
this.setupWebSocketHook();
this.setupDialogObserver();
}
start() {
if (this.isRunning) return;
this.isRunning = true;
console.log('[保活系统] 启动');
this.domTimer = setInterval(() => {
this.simulateUserActivity();
}, this.config.domInterval + Math.random() * 3000);
this.networkTimer = setInterval(() => {
this.sendNetworkPing();
}, this.config.networkInterval + Math.random() * 5000);
this.wsTimer = setInterval(() => {
this.sendWebSocketPing();
}, this.config.wsInterval + Math.random() * 3000);
this.updateButton();
}
stop() {
if (!this.isRunning) return;
this.isRunning = false;
console.log('[保活系统] 停止');
if (this.domTimer) {
clearInterval(this.domTimer);
this.domTimer = null;
}
if (this.networkTimer) {
clearInterval(this.networkTimer);
this.networkTimer = null;
}
if (this.wsTimer) {
clearInterval(this.wsTimer);
this.wsTimer = null;
}
this.updateButton();
}
toggle() {
if (this.isRunning) {
this.stop();
} else {
this.start();
}
}
simulateUserActivity() {
try {
const activities = ['mousemove', 'scroll', 'keydown'];
const activity = activities[Math.floor(Math.random() * activities.length)];
switch (activity) {
case 'mousemove':
const mouseEvent = new MouseEvent('mousemove', {
bubbles: true,
clientX: Math.random() * window.innerWidth,
clientY: Math.random() * window.innerHeight
});
document.dispatchEvent(mouseEvent);
break;
case 'scroll':
window.scrollBy(0, Math.random() * 10 - 5);
break;
case 'keydown':
const keyEvent = new KeyboardEvent('keydown', {
bubbles: true,
key: 'Control'
});
document.dispatchEvent(keyEvent);
break;
}
console.log('[保活系统] DOM活动:', activity);
} catch (error) {
console.error('[保活系统] DOM活动失败:', error);
}
}
sendNetworkPing() {
try {
fetch(window.location.href, { method: 'HEAD' })
.then(() => console.log('[保活系统] 网络ping成功'))
.catch(error => console.error('[保活系统] 网络ping失败:', error));
} catch (error) {
console.error('[保活系统] 网络ping异常:', error);
}
}
sendWebSocketPing() {
try {
this.wsConnections.forEach(ws => {
if (ws.readyState === WebSocket.OPEN) {
ws.send('2');
console.log('[保活系统] WebSocket ping发送');
}
});
} catch (error) {
console.error('[保活系统] WebSocket ping失败:', error);
}
}
setupWebSocketHook() {
const originalWebSocket = window.WebSocket;
const self = this;
window.WebSocket = function(...args) {
const ws = new originalWebSocket(...args);
self.wsConnections.push(ws);
ws.addEventListener('close', () => {
const index = self.wsConnections.indexOf(ws);
if (index > -1) {
self.wsConnections.splice(index, 1);
}
});
return ws;
};
}
setupDialogObserver() {
this.dialogObserver = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
mutation.addedNodes.forEach((node) => {
if (node.nodeType === Node.ELEMENT_NODE) {
const dialogKeywords = ['长时间未操作', '继续使用', '继续学习', '超时', 'timeout', '会话已结束'];
const buttonKeywords = ['确定', '继续', 'OK'];
let isDialog = false;
const pTags = node.querySelectorAll ? node.querySelectorAll('p') : [];
for (const p of pTags) {
const pText = p.textContent || '';
if (dialogKeywords.some(keyword => pText.includes(keyword))) {
isDialog = true;
break;
}
}
if (!isDialog) {
const nodeText = node.textContent || '';
if (dialogKeywords.some(keyword => nodeText.includes(keyword))) {
isDialog = true;
}
}
if (isDialog) {
console.log('[保活系统] 检测到超时对话框,准备自动处理...');
setTimeout(() => {
const buttons = node.querySelectorAll('button, .btn, [role="button"]');
for (const btn of buttons) {
const btnText = btn.textContent || '';
if (buttonKeywords.some(keyword => btnText.includes(keyword))) {
console.log(`[保活系统] 找到匹配按钮: "${btnText}",尝试点击。`);
btn.click();
return;
}
}
}, 300);
}
}
});
});
});
if (document.body) {
this.dialogObserver.observe(document.body, {
childList: true,
subtree: true
});
}
}
updateButton() {
const checkbox = document.getElementById('keepAliveToggle');
if (checkbox) {
checkbox.checked = this.isRunning;
}
}
}
const SkipManager = {
storageKey: 'u-helper-skipped-chapters',
getSkippedList() {
try {
return JSON.parse(localStorage.getItem(this.storageKey) || '[]');
} catch (e) {
return [];
}
},
saveSkippedList(list) {
localStorage.setItem(this.storageKey, JSON.stringify(list));
},
shouldSkip(chapterName) {
if (!chapterName) return false;
const list = this.getSkippedList();
return list.some(skipItem => chapterName.includes(skipItem) || skipItem.includes(chapterName));
},
initPanel(contentContainer) {
const controlRow = document.createElement('div');
controlRow.style.cssText = 'display:flex; justify-content:space-between; align-items:center; margin-bottom:10px;';
const tip = document.createElement('span');
tip.textContent = '勾选以跳过:';
tip.style.cssText = 'font-size:13px; color:#666; font-weight:600;';
const refreshBtn = document.createElement('button');
refreshBtn.innerHTML = '🔄 刷新目录';
refreshBtn.className = 'u-helper-btn u-helper-btn-secondary';
refreshBtn.style.cssText = 'padding: 4px 10px; font-size: 12px; width: auto;';
controlRow.appendChild(tip);
controlRow.appendChild(refreshBtn);
const listContainer = document.createElement('div');
listContainer.style.cssText = `
max-height: 200px;
overflow-y: auto;
border: 1px solid rgba(0,0,0,0.1);
border-radius: 6px;
padding: 8px;
background: rgba(255,255,255,0.5);
`;
const renderList = () => {
listContainer.innerHTML = '';
const savedList = this.getSkippedList();
const allItems = Array.from(document.querySelectorAll(
'.pc-menu-node-name, div[data-role="micro"], div[data-role="node"], ' +
'.menu--u3menu-3Xu4h li .name, li.unit .name, li.section .name, li.group .name'
));
const seen = new Set();
let count = 0;
allItems.forEach(item => {
let nameEl = item.querySelector('.pc-menu-node-name') ||
item.querySelector('i') ||
item.querySelector('a') ||
item;
let name = nameEl.textContent.trim().split('\n')[0];
if (!name || name.length < 2 || seen.has(name)) return;
seen.add(name);
count++;
const row = document.createElement('label');
row.style.cssText = 'display:flex; align-items:center; margin-bottom:6px; cursor:pointer; font-size:13px; user-select:none;';
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.checked = savedList.includes(name);
checkbox.style.marginRight = '8px';
checkbox.onchange = (e) => {
const currentList = this.getSkippedList();
if (e.target.checked) {
if (!currentList.includes(name)) currentList.push(name);
} else {
const idx = currentList.indexOf(name);
if (idx > -1) currentList.splice(idx, 1);
}
this.saveSkippedList(currentList);
};
const text = document.createElement('span');
text.textContent = name;
text.style.color = checkbox.checked ? '#ff4d4f' : '#333';
checkbox.addEventListener('change', () => {
text.style.color = checkbox.checked ? '#ff4d4f' : '#333';
});
row.appendChild(checkbox);
row.appendChild(text);
listContainer.appendChild(row);
});
if (count === 0) {
listContainer.innerHTML = '
未检测到目录,请展开左侧菜单后点击刷新
';
}
};
refreshBtn.onclick = () => {
refreshBtn.textContent = '扫描中...';
renderList();
setTimeout(() => refreshBtn.innerHTML = '🔄 刷新目录', 500);
};
contentContainer.appendChild(controlRow);
contentContainer.appendChild(listContainer);
setTimeout(renderList, 1000);
}
};
const keepAliveSystem = new SimpleKeepAliveSystem();
async function refreshPoints() {
console.log('开始刷新积分...');
console.log('当前用户ID:', userId);
console.log('当前POINTS_API_ENDPOINT:', POINTS_API_ENDPOINT);
if (!userId) {
console.error('错误: 用户ID为空');
return false;
}
try {
console.log('发送请求到:', `${POINTS_API_ENDPOINT}/deduct`);
const response = await new Promise((resolve, reject) => {
GM_xmlhttpRequest({
method: 'POST',
url: `${POINTS_API_ENDPOINT}/deduct`,
headers: {
'Content-Type': 'application/json'
},
data: JSON.stringify({
userId: userId,
points: 0
}),
onload: function(response) {
console.log('收到响应:', response.responseText);
resolve(response);
},
onerror: function(error) {
console.error('请求失败:', error);
reject(error);
}
});
});
console.log('解析响应...');
const data = JSON.parse(response.responseText);
console.log('解析后的数据:', data);
if (data.success) {
const newPoints = data.remainingPoints || data.points || 0;
console.log('服务器返回的积分:', newPoints);
if (newPoints !== userPoints) {
console.log('积分发生变化:', userPoints, '->', newPoints);
userPoints = newPoints;
localStorage.setItem('userPoints', userPoints);
}
updatePointsDisplay();
console.log('积分更新完成');
return true;
} else {
console.error('服务器返回失败:', data.message || '未知错误');
return false;
}
} catch (error) {
console.error('刷新积分过程中出错:', error);
return false;
}
}
window.refreshPoints = refreshPoints;
window.updateUI = updateUI;
function updateUI() {
const currentPointsDisplay = document.getElementById('currentPointsDisplay');
if (currentPointsDisplay) {
currentPointsDisplay.textContent = userPoints;
}
const rechargeModal = document.getElementById('rechargeModal');
if (rechargeModal) {
const pointsInfo = rechargeModal.querySelector('p:nth-child(2)');
if (pointsInfo) {
pointsInfo.textContent = `当前积分:${userPoints}`;
}
}
console.log('UI已更新,当前积分:', userPoints);
if (window.updateHighScoreLockState) window.updateHighScoreLockState();
}
setInterval(refreshPoints, 30000);
setInterval(updateUI, 4000);
refreshPoints().then(() => {
console.log('初始化完成,当前积分:', userPoints);
updateUI();
});
if (!userId) {
userId = 'UID' + Date.now() + Math.random().toString(36).substr(2, 6);
localStorage.setItem('userId', userId);
}
function createPointsDisplay() {
updatePointsDisplay();
}
function updatePointsDisplay() {
const aiPointsDisplay = document.querySelector('.u-helper-section-content .points-display');
if (aiPointsDisplay) {
aiPointsDisplay.textContent = `当前积分: ${userPoints}`;
}
const rechargeModal = document.getElementById('rechargeModal');
if (rechargeModal) {
const pointsInfo = rechargeModal.querySelector('p:nth-child(2)');
if (pointsInfo) {
pointsInfo.textContent = `当前积分:${userPoints}`;
}
}
window.updateUI && window.updateUI();
console.log('积分显示已更新:', userPoints);
}
function showRechargeModal(amount = 10) {
const QR_CODE_4_9 = '';
const QR_CODE_9_9 = '';
const QR_CODE_24_9 ='';
const getQRCodeUrl = (amount) => {
const amountNum = parseFloat(amount);
console.log('选择收款码, 金额:', amountNum);
if(amountNum === 4.9) return QR_CODE_4_9;
if(amountNum === 9.9) return QR_CODE_9_9;
if(amountNum === 24.9) return QR_CODE_24_9;
return QR_CODE_4_9;
};
const existingModal = document.getElementById('rechargeModal');
if (existingModal) existingModal.remove();
if (!document.getElementById('u-recharge-scrollbar-style')) {
const style = document.createElement('style');
style.id = 'u-recharge-scrollbar-style';
style.textContent = `
.u-recharge-scroll::-webkit-scrollbar { width: 5px; }
.u-recharge-scroll::-webkit-scrollbar-track { background: transparent; }
.u-recharge-scroll::-webkit-scrollbar-thumb { background: #d9d9d9; border-radius: 10px; }
.u-recharge-scroll::-webkit-scrollbar-thumb:hover { background: #bfbfbf; }
`;
document.head.appendChild(style);
}
const modalHtml = `
`;
document.body.insertAdjacentHTML('beforeend', modalHtml);
setTimeout(() => {
const qrContainer = document.getElementById("uidQrcode");
if (qrContainer) {
qrContainer.innerHTML = '';
try {
new QRCode(qrContainer, {
text: userId,
width: 90,
height: 90,
colorDark: "#000000",
colorLight: "#ffffff",
correctLevel: QRCode.CorrectLevel.L
});
} catch (error) {
console.error('QR Code error:', error);
qrContainer.innerHTML = '加载失败';
}
}
const closeBtn = document.getElementById('closeModalBtn');
const checkBtn = document.getElementById('checkStatusBtn');
const modal = document.getElementById('rechargeModal');
if(closeBtn) {
closeBtn.onmouseover = () => closeBtn.style.background = '#f5f5f5';
closeBtn.onmouseout = () => closeBtn.style.background = 'white';
closeBtn.onclick = () => modal && modal.remove();
}
if(checkBtn) {
checkBtn.onmouseover = () => checkBtn.style.background = '#40a9ff';
checkBtn.onmouseout = () => checkBtn.style.background = '#1890ff';
checkBtn.onclick = async () => {
try {
checkBtn.disabled = true;
checkBtn.style.background = '#91d5ff';
checkBtn.textContent = '提交中...';
const pointsToAdd = amount === 4.9 ? 100 : amount === 9.9 ? 220 : 600;
GM_xmlhttpRequest({
method: 'POST',
url: getApiUrl(API_CONFIG.ENDPOINTS.SUBMIT_ORDER),
headers: { 'Content-Type': 'application/json' },
data: JSON.stringify({
uid: userId,
amount: amount,
points: pointsToAdd
}),
onload: function(res) {
const data = JSON.parse(res.responseText);
if (data.status === 'success' || data.status === 'info') {
alert('✅ 订单提交成功!\n审核后积分将自动到账。\n无需重复点击。');
const modal = document.getElementById('rechargeModal');
if(modal) modal.remove();
} else {
alert('提交失败: ' + data.message);
}
checkBtn.disabled = false;
checkBtn.style.background = '#1890ff';
checkBtn.textContent = '检查支付状态';
},
onerror: function(err) {
alert('网络错误,无法连接服务器');
checkBtn.disabled = false;
checkBtn.textContent = '检查支付状态';
}
});
} catch(error) {
console.error('提交订单失败:', error);
checkBtn.disabled = false;
}
};
}
}, 100);
const orderInfo = {
userId: userId,
amount: amount,
timestamp: Date.now(),
points: amount === 4.9 ? 100 : amount === 9.9 ? 220 : 600
};
localStorage.setItem('pendingOrder', JSON.stringify(orderInfo));
}
async function checkPaymentStatus() {
const success = await refreshPoints();
if (success) {
const modal = document.getElementById('rechargeModal');
if (modal) {
modal.remove();
}
alert('充值成功!积分已到账');
localStorage.removeItem('pendingOrder');
} else {
alert('管理员正在处理您的订单,请稍后再试!\n如超过10分钟未到账,请联系管理员并提供您的UID。');
}
}
async function checkAndDeductPoints() {
try {
console.log(`🔄 正在请求服务器扣除积分...`);
const response = await new Promise((resolve, reject) => {
GM_xmlhttpRequest({
method: 'POST',
url: `${POINTS_API_ENDPOINT}/deduct`,
headers: {
'Content-Type': 'application/json'
},
data: JSON.stringify({
userId: userId
}),
timeout: 10000,
onload: resolve,
onerror: reject,
ontimeout: () => reject(new Error('请求超时'))
});
});
const data = JSON.parse(response.responseText);
if (data.success) {
userPoints = data.remainingPoints;
localStorage.setItem('userPoints', userPoints);
updatePointsDisplay();
console.log(`✅ 积分扣除成功,扣除了 ${data.deducted || POINTS_PER_QUESTION} 积分,剩余: ${userPoints}`);
return true;
} else {
console.log(`❌ 服务器返回: ${data.message}`);
alert(data.message || '积分不足,请充值!');
showPointsPackages();
return false;
}
} catch (error) {
console.error('❌ 积分扣除请求失败:', error);
alert('积分系统异常,请稍后再试!');
return false;
}
}
const KIMI_API_ENDPOINT = getApiUrl(API_CONFIG.ENDPOINTS.KIMI_CHAT);
const AI_SOLVE_ENDPOINT = getApiUrl(API_CONFIG.ENDPOINTS.SOLVE);
let useKimiAI = localStorage.getItem('useKimiAI') === 'true';
let interceptedQuestionData = null;
async function initPointsSystem() {
createPointsDisplay();
window.showRechargeModal = showRechargeModal;
window.checkPaymentStatus = checkPaymentStatus;
try {
const response = await new Promise((resolve, reject) => {
GM_xmlhttpRequest({
method: 'POST',
url: `${POINTS_API_ENDPOINT}/deduct`,
headers: {
'Content-Type': 'application/json'
},
data: JSON.stringify({
userId: userId,
points: 0
}),
onload: resolve,
onerror: reject
});
});
const data = JSON.parse(response.responseText);
if (data.success) {
userPoints = data.remainingPoints;
localStorage.setItem('userPoints', userPoints);
updatePointsDisplay();
}
} catch (error) {
console.error('获取积分失败:', error);
}
}
document.addEventListener('DOMContentLoaded', initPointsSystem);
function showPointsPackages() {
const packages = [
{
amount: '4.9',
title: '体验套餐',
points: '100',
times: '50',
gradient: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
accentColor: '#667eea'
},
{
amount: '9.9',
title: '进阶套餐',
points: '220',
times: '110',
bonus: '+20',
gradient: 'linear-gradient(135deg, #f093fb 0%, #f5576c 100%)',
accentColor: '#f5576c'
},
{
amount: '24.9',
title: '尊享套餐',
points: '600',
times: '300',
bonus: '+100',
gradient: 'linear-gradient(135deg, #4facfe 0%, #00f2fe 100%)',
accentColor: '#00f2fe'
}
];
const modalHtml = `
选择充值套餐
您的充值UID
${userId}
💡 点击即可复制,充值时请备注此UID
${packages.map((pkg, index) => `
${pkg.title}
约 ${pkg.times} 次AI答题${pkg.bonus ? ' · 赠送' + pkg.bonus + '积分' : ''}
¥${pkg.amount}
${pkg.points}积分
`).join('')}
`;
document.body.insertAdjacentHTML('beforeend', modalHtml);
const options = document.querySelectorAll('.package-option');
options.forEach(option => {
const accent = option.querySelector('.pkg-accent');
option.addEventListener('mouseover', () => {
option.style.borderColor = '#cbd5e0';
option.style.transform = 'translateX(4px)';
option.style.boxShadow = '0 4px 12px rgba(0,0,0,0.08)';
accent.style.opacity = '1';
});
option.addEventListener('mouseout', () => {
option.style.borderColor = '#e2e8f0';
option.style.transform = 'translateX(0)';
option.style.boxShadow = 'none';
accent.style.opacity = '0';
});
const amount = option.getAttribute('data-amount');
option.onclick = () => {
const modal = document.getElementById('pointsPackagesModal');
if (modal) modal.remove();
window.initiatePayFromScript(parseFloat(amount), 'ai_points');
};
});
}
window.showPointsPackages = () => {
showPointsPackages();
};
const KIMI_MODEL_NAME = "kimi-k2-0711-preview";
const KIMI_SYSTEM_PROMPT = `你是一个专业的英语教学助手,擅长分析英语题目。请注意:
1. 阅读整个页面的所有题目和选项
2. 给出每道题的答案,格式为:1.A, 2.B 这样的形式
3. 只使用实际存在的选项字母
4. 理解题目类型,特别是"not collocate"类型表示选择不正确的搭配
5. 确保答案数量与题目数量一致
6. 如果是填空题,直接给出单词或短语答案
7. 如果遇到不确定的答案,说明原因并给出最可能的选项`;
async function askKimi(question, retryCount = 3, retryDelay = 1000) {
console.log('🤖 V2脚本: askKimi 被调用');
if (!useKimiAI) {
console.log('❌ V2脚本: AI 模式未开启');
alert('请先开启 AI 答题功能');
return null;
}
console.log('✅ V2脚本: AI 模式已开启');
if (userPoints < POINTS_PER_QUESTION) {
console.log(`❌ V2脚本: 积分不足 (当前: ${userPoints}, 需要: ${POINTS_PER_QUESTION})`);
alert(`积分不足!每次AI答题需要 ${POINTS_PER_QUESTION} 积分,当前积分:${userPoints}`);
showPointsPackages();
return null;
}
console.log(`✅ V2脚本: 积分充足 (${userPoints})`);
const interceptedData = window.__interceptedQuestionData;
const hasValidInterceptedData = interceptedData &&
interceptedData.encryptedContent &&
interceptedData.decryptionKey &&
(Date.now() - interceptedData.timestamp) < 60000;
if (hasValidInterceptedData) {
console.log('🆕 V2脚本: 使用新流程 - 发送密文到服务端解密');
console.log(' - 密文长度:', interceptedData.encryptedContent.length);
console.log(' - 解密密钥:', interceptedData.decryptionKey);
return await askKimiWithEncryptedData(
interceptedData.encryptedContent,
interceptedData.decryptionKey,
retryCount,
retryDelay
);
}
console.log('⚠️ V2脚本: 未检测到密文数据,使用旧流程(发送题目文本)');
return await askKimiLegacy(question, retryCount, retryDelay);
}
async function askKimiWithEncryptedData(encryptedContent, decryptionKey, retryCount = 3, retryDelay = 1000) {
let unitId = window.location.href.split('/').pop().split('?')[0];
let courseId = '';
try {
const hash = window.location.hash;
const hashMatch = hash.match(/course-v2:[^+]+\+([^+]+)\+/);
if (hashMatch && hashMatch[1]) {
courseId = hashMatch[1];
console.log('V2脚本: 从 Hash 提取到教材ID ->', courseId);
} else {
const urlParams = new URLSearchParams(window.location.search);
courseId = urlParams.get('courseId') || urlParams.get('cid');
}
} catch (e) {
console.warn('V2脚本: ID 提取异常', e);
}
const pageKey = courseId ? `${courseId}_${unitId}` : unitId;
for (let attempt = 1; attempt <= retryCount; attempt++) {
try {
console.log(`🔄 V2脚本: 正在调用 AI接口... (Key: ${pageKey})`);
const response = await new Promise((resolve, reject) => {
GM_xmlhttpRequest({
method: 'POST',
url: AI_SOLVE_ENDPOINT,
headers: { 'Content-Type': 'application/json' },
data: JSON.stringify({
userId: userId,
encryptedContent: encryptedContent,
decryptionKey: decryptionKey,
pageKey: pageKey
}),
timeout: 60000,
onload: function(res) { resolve(res); },
onerror: function(error) { reject(error); },
ontimeout: function() { reject(new Error('请求超时')); }
});
});
if (response.status >= 200 && response.status < 300 && response.responseText) {
let data;
try { data = JSON.parse(response.responseText); } catch (e) { continue; }
console.log('📥 V2脚本: 服务端响应:', data);
if (data.error === 'INSUFFICIENT_POINTS') {
userPoints = data.currentPoints || 0;
localStorage.setItem('userPoints', userPoints);
updatePointsDisplay();
alert(`积分不足!当前积分:${userPoints}`);
return null;
}
if (data.success && data.answer) {
let finalAnswer = data.answer;
if (data.source === 'truth_cache') {
finalAnswer = finalAnswer.replace(/【.*?】/g, '').trim();
if (finalAnswer.includes(';') && !finalAnswer.includes('\n')) {
const parts = finalAnswer.split(';').map(p => p.trim());
finalAnswer = parts.map((part, index) => `${index + 1}. ${part}`).join('\n');
}
}
userPoints = data.points;
localStorage.setItem('userPoints', userPoints);
updatePointsDisplay();
window.__interceptedQuestionData = null;
return finalAnswer;
}
}
if (attempt < retryCount) {
const delay = retryDelay * Math.pow(2, attempt - 1);
await new Promise(resolve => setTimeout(resolve, delay));
}
} catch (error) {
if (attempt === retryCount) return null;
await new Promise(resolve => setTimeout(resolve, retryDelay));
}
}
return null;
}
async function askKimiLegacy(question, retryCount = 3, retryDelay = 1000) {
for (let attempt = 1; attempt <= retryCount; attempt++) {
try {
console.log(`🔄 V2脚本 [旧流程]: 正在调用 KIMI API... (第${attempt}次尝试)`);
const messages = [
{
role: "system",
content: KIMI_SYSTEM_PROMPT
},
{
role: "user",
content: question
}
];
const response = await new Promise((resolve, reject) => {
GM_xmlhttpRequest({
method: 'POST',
url: KIMI_API_ENDPOINT,
headers: {
'Content-Type': 'application/json'
},
data: JSON.stringify({
userId: userId,
messages: messages,
temperature: 0.6
}),
timeout: 30000,
onload: function(response) {
try {
const data = JSON.parse(response.responseText);
if (data.error === 'INSUFFICIENT_POINTS') {
alert(`积分不足!每次AI答题需要${POINTS_PER_QUESTION}积分,当前积分:${userPoints}`);
showPointsPackages();
reject(new Error('积分不足'));
return;
}
if (data.points !== undefined) {
userPoints = data.points;
localStorage.setItem('userPoints', userPoints);
updatePointsDisplay();
}
} catch(e) {}
resolve(response);
},
onerror: function(error) {
console.error('KIMI API请求错误:', error);
reject(error);
},
ontimeout: function() {
console.error('KIMI API请求超时');
reject(new Error('请求超时'));
}
});
});
if (response.status >= 200 && response.status < 300 && response.responseText) {
try {
const data = JSON.parse(response.responseText);
console.log('KIMI API响应:', data);
if (data.choices && data.choices[0] && data.choices[0].message && data.choices[0].message.content) {
return data.choices[0].message.content;
} else {
throw new Error('API响应格式不正确');
}
} catch (error) {
console.error('解析KIMI响应失败:', error);
if (attempt === retryCount) throw error;
}
} else {
let errorMessage = `API请求失败 (HTTP ${response.status})`;
try {
if (response.responseText) {
const errorData = JSON.parse(response.responseText);
errorMessage += `: ${JSON.stringify(errorData)}`;
}
} catch (e) {}
console.error(errorMessage);
if (attempt === retryCount) {
console.log('所有重试都失败,使用本地分析替代API响应');
return await analyzeQuestionLocally(question);
}
}
if (attempt < retryCount) {
const delay = retryDelay * Math.pow(2, attempt - 1);
console.log(`等待 ${delay}ms 后重试...`);
await new Promise(resolve => setTimeout(resolve, delay));
}
} catch (error) {
console.error(`第${attempt}次尝试失败:`, error);
if (attempt === retryCount) {
console.log('所有重试都失败,使用本地分析替代API响应');
return await analyzeQuestionLocally(question);
}
const delay = retryDelay * Math.pow(2, attempt - 1);
console.log(`等待 ${delay}ms 后重试...`);
await new Promise(resolve => setTimeout(resolve, delay));
}
}
return null;
}
async function analyzeQuestionLocally(question) {
console.log('开始本地分析题目');
const questionLines = question.split('\n');
const questionText = questionLines.find(line =>
line.includes('Identify') ||
line.includes('Choose') ||
line.includes('Select') ||
line.includes('which')
) || questionLines[0];
console.log('题目文本:', questionText);
const options = [];
let optionLetters = '';
questionLines.forEach(line => {
const optionMatch = line.match(/^([A-D])[\.:\)\s]\s*(.+)$/);
if (optionMatch) {
const [, letter, text] = optionMatch;
options.push({ letter, text });
console.log(`选项 ${letter}: ${text}`);
}
});
let simulatedAnswer = '';
if (questionText.includes('not collocate') ||
questionText.includes('do not') ||
questionText.includes('incorrect') ||
questionText.includes('wrong') ||
questionText.includes('false')) {
console.log('识别为"查找不正确"类型题目');
simulatedAnswer = 'B';
optionLetters = 'B';
} else if (questionText.includes('collocate') ||
questionText.includes('match') ||
questionText.includes('pair') ||
questionText.includes('correct') ||
questionText.includes('true')) {
console.log('识别为"查找正确"类型题目');
simulatedAnswer = 'A, C, D';
optionLetters = 'ACD';
} else {
console.log('无法确定题目类型,返回所有选项');
optionLetters = options.map(opt => opt.letter).join(', ');
simulatedAnswer = optionLetters;
}
console.log('本地分析生成的答案:', simulatedAnswer);
return simulatedAnswer;
}
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
let isProcessingVirtualMic = false;
function setupRecordingHijack() {
const originalGetUserMedia = navigator.mediaDevices.getUserMedia.bind(navigator.mediaDevices);
navigator.mediaDevices.getUserMedia = async function(constraints) {
if (constraints.audio && window.__autoPlayRecordEnabled && !isProcessingVirtualMic) {
const sampleAudio = findSampleAudio(currentRecordButton);
const wavBlob = audioBlobCache.get(currentQuestionContainer);
if (wavBlob) {
isProcessingVirtualMic = true;
console.log('[核心] 正在构建虚拟音频流...');
const audioContext = new (window.AudioContext || window.webkitAudioContext)();
const arrayBuffer = await wavBlob.arrayBuffer();
const audioBuffer = await audioContext.decodeAudioData(arrayBuffer);
const sourceNode = audioContext.createBufferSource();
sourceNode.buffer = audioBuffer;
const destinationNode = audioContext.createMediaStreamDestination();
sourceNode.connect(destinationNode);
sourceNode.connect(audioContext.destination);
const delay = 800;
setTimeout(() => {
sourceNode.start(0);
console.log('[核心] 虚拟音频开始推送');
const totalDuration = (audioBuffer.duration * 1000) + 1000;
setTimeout(() => {
autoStopRecording();
isProcessingVirtualMic = false;
audioContext.close();
}, totalDuration);
}, delay);
return destinationNode.stream;
}
}
return originalGetUserMedia(constraints);
};
}
async function downloadAndSaveAudio(audioUrl, recordButton) {
try {
console.log('[自动播放录制器] 下载示例音频:', audioUrl);
const response = await fetch(audioUrl);
const blob = await response.blob();
const wavBlob = await convertToWAV(blob);
recordedAudioBlob = wavBlob;
recordedAudioUrl = URL.createObjectURL(wavBlob);
if (recordButton) {
const questionContainer = recordButton.closest('.oral-study-sentence') ||
recordButton.closest('.question-common-abs-reply') ||
recordButton.closest('.question-vocabulary');
if (questionContainer) {
audioCache.set(questionContainer, recordedAudioUrl);
audioBlobCache.set(questionContainer, wavBlob);
console.log('[自动播放录制器] ✅ 音频已保存到当前题目');
}
}
console.log('[自动播放录制器] ✅ 音频已保存');
} catch (error) {
console.error('[自动播放录制器] 下载音频失败:', error);
}
}
async function convertToWAV(blob) {
try {
const arrayBuffer = await blob.arrayBuffer();
const audioContext = new (window.AudioContext || window.webkitAudioContext)();
const audioBuffer = await audioContext.decodeAudioData(arrayBuffer);
let channelData;
if (audioBuffer.numberOfChannels === 1) {
channelData = audioBuffer.getChannelData(0);
} else {
const left = audioBuffer.getChannelData(0);
const right = audioBuffer.getChannelData(1);
channelData = new Float32Array(left.length);
for (let i = 0; i < left.length; i++) {
channelData[i] = (left[i] + right[i]) / 2;
}
}
const resampled = resampleAudio(channelData, audioBuffer.sampleRate, 16000);
const wavBuffer = encodeWAV(resampled, 16000);
return new Blob([wavBuffer], { type: 'audio/wav' });
} catch (error) {
console.error('[自动播放录制器] 转换失败,使用原始音频:', error);
return blob;
}
}
function resampleAudio(audioData, fromSampleRate, toSampleRate) {
if (fromSampleRate === toSampleRate) return audioData;
const ratio = fromSampleRate / toSampleRate;
const newLength = Math.round(audioData.length / ratio);
const result = new Float32Array(newLength);
for (let i = 0; i < newLength; i++) {
const position = i * ratio;
const index = Math.floor(position);
const fraction = position - index;
if (index + 1 < audioData.length) {
result[i] = audioData[index] * (1 - fraction) + audioData[index + 1] * fraction;
} else {
result[i] = audioData[index];
}
}
return result;
}
function encodeWAV(samples, sampleRate) {
const buffer = new ArrayBuffer(44 + samples.length * 2);
const view = new DataView(buffer);
const writeString = (offset, string) => {
for (let i = 0; i < string.length; i++) {
view.setUint8(offset + i, string.charCodeAt(i));
}
};
writeString(0, 'RIFF');
view.setUint32(4, 36 + samples.length * 2, true);
writeString(8, 'WAVE');
writeString(12, 'fmt ');
view.setUint32(16, 16, true);
view.setUint16(20, 1, true);
view.setUint16(22, 1, true);
view.setUint32(24, sampleRate, true);
view.setUint32(28, sampleRate * 2, true);
view.setUint16(32, 2, true);
view.setUint16(34, 16, true);
writeString(36, 'data');
view.setUint32(40, samples.length * 2, true);
let offset = 44;
for (let i = 0; i < samples.length; i++) {
const s = Math.max(-1, Math.min(1, samples[i]));
view.setInt16(offset, s < 0 ? s * 0x8000 : s * 0x7FFF, true);
offset += 2;
}
return buffer;
}
function findSampleAudio(recordButton) {
const questionContainer = recordButton ?
recordButton.closest('.oral-study-sentence') ||
recordButton.closest('.question-common-abs-reply') ||
recordButton.closest('.question-vocabulary') ||
recordButton.closest('.vocContainer') ||
recordButton.closest('.layoutBody-container.has-reply') :
null;
if (questionContainer) {
console.log('[自动播放录制器] 找到题目容器:', questionContainer.className);
if (questionContainer.classList.contains('vocContainer')) {
const vocAudio = questionContainer.querySelector('audio[src], .audio-player audio, .sound-btn audio, [class*="audio"] audio');
if (vocAudio && vocAudio.src) {
console.log('[自动播放录制器] 找到词汇卡片的音频');
return vocAudio;
}
const audioButtons = questionContainer.querySelectorAll('.sound-btn, .audio-btn, [class*="sound"], [class*="audio"]');
for (const btn of audioButtons) {
const audio = btn.querySelector('audio') || btn.parentElement.querySelector('audio');
if (audio && audio.src) {
console.log('[自动播放录制器] 找到词汇卡片按钮关联的音频');
return audio;
}
}
}
if (questionContainer.classList.contains('question-vocabulary')) {
const vocabularyAudio = questionContainer.querySelector('.question-audio audio');
if (vocabularyAudio && vocabularyAudio.src) {
console.log('[自动播放录制器] 找到词汇练习的单词发音');
return vocabularyAudio;
}
const soundAudio = questionContainer.querySelector('.soundWrap .question-audio audio');
if (soundAudio && soundAudio.src) {
console.log('[自动播放录制器] 找到词汇练习的soundWrap音频');
return soundAudio;
}
}
if (questionContainer.classList.contains('layoutBody-container') && questionContainer.classList.contains('has-reply')) {
const sentenceContainer = recordButton.closest('.oral-study-sentence');
if (sentenceContainer) {
console.log('[自动播放录制器] 检测到句子跟读练习');
const originAudio = sentenceContainer.querySelector('.question-audio.audio-origin audio[src]');
if (originAudio && originAudio.src) {
console.log('[自动播放录制器] 找到句子跟读练习的示例音频(audio-origin)');
return originAudio;
}
const audioType = window.__selectedAudioType || 'british';
const sampleAudioContainer = sentenceContainer.querySelector('.sample-audio');
if (sampleAudioContainer) {
let targetAudio = null;
if (audioType === 'british') {
const britishItem = sampleAudioContainer.querySelector('.item:first-child');
if (britishItem) {
targetAudio = britishItem.querySelector('audio');
if (targetAudio && targetAudio.src) {
console.log('[自动播放录制器] 找到句子跟读练习的英音示例');
return targetAudio;
}
}
} else {
const americanItem = sampleAudioContainer.querySelector('.item:last-child');
if (americanItem) {
targetAudio = americanItem.querySelector('audio');
if (targetAudio && targetAudio.src) {
console.log('[自动播放录制器] 找到句子跟读练习的美音示例');
return targetAudio;
}
}
}
const anyAudio = sampleAudioContainer.querySelector('audio[src]');
if (anyAudio && anyAudio.src) {
console.log('[自动播放录制器] 找到句子跟读练习的示例音频(任意类型)');
return anyAudio;
}
}
console.log('[自动播放录制器] ⚠️ 未在当前句子中找到示例音频');
return null;
}
}
const originAudio = questionContainer.querySelector('.question-audio.audio-origin audio[src]');
if (originAudio && originAudio.src) {
console.log('[自动播放录制器] 找到题目的示例音频(audio-origin)');
return originAudio;
}
const audioType = window.__selectedAudioType || 'british';
if (audioType === 'british') {
const britishAudio = questionContainer.querySelector('.sample-audio .item:first-child audio');
if (britishAudio && britishAudio.src) {
console.log('[自动播放录制器] 找到当前题目的英音示例');
return britishAudio;
}
} else {
const americanAudio = questionContainer.querySelector('.sample-audio .item:last-child audio');
if (americanAudio && americanAudio.src) {
console.log('[自动播放录制器] 找到当前题目的美音示例');
return americanAudio;
}
}
const anyAudio = questionContainer.querySelector('.sample-audio audio');
if (anyAudio && anyAudio.src) {
console.log('[自动播放录制器] 找到当前题目的示例音频');
return anyAudio;
}
}
console.log('[自动播放录制器] ⚠️ 未找到当前题目的示例音频');
return null;
}
function monitorRecordButton() {
document.addEventListener('click', async (e) => {
const recordIcon = e.target.closest('.record-icon') ||
e.target.closest('.record-fill-icon') ||
e.target.closest('.button-record');
if (recordIcon) {
currentRecordButton = recordIcon;
currentQuestionContainer = recordIcon.closest('.oral-study-sentence') ||
recordIcon.closest('.question-common-abs-reply') ||
recordIcon.closest('.question-vocabulary') ||
recordIcon.closest('.vocContainer') ||
recordIcon.closest('.layoutBody-container.has-reply');
console.log('[自动播放录制器] 检测到录音按钮点击');
if (window.__autoPlayRecordEnabled) {
const sampleAudio = findSampleAudio(recordIcon);
if (sampleAudio) {
showRecordNotification('⏳ 正在准备音频...', 'info');
await downloadAndSaveAudio(sampleAudio.src, recordIcon);
console.log('[自动播放录制器] ✅ 音频已预先加载并缓存');
} else {
console.log('[自动播放录制器] ⚠️ 未找到当前题目的示例音频 (已静默)');
}
}
}
}, true);
}
function monitorReplayAudio() {
setInterval(() => {
if (window.__autoPlayRecordEnabled) {
const questionContainers = document.querySelectorAll('.oral-study-sentence, .question-common-abs-reply, .question-vocabulary, .vocContainer, .layoutBody-container.has-reply .oral-study-sentence');
questionContainers.forEach(container => {
const replayAudio = container.querySelector('.audio-replay audio') ||
container.querySelector('.question-audio audio-player audio');
const cachedUrl = audioCache.get(container);
if (replayAudio && cachedUrl && replayAudio.src !== cachedUrl) {
console.log('[自动播放录制器] 🎯 定期检查:替换题目回放音频');
replayAudio.src = cachedUrl;
replayAudio.load();
const controlBox = container.querySelector('.audio-replay .audio-control-box') ||
container.querySelector('.audio-control-box');
if (controlBox) {
controlBox.classList.remove('disabled');
controlBox.style.display = 'flex';
}
}
});
}
checkForAudioCompleteNotification();
}, 500);
}
function checkForAudioCompleteNotification() {
const notifications = document.querySelectorAll('div, span, p, .notification, .toast, .message');
for (const notification of notifications) {
const text = notification.textContent || notification.innerText || '';
if (text.includes('音频播放完成') ||
text.includes('可以停止录音') ||
text.includes('录音完成') ||
text.includes('播放完成')) {
const rect = notification.getBoundingClientRect();
const isVisible = rect.width > 0 && rect.height > 0 &&
rect.top >= 0 && rect.left >= 0 &&
rect.bottom <= window.innerHeight &&
rect.right <= window.innerWidth;
if (isVisible) {
console.log('[自动停止录音] 🔔 检测到音频播放完成提示:', text);
const recordingButton = document.querySelector('.record-icon.recording, .button-record.recording, .record-fill-icon.recording');
if (recordingButton) {
console.log('[自动停止录音] 🎤 发现正在录音,准备自动停止...');
setTimeout(() => {
autoStopRecording();
}, 1000);
notification.setAttribute('data-auto-handled', 'true');
break;
}
}
}
}
}
function setupURLHijack() {
const originalCreateObjectURL = URL.createObjectURL;
URL.createObjectURL = function(obj) {
if (window.__autoPlayRecordEnabled &&
recordedAudioUrl &&
obj instanceof Blob &&
obj.type &&
(obj.type.includes('audio') || obj.type.includes('webm'))) {
console.log('[自动播放录制器] 🎯 拦截回放 URL,返回示例音频');
return recordedAudioUrl;
}
return originalCreateObjectURL(obj);
};
}
function setupAudioSrcHijack() {
const originalAudioSrcDescriptor = Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype, 'src');
Object.defineProperty(HTMLMediaElement.prototype, 'src', {
get: function() {
return originalAudioSrcDescriptor.get.call(this);
},
set: function(value) {
if (window.__autoPlayRecordEnabled &&
recordedAudioUrl &&
this.closest('.audio-replay') &&
typeof value === 'string' &&
value.startsWith('blob:')) {
console.log('[自动播放录制器] 🎯 拦截回放 src,使用示例音频');
originalAudioSrcDescriptor.set.call(this, recordedAudioUrl);
return;
}
originalAudioSrcDescriptor.set.call(this, value);
}
});
}
function autoStopRecording() {
const recordingButton = document.querySelector('.record-icon.recording, .button-record.recording, .record-fill-icon.recording');
if (recordingButton) {
recordingButton.dataset.autoStopped = "true";
console.log('[停止] 触发点击停止录音');
recordingButton.click();
}
}
function showRecordNotification(message, type = 'info') {
const notification = document.createElement('div');
notification.style.cssText = `
position: fixed;
top: 20px;
left: 50%;
transform: translateX(-50%);
background: ${type === 'success' ? '#48bb78' : type === 'error' ? '#f56565' : '#4299e1'};
color: white;
padding: 15px 30px;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0,0,0,0.3);
z-index: 100000;
font-size: 14px;
font-weight: 600;
animation: slideDown 0.3s ease;
`;
notification.textContent = message;
document.body.appendChild(notification);
setTimeout(() => {
notification.style.animation = 'slideUp 0.3s ease';
setTimeout(() => notification.remove(), 300);
}, 3000);
}
function startAutoRefresh() {
if (autoRefreshInterval) {
clearInterval(autoRefreshInterval);
}
const intervalMinutes = window.__refreshInterval || 30;
const intervalMs = intervalMinutes * 60 * 1000;
let displayTime;
if (intervalMinutes < 1) {
displayTime = `${intervalMinutes * 60}秒`;
} else {
displayTime = `${intervalMinutes}分钟`;
}
console.log(`[自动刷新] 已启动,间隔: ${displayTime}`);
showRefreshNotification(`🔄 自动刷新已启动 (${displayTime}间隔)`, 'info');
autoRefreshInterval = setInterval(() => {
console.log('[自动刷新] 执行页面刷新...');
showRefreshNotification('🔄 正在刷新页面...', 'info');
setTimeout(() => {
location.reload();
}, 1000);
}, intervalMs);
autoRefreshEnabled = true;
}
function stopAutoRefresh() {
if (autoRefreshInterval) {
clearInterval(autoRefreshInterval);
autoRefreshInterval = null;
}
autoRefreshEnabled = false;
console.log('[自动刷新] 已停止');
showRefreshNotification('⏹️ 自动刷新已停止', 'info');
}
function showRefreshNotification(message, type = 'info') {
const notification = document.createElement('div');
notification.style.cssText = `
position: fixed;
top: 20px;
right: 20px;
padding: 12px 20px;
border-radius: 8px;
color: white;
font-weight: bold;
font-size: 14px;
z-index: 10000;
box-shadow: 0 4px 12px rgba(0,0,0,0.3);
animation: slideDown 0.3s ease;
max-width: 300px;
`;
switch(type) {
case 'success':
notification.style.background = 'linear-gradient(135deg, #10B981, #059669)';
break;
case 'error':
notification.style.background = 'linear-gradient(135deg, #EF4444, #DC2626)';
break;
case 'info':
default:
notification.style.background = 'linear-gradient(135deg, #3B82F6, #2563EB)';
break;
}
notification.textContent = message;
document.body.appendChild(notification);
setTimeout(() => {
notification.style.animation = 'slideUp 0.3s ease';
setTimeout(() => notification.remove(), 300);
}, 3000);
}
async function handleVocabularyRecording() {
console.log('[挂机录音] 开始检测词汇卡片录音按钮...');
const activeSlide = document.querySelector('.swiper-slide-active');
if (!activeSlide) return false;
const recordButton = activeSlide.querySelector('.record-fill-icon, .record-icon, .button-record');
if (!recordButton) return false;
if (recordButton.hasAttribute('data-auto-handled')) return false;
try {
recordButton.setAttribute('data-auto-handled', 'true');
showRecordNotification('🎤 词汇录音开始...', 'info');
recordButton.click();
const settingDuration = window.__recordDuration || 3;
const totalWaitTime = (settingDuration * 1000) + 1500;
await sleep(totalWaitTime);
recordButton.click();
console.log('[挂机录音] ⏹ 词汇录音停止');
await waitForScoreAppear();
return true;
} catch (error) {
console.error('[挂机录音] 词汇录音异常:', error);
return false;
}
}
async function waitForScoreAppear() {
console.log('[挂机录音] ⏳ 正在等待评分结果...');
const maxWaitTime = 15000;
const checkInterval = 500;
let waitedTime = 0;
return new Promise((resolve) => {
const checkScore = () => {
const scoreElement = document.querySelector('.score_layout') ||
document.querySelector('.practice-score .score') ||
document.querySelector('.score-wrapper .score') ||
document.querySelector('.oral-score');
if (scoreElement && scoreElement.textContent.trim() && scoreElement.textContent.trim() !== '') {
const score = scoreElement.textContent.trim();
console.log(`[挂机录音] ✅ 检测到分数: ${score}`);
showRecordNotification(`📊 得分: ${score}`, 'success');
resolve(true);
return;
}
waitedTime += checkInterval;
if (waitedTime >= maxWaitTime) {
console.warn('[挂机录音] ⚠️ 等待分数超时 (可能是网络卡顿或未检测到)');
resolve(false);
return;
}
setTimeout(checkScore, checkInterval);
};
checkScore();
});
}
async function handleSentenceRecitationExercise() {
console.log('[挂机录音] 开始检测句子跟读练习...');
const exerciseContainer = document.querySelector('.layoutBody-container.has-reply');
if (!exerciseContainer) return false;
const sentenceContainers = exerciseContainer.querySelectorAll('.oral-study-sentence');
if (sentenceContainers.length === 0) return false;
let handledCount = 0;
for (let i = 0; i < sentenceContainers.length; i++) {
const sentenceContainer = sentenceContainers[i];
const recordButton = sentenceContainer.querySelector('.record-icon:not([data-auto-handled]), .button-record:not([data-auto-handled])');
if (!recordButton) continue;
try {
recordButton.setAttribute('data-auto-handled', 'true');
console.log(`[挂机录音] ➤ 处理第 ${i + 1} 句`);
await processSentenceRecording(recordButton, sentenceContainer, i + 1);
await waitForScoreAppear();
handledCount++;
} catch (error) {
console.error(`[挂机录音] 第 ${i + 1} 句异常:`, error);
}
await sleep(1500);
}
if (handledCount > 0) {
showRecordNotification(`✅ 已完成 ${handledCount} 个句子`, 'success');
return true;
}
return false;
}
async function processSentenceRecording(recordButton, sentenceContainer, sentenceIndex) {
return new Promise(async (resolve) => {
try {
const sampleAudio = findSampleAudio(recordButton);
let targetDuration = 0;
if (sampleAudio) {
await downloadAndSaveAudio(sampleAudio.src, recordButton);
const cachedBlob = audioBlobCache.get(sentenceContainer);
if (cachedBlob) {
const tempAudio = new Audio(URL.createObjectURL(cachedBlob));
targetDuration = await new Promise(r => {
tempAudio.onloadedmetadata = () => r(tempAudio.duration);
tempAudio.onerror = () => r(0);
setTimeout(() => r(0), 1000);
});
}
}
const baseTime = targetDuration > 0 ? targetDuration : (window.__recordDuration || 3);
const waitTimeMs = (baseTime * 1000) + 1500;
console.log(`[挂机录音] ⏺ 第 ${sentenceIndex} 句:点击开始`);
recordButton.click();
console.log(`[挂机录音] ⏳ 强制等待 ${waitTimeMs}ms ...`);
await sleep(waitTimeMs);
console.log(`[挂机录音] ⏹ 第 ${sentenceIndex} 句:点击停止`);
recordButton.click();
setTimeout(() => {
resolve(true);
}, 2000);
} catch (error) {
console.error(`[挂机录音] 执行错误:`, error);
resolve(true);
}
});
}
async function handleRoleSelection() {
const roleList = document.querySelector('.role-list');
if (!roleList || roleList.offsetParent === null) return false;
const roles = roleList.querySelectorAll('.role');
if (roles.length === 0) return false;
console.log(`[挂机录音] 🎭 检测到角色选择界面,共有 ${roles.length} 个选项`);
const randomIndex = Math.floor(Math.random() * roles.length);
const targetRole = roles[randomIndex];
const roleName = targetRole.querySelector('.label span')?.textContent.trim() || `角色 ${randomIndex + 1}`;
console.log(`[挂机录音] 🎲 随机选中: ${roleName}`);
const clickTarget = targetRole.querySelector('.svg-icon') || targetRole;
const opts = { bubbles: true, cancelable: true };
clickTarget.dispatchEvent(new MouseEvent('mouseover', opts));
clickTarget.dispatchEvent(new MouseEvent('mousedown', opts));
clickTarget.dispatchEvent(new MouseEvent('mouseup', opts));
clickTarget.click();
const input = targetRole.querySelector('input');
if (input) input.click();
await sleep(2000);
return true;
}
async function handleRolePlayExercise() {
console.log('[挂机录音] 🎭 进入角色扮演(Role Play)模式...');
const recordSeat = document.querySelector('.record-seat');
if (!recordSeat) {
console.log('[挂机录音] ⚠️ 未找到录音按钮');
return false;
}
const startSvg = recordSeat.querySelector('svg');
if (!startSvg) {
console.log('[挂机录音] ⚠️ 未找到启动图标');
return false;
}
const simulateClick = (element) => {
if (!element) return;
const rect = element.getBoundingClientRect();
const opts = {
bubbles: true, cancelable: true, buttons: 1,
clientX: rect.left + rect.width / 2, clientY: rect.top + rect.height / 2
};
element.dispatchEvent(new PointerEvent('pointerdown', opts));
element.dispatchEvent(new MouseEvent('mousedown', opts));
setTimeout(() => {
element.dispatchEvent(new PointerEvent('pointerup', opts));
element.dispatchEvent(new MouseEvent('mouseup', opts));
if (typeof element.click === 'function') element.click();
else element.dispatchEvent(new MouseEvent('click', opts));
}, 50);
};
console.log('[挂机录音] 🚀 点击启动...');
simulateClick(startSvg);
await sleep(2000);
const maxMonitorSeconds = 900;
let lastProcessedItem = null;
for (let i = 0; i < maxMonitorSeconds; i++) {
const allItems = document.querySelectorAll('.list-item-review');
const activeItem = document.querySelector('.list-item-review.active');
if (activeItem) {
if (activeItem !== lastProcessedItem) {
lastProcessedItem = activeItem;
const currentIndex = Array.from(allItems).indexOf(activeItem);
const isLastLine = (currentIndex === allItems.length - 1);
const isNPC = activeItem.querySelector('.score.hide') !== null;
const textEl = activeItem.querySelector('.component-htmlview') || activeItem.querySelector('.text');
const currentText = textEl ? textEl.textContent.trim() : '';
const wordCount = currentText.split(/\s+/).length;
const waitTime = Math.min(Math.max(wordCount * 450 + 1200, 2500), 15000);
if (isNPC) {
console.log(`[挂机录音] 👂 NPC (${currentIndex + 1}/${allItems.length}): "${currentText.substring(0, 15)}..."`);
console.log(`[挂机录音] ⏳ 等待播放 ${waitTime/1000} 秒...`);
await sleep(waitTime);
} else {
console.log(`[挂机录音] 🎤 用户 (${currentIndex + 1}/${allItems.length}): "${currentText.substring(0, 15)}..."`);
console.log(`[挂机录音] ⏳ 模拟录音 ${waitTime/1000} 秒...`);
await sleep(waitTime);
const stopBtn = activeItem.querySelector('.pause-circle-player');
if (stopBtn) {
console.log('[挂机录音] ⏹️ 录音结束,点击提交');
simulateClick(stopBtn);
}
}
if (isLastLine) {
console.log('[挂机录音] ✅ 检测到这是最后一句台词,流程结束!');
await sleep(2000);
break;
}
await sleep(1000);
}
}
await sleep(1000);
}
console.log('[挂机录音] 🎉 角色扮演流程完成,等待结算...');
await sleep(3000);
return true;
}
async function handleRecordingQuestions() {
console.log('[挂机录音] 开始检测录音题...');
const roleSelected = await handleRoleSelection();
if (roleSelected) {
console.log('[挂机录音] 角色已选择,等待界面刷新...');
await sleep(2000);
}
if (document.querySelector('.record-seat')) {
return await handleRolePlayExercise();
}
if (document.querySelector('textarea[placeholder*="评论"]') ||
document.querySelector('.discussion-container')) {
console.log('[挂机录音] 🛑 检测到当前是讨论/评论页面,跳过录音题检测。');
return false;
}
if (document.querySelector('.layoutBody-container.has-reply .oral-study-sentence')) {
console.log('[挂机录音] 检测到句子跟读练习,使用专门处理函数');
return await handleSentenceRecitationExercise();
}
const recordButtons = document.querySelectorAll(`
.record-icon:not(.recording):not([data-auto-handled]),
.record-fill-icon:not(.recording):not([data-auto-handled]),
.button-record:not(.recording):not([data-auto-handled]),
[class*="record"]:not(.recording):not([data-auto-handled]):not(.audio-replay),
.microphone-btn:not(.recording):not([data-auto-handled]),
.mic-button:not(.recording):not([data-auto-handled])
`);
const validRecordButtons = Array.from(recordButtons).filter(btn => {
if (btn.closest('.audio-replay') ||
btn.closest('.playback') ||
btn.classList.contains('play') ||
btn.classList.contains('pause')) {
return false;
}
const container = btn.closest(`
.record-button-wrap,
.ucomp-recorder,
.oral-study-sentence,
.question-common-abs-reply,
.question-vocabulary,
.vocContainer,
.layoutBody-container.has-reply,
.question-container
`);
if (!container) {
return false;
}
if (btn.offsetParent === null) {
return false;
}
if (container.classList.contains('vocContainer')) {
const rect = btn.getBoundingClientRect();
if (rect.width === 0 || rect.height === 0) {
return false;
}
const vocCard = btn.closest('.voc-card, .vocabulary-card, [class*="card"]');
if (vocCard) {
const cardRect = vocCard.getBoundingClientRect();
return cardRect.width > 0 && cardRect.height > 0;
}
}
return true;
});
if (validRecordButtons.length === 0) {
console.log('[挂机录音] 未发现有效的录音题');
return false;
}
console.log(`[挂机录音] 发现 ${validRecordButtons.length} 个录音题,开始逐个处理...`);
let handledCount = 0;
for (let i = 0; i < validRecordButtons.length; i++) {
const recordButton = validRecordButtons[i];
if (recordButton.offsetParent === null) continue;
recordButton.setAttribute('data-auto-handled', 'true');
console.log(`[挂机录音] 处理第 ${i + 1}/${validRecordButtons.length} 个录音题`);
try {
const success = await processRecordingQuestion(recordButton);
if (success) {
handledCount++;
console.log(`[挂机录音] 第 ${i + 1} 个录音题动作已执行`);
const safetyDelay = 3000 + (window.__recordDuration * 1000);
console.log(`[挂机录音] 安全等待 ${safetyDelay}ms...`);
await sleep(safetyDelay);
} else {
console.warn(`[挂机录音] 第 ${i + 1} 个录音题处理失败`);
}
} catch (error) {
console.error(`[挂机录音] 处理第 ${i + 1} 个录音题时出错:`, error);
}
if (i < validRecordButtons.length - 1) {
await sleep(2000 + Math.random() * 1000);
}
}
if (handledCount > 0) {
console.log(`[挂机录音] ✅ 成功处理了 ${handledCount} 个录音题`);
showRecordNotification(`✅ 自动完成 ${handledCount} 个录音题`, 'success');
return true;
}
return false;
}
async function processRecordingQuestion(recordButton) {
return new Promise(async (resolve) => {
try {
currentRecordButton = recordButton;
currentQuestionContainer = recordButton.closest('.oral-study-sentence') ||
recordButton.closest('.question-common-abs-reply') ||
recordButton.closest('.question-vocabulary') ||
recordButton.closest('.vocContainer') ||
recordButton.closest('.layoutBody-container.has-reply');
if (!currentQuestionContainer) {
console.warn('[挂机录音] 无法找到题目容器,尝试盲录');
}
console.log('[挂机录音] 🎤 开始录音题自动处理...');
const sampleAudio = findSampleAudio(recordButton);
let hasSample = false;
if (sampleAudio) {
await downloadAndSaveAudio(sampleAudio.src, recordButton);
hasSample = true;
} else {
console.log('[挂机录音] 无示例音频,进入强制录音模式...');
}
recordButton.click();
await sleep(500);
let recordingStarted = false;
let recordingFinished = false;
let timeoutId = null;
const checkRecordingStart = () => {
const isRecording = recordButton.classList.contains('recording') ||
recordButton.closest('.question-container')?.querySelector('.recording') ||
document.querySelector('.recording');
if (isRecording && !recordingStarted) {
recordingStarted = true;
console.log('[挂机录音] 📹 录音已开始');
const cachedBlob = currentQuestionContainer ? audioBlobCache.get(currentQuestionContainer) : null;
if (hasSample && cachedBlob) {
const tempAudio = new Audio(URL.createObjectURL(cachedBlob));
tempAudio.addEventListener('loadedmetadata', () => {
const duration = tempAudio.duration;
const delayTime = parseInt(document.getElementById('voice-delay-selector')?.value || '1000');
const totalTime = duration * 1000 + delayTime + 1000;
console.log(`[挂机录音] 跟读模式,时长: ${duration.toFixed(2)}s`);
timeoutId = setTimeout(() => finishRecording(), totalTime);
});
tempAudio.load();
} else {
const recordDuration = window.__recordDuration || 3;
const defaultTime = recordDuration * 1000;
console.log(`[挂机录音] 强制录音模式,固定时长: ${recordDuration}s`);
timeoutId = setTimeout(() => finishRecording(), defaultTime);
}
}
};
const finishRecording = () => {
if (!recordingFinished) {
console.log('[挂机录音] ⏹️ 自动停止录音');
recordButton.click();
recordingFinished = true;
setTimeout(() => {
console.log('[挂机录音] ✅ 录音题处理完成');
resolve(true);
}, 1000);
}
};
const statusCheckInterval = setInterval(() => {
if (recordingFinished) {
clearInterval(statusCheckInterval);
return;
}
checkRecordingStart();
const isStillRecording = recordButton.classList.contains('recording') ||
recordButton.closest('.question-container')?.querySelector('.recording') ||
document.querySelector('.recording');
if (recordingStarted && !isStillRecording && !recordingFinished) {
recordingFinished = true;
clearInterval(statusCheckInterval);
if (timeoutId) clearTimeout(timeoutId);
console.log('[挂机录音] ✅ 录音自然结束');
resolve(true);
}
}, 200);
setTimeout(() => {
if (!recordingFinished) {
recordingFinished = true;
clearInterval(statusCheckInterval);
if (timeoutId) clearTimeout(timeoutId);
console.warn('[挂机录音] ⚠️ 录音超时强制跳过');
recordButton.click();
resolve(true);
}
}, 15000);
} catch (error) {
console.error('[挂机录音] 处理录音题时出错:', error);
resolve(true);
}
});
}
function createCollapsibleSection(title, storageKey) {
const section = document.createElement('div');
section.className = 'u-helper-section u-collapsible';
const header = document.createElement('div');
header.className = 'u-helper-section-header';
const titleEl = document.createElement('div');
titleEl.className = 'u-helper-section-title';
titleEl.textContent = title;
const sectionContent = document.createElement('div');
sectionContent.className = 'u-helper-section-content';
header.appendChild(titleEl);
section.appendChild(header);
section.appendChild(sectionContent);
if (title.includes('AI')) {
const pointsSection = document.createElement('div');
pointsSection.style.cssText = `
margin: -12px -12px 12px;
padding: 15px;
background: linear-gradient(145deg, #f8f9fa, #e9ecef);
border-bottom: 1px solid rgba(0,0,0,0.05);
`;
const pointsHeader = document.createElement('div');
pointsHeader.style.cssText = `
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
`;
const pointsDisplay = document.createElement('div');
pointsDisplay.style.cssText = `
display: flex;
align-items: baseline;
gap: 8px;
`;
const pointsValue = document.createElement('span');
pointsValue.id = 'currentPointsDisplay';
pointsValue.style.cssText = `
font-size: 36px;
font-weight: bold;
color: #1890ff;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI";
`;
pointsValue.textContent = userPoints;
const pointsLabel = document.createElement('span');
pointsLabel.style.cssText = `
font-size: 15px;
font-weight: 600;
color: #666;
`;
pointsLabel.textContent = '积分';
pointsDisplay.appendChild(pointsValue);
pointsDisplay.appendChild(pointsLabel);
const buyPoints = document.createElement('button');
buyPoints.onclick = () => window.showPointsPackages();
buyPoints.style.cssText = `
padding: 8px 18px;
background: #1890ff;
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
font-size: 15px;
font-weight: 600;
transition: all 0.3s;
display: flex;
align-items: center;
gap: 4px;
box-shadow: 0 2px 4px rgba(24, 144, 255, 0.3);
`;
buyPoints.innerHTML = `
充值
`;
buyPoints.onmouseover = () => buyPoints.style.background = '#40a9ff';
buyPoints.onmouseout = () => buyPoints.style.background = '#1890ff';
pointsHeader.appendChild(pointsDisplay);
pointsHeader.appendChild(buyPoints);
const usageInfo = document.createElement('div');
usageInfo.style.cssText = `
font-size: 14px;
font-weight: 500;
color: #666;
display: flex;
align-items: center;
gap: 8px;
padding: 10px 14px;
background: rgba(24,144,255,0.1);
border-radius: 6px;
`;
const costIcon = document.createElement('span');
costIcon.textContent = '💡';
costIcon.style.fontSize = '16px';
const costText = document.createElement('span');
costText.textContent = `每次AI答题消耗 ${POINTS_PER_QUESTION} 积分`;
usageInfo.appendChild(costIcon);
usageInfo.appendChild(costText);
pointsSection.appendChild(pointsHeader);
pointsSection.appendChild(usageInfo);
sectionContent.appendChild(pointsSection);
}
const icon = document.createElement('div');
icon.className = 'u-collapse-icon';
icon.innerHTML = '';
const content = document.createElement('div');
content.className = 'u-helper-section-content';
header.appendChild(titleEl);
header.appendChild(icon);
section.appendChild(header);
section.appendChild(content);
const isCollapsed = localStorage.getItem(storageKey) === 'true';
if (isCollapsed) {
section.classList.add('u-collapsed');
}
header.addEventListener('click', () => {
const collapsed = section.classList.toggle('u-collapsed');
localStorage.setItem(storageKey, collapsed);
});
return { section, content };
}
function createFloatingButton() {
const styles = `
:root {
--u-bg-color: rgba(255, 255, 255, 0.75);
--u-blur-bg-color: rgba(255, 255, 255, 0.5);
--u-border-color: rgba(0, 0, 0, 0.08);
--u-text-color-primary: #1a202c;
--u-text-color-secondary: #4a5568;
--u-text-color-tertiary: #718096;
--u-accent-color: #4299e1;
--u-accent-color-dark: #3182ce;
--u-success-color: #38a169;
--u-danger-color: #e53e3e;
--u-warning-color: #dd6b20;
--u-font-family: 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
--u-border-radius-lg: 16px;
--u-border-radius-md: 12px;
--u-border-radius-sm: 8px;
--u-shadow-lg: 0 10px 25px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
--u-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}
.u-helper-container {
position: fixed;
top: 20px;
right: 20px;
z-index: 10000;
display: flex;
flex-direction: column;
font-family: var(--u-font-family);
background: var(--u-bg-color);
backdrop-filter: blur(16px) saturate(180%);
-webkit-backdrop-filter: blur(16px) saturate(180%);
border-radius: var(--u-border-radius-lg);
border: 1px solid rgba(255, 255, 255, 0.6);
box-shadow: var(--u-shadow-lg);
transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
overflow: hidden;
width: 320px;
opacity: 0;
transform: translateY(-20px) scale(0.95);
color: var(--u-text-color-primary);
}
.u-helper-container.u-visible {
opacity: 1;
transform: translateY(0) scale(1);
}
.u-helper-title-bar {
display: flex;
justify-content: space-between;
align-items: center;
padding: 14px 18px;
background-color: var(--u-blur-bg-color);
font-weight: 700;
cursor: move;
user-select: none;
font-size: 16px;
border-bottom: 1px solid var(--u-border-color);
flex-shrink: 0;
}
.u-helper-title {
display: flex;
align-items: center;
gap: 10px;
}
.u-helper-logo-icon {
animation: logoBreath 3s ease-in-out infinite;
transition: transform 0.3s ease;
}
.u-helper-logo-icon:hover {
animation: logoSpin 0.6s ease-in-out;
transform: scale(1.1);
}
@keyframes logoBreath {
0%, 100% {
opacity: 1;
transform: scale(1);
}
50% {
opacity: 0.85;
transform: scale(1.05);
}
}
@keyframes logoSpin {
from {
transform: rotate(0deg) scale(1.1);
}
to {
transform: rotate(360deg) scale(1.1);
}
}
.u-helper-control-btn {
background: transparent;
border: none;
color: var(--u-text-color-secondary);
font-size: 20px;
cursor: pointer;
padding: 0;
display: flex;
align-items: center;
justify-content: center;
height: 28px;
width: 28px;
border-radius: var(--u-border-radius-sm);
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.u-helper-control-btn:hover {
background-color: rgba(0, 0, 0, 0.08);
transform: scale(1.15);
}
.u-helper-control-btn:active {
transform: scale(0.95);
}
.u-helper-content {
display: flex;
flex-direction: column;
gap: 18px;
padding: 18px;
width: 100%;
box-sizing: border-box;
max-height: calc(100vh - 150px);
overflow-y: auto;
overflow-x: hidden;
opacity: 1;
transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1),
opacity 0.3s ease,
padding 0.3s ease;
}
.u-helper-content.u-minimized {
max-height: 0;
opacity: 0;
padding-top: 0;
padding-bottom: 0;
overflow: hidden;
}
.u-helper-section {
display: flex;
flex-direction: column;
padding: 14px;
background: rgba(255, 255, 255, 0.6);
border-radius: var(--u-border-radius-md);
}
.u-helper-section-header {
display: flex;
justify-content: space-between;
align-items: center;
font-weight: 600;
}
.u-helper-section.u-collapsible > .u-helper-section-header {
cursor: pointer;
margin: -12px;
padding: 12px;
}
.u-helper-section-content {
padding-top: 12px;
display: flex;
flex-direction: column;
gap: 12px;
max-height: 2000px;
opacity: 1;
overflow: hidden;
transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1),
opacity 0.3s ease,
padding 0.3s ease;
}
.u-collapse-icon {
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
color: var(--u-text-color-tertiary);
}
.u-collapsible.u-collapsed .u-collapse-icon {
transform: rotate(-90deg);
}
.u-collapsible.u-collapsed .u-helper-section-content {
max-height: 0;
opacity: 0;
padding-top: 0;
padding-bottom: 0;
}
.u-helper-section-title {
font-size: 15px;
color: var(--u-text-color-primary);
font-weight: 700;
}
.u-helper-input-row {
display: flex;
align-items: center;
justify-content: space-between;
}
.u-helper-label {
font-size: 14px;
color: var(--u-text-color-secondary);
font-weight: 500;
}
.u-helper-input {
width: 80px;
padding: 8px 10px;
border-radius: var(--u-border-radius-sm);
border: 1px solid var(--u-border-color);
text-align: center;
background-color: #fff;
font-size: 14px;
font-weight: 500;
transition: all 0.2s;
box-shadow: var(--u-shadow-md);
}
.u-helper-input:focus {
outline: none;
border-color: var(--u-accent-color);
box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.2);
}
.u-helper-select-group {
display: flex;
align-items: center;
gap: 8px;
}
.u-helper-select {
flex-grow: 1;
padding: 9px 12px;
border: 1px solid var(--u-border-color);
border-radius: var(--u-border-radius-md);
font-size: 14px;
font-weight: 500;
background-color: #fff;
cursor: pointer;
width: 100%;
min-width: 0;
box-shadow: var(--u-shadow-md);
transition: all 0.2s;
}
.u-helper-select:focus {
outline: none;
border-color: var(--u-accent-color);
box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.2);
}
/* 开关样式 */
.u-helper-switch {
position: relative;
display: inline-block;
width: 44px;
height: 24px;
background-color: #ccc;
border-radius: 24px;
cursor: pointer;
transition: background-color 0.3s;
}
.u-helper-switch.active {
background-color: var(--u-accent-color);
}
.u-helper-switch-slider {
position: absolute;
top: 2px;
left: 2px;
width: 20px;
height: 20px;
background-color: white;
border-radius: 50%;
transition: transform 0.3s;
box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.u-helper-switch.active .u-helper-switch-slider {
transform: translateX(20px);
}
.u-helper-delete-btn {
background: rgba(0, 0, 0, 0.05);
color: var(--u-text-color-tertiary);
border: none;
border-radius: 50%;
width: 28px;
height: 28px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
flex-shrink: 0;
display: none;
}
.u-helper-delete-btn:hover {
background-color: var(--u-danger-color);
color: white;
transform: scale(1.1) rotate(90deg);
}
.u-helper-btn {
padding: 12px 18px;
border: none;
border-radius: var(--u-border-radius-md);
font-size: 15px;
font-weight: 600;
cursor: pointer;
transition: all 0.2s ease-in-out;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
width: 100%;
box-sizing: border-box;
box-shadow: var(--u-shadow-md);
}
.u-helper-btn:hover {
transform: translateY(-2px);
box-shadow: var(--u-shadow-lg);
}
.u-helper-btn:active {
transform: translateY(0) scale(0.98);
box-shadow: var(--u-shadow-md);
}
.u-helper-btn-primary {
background: var(--u-accent-color);
color: white;
}
.u-helper-btn-primary:hover {
background: var(--u-accent-color-dark);
}
.u-helper-btn-success {
background: var(--u-success-color);
color: white;
}
.u-helper-btn-warning {
background: var(--u-warning-color);
color: white;
}
.u-helper-btn-danger {
background: var(--u-danger-color);
color: white;
}
.u-helper-btn-secondary {
background: #fff;
color: var(--u-text-color-secondary);
border: 1px solid var(--u-border-color);
}
.u-helper-btn-secondary:hover {
background: #f7fafc;
}
.u-helper-info-display {
padding: 12px;
background: var(--u-blur-bg-color);
border-radius: var(--u-border-radius-md);
font-size: 13px;
color: var(--u-text-color-primary);
width: 100%;
max-height: 250px;
overflow-y: auto;
overflow-x: hidden;
overflow-wrap: break-word;
white-space: pre-wrap;
line-height: 1.4;
display: none;
border: 1px solid rgba(255, 255, 255, 0.8);
box-sizing: border-box;
opacity: 0;
transform: translateY(-10px) scale(0.98);
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.u-helper-info-display.u-visible {
display: block;
opacity: 1;
transform: translateY(0) scale(1);
}
.u-helper-info-display::-webkit-scrollbar { width: 6px; }
.u-helper-info-display::-webkit-scrollbar-track { background: transparent; }
.u-helper-info-display::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.2); border-radius: 3px; }
.u-helper-info-display::-webkit-scrollbar-thumb:hover { background: rgba(0, 0, 0, 0.3); }
.u-helper-footer {
width: 100%;
padding: 10px 0;
margin-top: 10px;
border-top: 1px solid var(--u-border-color);
font-size: 13px;
color: var(--u-text-color-tertiary);
text-align: center;
font-weight: 600;
cursor: default;
user-select: none;
}
.u-ripple {
position: absolute;
border-radius: 50%;
background: rgba(255, 255, 255, 0.4);
transform: scale(0);
animation: u-ripple-anim 0.6s linear;
pointer-events: none;
}
@keyframes u-ripple-anim {
to {
transform: scale(4);
opacity: 0;
}
}
@keyframes slideDown {
from { transform: translateX(-50%) translateY(-100%); opacity: 0; }
to { transform: translateX(-50%) translateY(0); opacity: 1; }
}
@keyframes slideUp {
from { transform: translateX(-50%) translateY(0); opacity: 1; }
to { transform: translateX(-50%) translateY(-100%); opacity: 0; }
}
.product-dialog {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
z-index: 10001;
}
.product-dialog-content {
background: white;
padding: 20px;
border-radius: 12px;
width: 90%;
max-width: 800px;
max-height: 90vh;
overflow-y: auto;
}
.product-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 20px;
margin: 20px 0;
}
.product-card {
border: 1px solid #eee;
border-radius: 8px;
padding: 15px;
text-align: center;
cursor: pointer;
transition: all 0.3s ease;
}
.product-card:hover {
transform: translateY(-5px);
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}
.product-card.selected {
border: 2px solid #4299e1;
background: #ebf8ff;
}
.product-image {
width: 100%;
height: 150px;
object-fit: cover;
border-radius: 4px;
margin-bottom: 10px;
}
.product-title {
font-size: 18px;
font-weight: bold;
margin-bottom: 10px;
}
.product-price {
font-size: 20px;
color: #e53e3e;
margin-bottom: 10px;
}
.product-description {
color: #666;
margin-bottom: 15px;
}
.dialog-buttons {
display: flex;
justify-content: flex-end;
gap: 10px;
margin-top: 20px;
}
.dialog-button {
padding: 8px 16px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
transition: all 0.3s ease;
}
.dialog-button.primary {
background: #4299e1;
color: white;
}
.dialog-button.primary:hover {
background: #3182ce;
}
.dialog-button.secondary {
background: #e2e8f0;
color: #4a5568;
}
.dialog-button.secondary:hover {
background: #cbd5e0;
}
.product-list {
display: flex;
flex-direction: column;
gap: 12px;
margin: 20px 0;
max-height: 400px;
overflow-y: auto;
}
.product-item {
border: 2px solid #e2e8f0;
border-radius: 8px;
padding: 16px 20px;
cursor: pointer;
transition: all 0.3s ease;
background: white;
position: relative;
}
.product-item:hover {
border-color: #4299e1;
background: #f7fafc;
transform: translateX(4px);
box-shadow: 0 2px 8px rgba(66, 153, 225, 0.15);
}
.product-item.selected {
border-color: #4299e1;
background: linear-gradient(135deg, #ebf8ff 0%, #f0f9ff 100%);
box-shadow: 0 4px 12px rgba(66, 153, 225, 0.2);
}
.product-item.selected::before {
content: '✓';
position: absolute;
right: 16px;
top: 50%;
transform: translateY(-50%);
width: 24px;
height: 24px;
background: #4299e1;
color: white;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
font-size: 14px;
}
.product-item .product-title {
font-size: 16px;
font-weight: 600;
color: #2d3748;
margin-bottom: 8px;
}
.product-item .product-description {
font-size: 14px;
color: #718096;
margin-bottom: 8px;
}
.product-item .product-price {
font-size: 18px;
font-weight: bold;
color: #e53e3e;
}
.product-dialog-title {
font-size: 20px;
font-weight: bold;
color: #2d3748;
margin-bottom: 8px;
text-align: center;
}
.product-dialog-actions {
display: flex;
justify-content: flex-end;
gap: 12px;
margin-top: 20px;
padding-top: 20px;
border-top: 1px solid #e2e8f0;
}
.keep-alive-switch {
position: relative;
display: inline-block;
width: 40px;
height: 22px;
}
.keep-alive-switch input {
opacity: 0;
width: 0;
height: 0;
}
.keep-alive-slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
transition: .4s;
border-radius: 22px;
}
.keep-alive-slider:before {
position: absolute;
content: "";
height: 18px;
width: 18px;
left: 2px;
bottom: 2px;
background-color: white;
transition: .4s;
border-radius: 50%;
}
input:checked + .keep-alive-slider {
background-color: #52c41a;
}
input:checked + .keep-alive-slider:before {
transform: translateX(18px);
}
`;
const styleSheet = document.createElement("style");
styleSheet.type = "text/css";
styleSheet.innerText = styles;
document.head.appendChild(styleSheet);
const container = document.createElement('div');
container.className = 'u-helper-container';
setTimeout(() => {
container.classList.add('u-visible');
}, 100);
const titleBar = document.createElement('div');
titleBar.className = 'u-helper-title-bar';
titleBar.innerHTML = `
`;
setTimeout(() => {
const noticeBtn = document.getElementById('u-notice-btn');
if (noticeBtn) {
noticeBtn.onmouseover = () => {
noticeBtn.style.background = '#ffadd2';
noticeBtn.style.color = 'white';
};
noticeBtn.onmouseout = () => {
noticeBtn.style.background = '#fff0f6';
noticeBtn.style.color = '#eb2f96';
};
noticeBtn.onclick = (e) => {
e.stopPropagation();
e.preventDefault();
if (typeof showAnnouncement === 'function') {
showAnnouncement();
} else {
alert('公告功能正在初始化,请稍后再试...');
}
};
noticeBtn.onmousedown = (e) => e.stopPropagation();
}
}, 800);
const buttonContainer = document.createElement('div');
const minimizeButton = document.createElement('button');
minimizeButton.innerHTML = '⚊';
minimizeButton.className = 'u-helper-control-btn';
const contentContainer = document.createElement('div');
contentContainer.className = 'u-helper-content';
const { section: aiConfigSection, content: aiConfigContent } = createCollapsibleSection('🤖 AI助手', 'u-collapse-ai');
const aiToggleContainer = document.createElement('div');
aiToggleContainer.style.cssText = `
display: flex;
align-items: center;
justify-content: space-between;
padding: 12px;
background: linear-gradient(135deg, rgba(66, 153, 225, 0.1) 0%, rgba(49, 130, 206, 0.1) 100%);
border-radius: 8px;
border: 1px solid rgba(66, 153, 225, 0.2);
`;
const aiToggleLabel = document.createElement('label');
aiToggleLabel.style.cssText = `
display: flex;
align-items: center;
gap: 10px;
cursor: pointer;
font-size: 14px;
font-weight: 500;
color: var(--u-text-color-primary);
`;
const aiToggle = document.createElement('input');
aiToggle.type = 'checkbox';
aiToggle.checked = useKimiAI;
aiToggle.style.cssText = `
width: 18px;
height: 18px;
cursor: pointer;
`;
aiToggle.onchange = (e) => {
useKimiAI = e.target.checked;
localStorage.setItem('useKimiAI', useKimiAI.toString());
const statusText = aiToggleContainer.querySelector('.ai-status');
if (statusText) {
statusText.textContent = useKimiAI ? '已启用' : '已禁用';
statusText.style.color = useKimiAI ? '#10B981' : '#6B7280';
statusText.style.background = useKimiAI ? 'rgba(16, 185, 129, 0.1)' : 'rgba(107, 114, 128, 0.1)';
}
};
aiToggleLabel.appendChild(aiToggle);
aiToggleLabel.appendChild(document.createTextNode('启用 AI 答题'));
const statusIndicator = document.createElement('span');
statusIndicator.className = 'ai-status';
statusIndicator.textContent = useKimiAI ? '已启用' : '已禁用';
statusIndicator.style.cssText = `
font-size: 12px;
font-weight: 600;
color: ${useKimiAI ? '#10B981' : '#6B7280'};
padding: 4px 12px;
border-radius: 12px;
background: ${useKimiAI ? 'rgba(16, 185, 129, 0.1)' : 'rgba(107, 114, 128, 0.1)'};
`;
aiToggleContainer.appendChild(aiToggleLabel);
aiToggleContainer.appendChild(statusIndicator);
aiConfigContent.appendChild(aiToggleContainer);
const aiTip = document.createElement('div');
aiTip.style.cssText = `
margin-top: 10px;
padding: 8px 12px;
background: rgba(255, 193, 7, 0.1);
border-left: 3px solid #FFC107;
border-radius: 4px;
font-size: 12px;
color: #666;
line-height: 1.5;
`;
aiTip.innerHTML = `
💡 提示:
• 有在线题库时,答题用题库,评论用AI
• 无在线题库时,答题用AI,评论用默认文本
`;
aiConfigContent.appendChild(aiTip);
const defaultCommentContainer = document.createElement('div');
defaultCommentContainer.style.cssText = `
margin-top: 10px;
padding: 12px;
background: rgba(255, 255, 255, 0.6);
border-radius: 8px;
border: 1px solid rgba(0, 0, 0, 0.08);
`;
const defaultCommentLabel = document.createElement('div');
defaultCommentLabel.className = 'u-helper-label';
defaultCommentLabel.textContent = '默认评论文本';
defaultCommentLabel.style.marginBottom = '8px';
const defaultCommentInput = document.createElement('input');
defaultCommentInput.type = 'text';
defaultCommentInput.className = 'u-helper-input';
defaultCommentInput.style.width = '100%';
defaultCommentInput.placeholder = '输入默认评论内容(如:Hello)';
defaultCommentInput.value = localStorage.getItem('u-default-comment');
defaultCommentInput.addEventListener('input', () => {
localStorage.setItem('u-default-comment', defaultCommentInput.value);
});
const defaultCommentTip = document.createElement('div');
defaultCommentTip.style.cssText = `
margin-top: 6px;
font-size: 12px;
color: #666;
line-height: 1.4;
`;
defaultCommentTip.textContent = '当AI未启用或无在线题库时,将使用此文本作为评论内容';
defaultCommentContainer.appendChild(defaultCommentLabel);
defaultCommentContainer.appendChild(defaultCommentInput);
defaultCommentContainer.appendChild(defaultCommentTip);
aiConfigContent.appendChild(defaultCommentContainer);
const silentSubmitContainer = document.createElement('div');
silentSubmitContainer.className = 'u-helper-input-row';
silentSubmitContainer.style.marginTop = '15px';
silentSubmitContainer.style.paddingTop = '10px';
silentSubmitContainer.style.borderTop = '1px dashed #eee';
const silentSubmitLabel = document.createElement('label');
silentSubmitLabel.className = 'u-helper-label';
silentSubmitLabel.innerHTML = '⚡️ 启用高级提交 (强力)';
silentSubmitLabel.title = '开启后,AI或题库的答案将直接进行提交,跳过所有弹窗,实现满分/高分秒过。';
const silentSubmitSwitch = document.createElement('div');
silentSubmitSwitch.className = 'u-helper-switch';
silentSubmitSwitch.innerHTML = '';
const savedSilentMode = localStorage.getItem('u-silent-submit-mode') === 'true';
if (savedSilentMode) {
silentSubmitSwitch.classList.add('active');
}
silentSubmitSwitch.addEventListener('click', function() {
const isActive = this.classList.contains('active');
if (isActive) {
this.classList.remove('active');
localStorage.setItem('u-silent-submit-mode', 'false');
if (typeof unsafeWindow !== 'undefined') {
unsafeWindow.__UCAMPUS_ANSWER_CACHE__ = null;
}
console.log('🚫 高级提交已关闭,内存缓存已清除');
showRecordNotification('🚫 已关闭高级提交 (恢复普通模式)', 'info');
} else {
this.classList.add('active');
localStorage.setItem('u-silent-submit-mode', 'true');
showRecordNotification('⚡️ 已开启高级提交', 'success');
}
});
silentSubmitContainer.appendChild(silentSubmitLabel);
silentSubmitContainer.appendChild(silentSubmitSwitch);
aiConfigContent.appendChild(silentSubmitContainer);
const onlineBankSection = document.createElement('div');
onlineBankSection.style.marginTop = '10px';
const bankSelectorLabel = document.createElement('div');
bankSelectorLabel.className = 'u-helper-label';
bankSelectorLabel.textContent = '在线题库选择';
bankSelectorLabel.style.marginBottom = '8px';
const bankSelectorGroup = document.createElement('div');
bankSelectorGroup.className = 'u-helper-select-group';
const bankSelector = document.createElement('select');
bankSelector.id = 'online-bank-selector';
bankSelector.className = 'u-helper-select';
const refreshBanksBtn = document.createElement('button');
refreshBanksBtn.innerHTML = '🔄';
refreshBanksBtn.title = '刷新题库列表';
refreshBanksBtn.style.cssText = `
flex-shrink: 0; width: 36px; height: 36px; border: 1px solid var(--u-border-color);
background: #fff; border-radius: var(--u-border-radius-md); cursor: pointer;
display: flex; align-items: center; justify-content: center;
`;
bankSelectorGroup.appendChild(bankSelector);
bankSelectorGroup.appendChild(refreshBanksBtn);
onlineBankSection.appendChild(bankSelectorLabel);
onlineBankSection.appendChild(bankSelectorGroup);
const checkOnlineBankBtn = document.createElement('button');
checkOnlineBankBtn.className = 'u-helper-btn u-helper-btn-secondary';
checkOnlineBankBtn.style.marginTop = '8px';
checkOnlineBankBtn.style.fontSize = '13px';
checkOnlineBankBtn.style.padding = '6px 12px';
checkOnlineBankBtn.innerHTML = '🔍 核对在线题库与课程是否匹配';
checkOnlineBankBtn.title = '点击对比当前选中的在线题库与网页标题是否一致';
checkOnlineBankBtn.onclick = () => {
const selector = document.getElementById('online-bank-selector');
const selectedBankName = selector ? selector.value : '';
if (!selectedBankName) {
alert('❌ 你还没有选择在线题库!\n请先点击下拉框选择一个题库。');
return;
}
const breadcrumbs = document.querySelectorAll('.pc-break-crumb-text');
let pageContextText = '';
if (breadcrumbs.length >= 2) {
pageContextText = breadcrumbs[0].textContent.trim();
} else if (breadcrumbs.length === 1) {
pageContextText = breadcrumbs[0].textContent.trim();
} else {
pageContextText = document.title.split('-')[0].trim();
}
if (!pageContextText) {
alert('⚠️ 无法获取当前页面的课程名称,请确保你已进入课程学习页面。');
return;
}
const normalize = (str) => {
return str.toLowerCase()
.replace(/\.json$/i, '')
.replace(/[()()\[\]【】\s\-_]/g, '')
.replace(/第[一二三四五六七八九十\d]+版/g, '');
};
const cleanBankName = normalize(selectedBankName);
const cleanPageText = normalize(pageContextText);
console.log(`[在线核对] 题库清洗后: ${cleanBankName}`);
console.log(`[在线核对] 页面清洗后: ${cleanPageText}`);
if (cleanPageText.includes(cleanBankName) || cleanBankName.includes(cleanPageText)) {
alert(`✅ 匹配成功!\n\n在线题库:${selectedBankName}\n当前课程:${pageContextText}\n\n书名一致,可以放心使用。`);
} else {
alert(`⚠️ 警告:题库可能不匹配!\n\n🔴 你选择的:【${selectedBankName}】\n🟢 页面课程:【${pageContextText}】\n\n请检查:\n1. 教材名称是否一致?\n2. 级别/册数(如 1 vs 2)是否一致?`);
}
};
onlineBankSection.appendChild(checkOnlineBankBtn);
const multiPageStatusDiv = document.createElement('div');
multiPageStatusDiv.id = 'multi-page-status';
multiPageStatusDiv.style.cssText = `
margin-top: 10px;
padding: 8px 12px;
background-color: #f8f9fa;
border-radius: var(--u-border-radius-sm);
border-left: 3px solid #007bff;
font-size: 12px;
color: #495057;
display: none;
`;
multiPageStatusDiv.innerHTML = `
多页教材模式
状态: 未启用
进度: -
答案总数: -
`;
onlineBankSection.appendChild(multiPageStatusDiv);
const updateOnlineBankList = async () => {
const uid = localStorage.getItem('userId');
const bankSelector = document.getElementById('online-bank-selector');
if (!uid) {
bankSelector.innerHTML = '';
return;
}
bankSelector.innerHTML = '';
try {
const authorized_banks = await new Promise((resolve, reject) => {
GM_xmlhttpRequest({
method: 'POST',
url: 'https://eghome.9vvn.com/api/get-my-authorizations',
headers: { 'Content-Type': 'application/json' },
data: JSON.stringify({ uid }),
onload: res => {
const data = JSON.parse(res.responseText);
if (data.status === 'success') resolve(data.authorized_banks);
else reject(new Error(data.message));
},
onerror: err => reject(new Error('网络请求失败'))
});
});
bankSelector.innerHTML = '';
const offOption = document.createElement('option');
offOption.value = "";
offOption.textContent = "--- 关闭在线题库 ---";
bankSelector.appendChild(offOption);
if (!authorized_banks || authorized_banks.length === 0) {
const noAuthOption = document.createElement('option');
noAuthOption.value = "";
noAuthOption.textContent = "无可用题库";
noAuthOption.disabled = true;
bankSelector.appendChild(noAuthOption);
return;
}
authorized_banks.forEach(bankName => {
const option = document.createElement('option');
option.value = bankName;
option.textContent = bankName;
bankSelector.appendChild(option);
});
let pageCourseName = "";
const breadcrumbs = document.querySelectorAll('.pc-break-crumb-text');
if (breadcrumbs.length >= 1) {
pageCourseName = breadcrumbs[0].textContent.trim();
if(breadcrumbs.length >= 2 && pageCourseName.length < 4) {
pageCourseName = breadcrumbs[1].textContent.trim();
}
} else {
pageCourseName = document.title.split('-')[0].trim();
}
console.log(`[自动匹配] 当前页面课程名: "${pageCourseName}"`);
const normalize = (str) => {
return (str || '').toLowerCase()
.replace(/\.json$/i, '')
.replace(/[()()\[\]【】\s\-_]/g, '')
.replace(/第[一二三四五六七八九十\d]+版/g, '');
};
const cleanPageName = normalize(pageCourseName);
let bestMatch = null;
if (cleanPageName && cleanPageName.length > 2) {
for (const bankName of authorized_banks) {
const cleanBankName = normalize(bankName);
if (cleanPageName.includes(cleanBankName) || cleanBankName.includes(cleanPageName)) {
bestMatch = bankName;
console.log(`[自动匹配] 发现匹配题库: "${bankName}"`);
break;
}
}
}
if (bestMatch) {
bankSelector.value = bestMatch;
localStorage.setItem('selectedOnlineBank', bestMatch);
const matchTip = document.createElement('span');
matchTip.textContent = '成功';
matchTip.style.cssText = 'color: #52c41a; font-size: 12px; margin-left: 8px; font-weight: bold; transition: opacity 0.5s;';
const parent = bankSelector.parentNode;
const existingTip = parent.querySelector('span');
if(existingTip) existingTip.remove();
parent.appendChild(matchTip);
setTimeout(() => {
if (matchTip) {
matchTip.style.opacity = '0';
setTimeout(() => matchTip.remove(), 500);
}
}, 2000);
} else {
const lastSelected = localStorage.getItem('selectedOnlineBank');
if (lastSelected && authorized_banks.includes(lastSelected)) {
bankSelector.value = lastSelected;
console.log(`[自动匹配] 未找到匹配项,回退到上次选择: ${lastSelected}`);
}
}
} catch (error) {
bankSelector.innerHTML = ``;
}
};
refreshBanksBtn.onclick = updateOnlineBankList;
bankSelector.onchange = () => {
localStorage.setItem('selectedOnlineBank', bankSelector.value);
if (window.updateHighScoreLockState) window.updateHighScoreLockState();
};
setTimeout(updateOnlineBankList, 1000);
const { section: fileManagementSection, content: fileManagementContent } = createCollapsibleSection('📚 题库管理', 'u-collapse-file');
const buyBankLink = document.createElement('a');
buyBankLink.href = 'javascript:void(0)';
buyBankLink.textContent = '🛒 点我购买题库';
buyBankLink.style.cssText = 'display: block; text-align: center; margin: 10px 0; color: #4299e1; text-decoration: underline; cursor: pointer;';
buyBankLink.onclick = async () => {
let products = [];
try {
products = await new Promise((resolve, reject) => {
GM_xmlhttpRequest({
method: "GET",
url: 'https://eghome.9vvn.com/api/products',
onload: function(response) {
if (response.status === 200) {
try {
const data = JSON.parse(response.responseText);
resolve(data);
} catch (e) {
reject(new Error('解析JSON失败'));
}
} else {
reject(new Error(`HTTP error! status: ${response.status}`));
}
},
onerror: function(error) {
reject(new Error('网络请求失败'));
}
});
});
} catch (error) {
console.error("Could not fetch products:", error);
alert("无法加载题库列表,请确保API服务器正在运行。");
return;
}
let selectedProduct = null;
const dialog = document.createElement('div');
dialog.className = 'product-dialog';
const content = document.createElement('div');
content.className = 'product-dialog-content';
content.innerHTML = `
📚 选择题库
您的充值UID
${userId}
💡 支付时请备注此UID
${products.map(p => `
${p.title}
${p.description}
${p.price}
`).join('')}
未找到包含该关键词的题库
`;
dialog.appendChild(content);
document.body.appendChild(dialog);
const productItems = content.querySelectorAll('.product-item');
const confirmButton = content.querySelector('#confirmButton');
const searchInput = content.querySelector('#bankSearchInput');
const noResultTip = content.querySelector('#noResultTip');
searchInput.addEventListener('input', (e) => {
const keyword = e.target.value.toLowerCase().trim();
let hasResult = false;
productItems.forEach(item => {
const title = item.getAttribute('data-search-text');
if (title.includes(keyword)) {
item.style.display = 'block';
hasResult = true;
} else {
item.style.display = 'none';
}
});
if (noResultTip) {
noResultTip.style.display = hasResult ? 'none' : 'block';
}
});
productItems.forEach(item => {
item.addEventListener('click', () => {
productItems.forEach(i => i.classList.remove('selected'));
item.classList.add('selected');
selectedProduct = products.find(p => p.id === item.dataset.id);
confirmButton.disabled = false;
});
});
content.querySelector('#cancelButton').addEventListener('click', () => {
document.body.removeChild(dialog);
});
confirmButton.addEventListener('click', async () => {
if (!selectedProduct) return;
document.body.removeChild(dialog);
const uid = userId;
const courseName = selectedProduct.id;
const amount = selectedProduct.price.replace('¥', '');
const loadingToast = document.createElement('div');
loadingToast.textContent = '🚀 正在跳转至安全支付页面...';
loadingToast.style.cssText = 'position:fixed;top:50%;left:50%;transform:translateX(-50%);background:rgba(0,0,0,0.8);color:white;padding:15px 25px;border-radius:10px;z-index:10005;';
document.body.appendChild(loadingToast);
const payJumpUrl = `https://eghome.9vvn.com/api/payments/create-bank-order?uid=${encodeURIComponent(uid)}&courseName=${encodeURIComponent(courseName)}&amount=${amount}`;
window.open(payJumpUrl, '_blank');
setTimeout(() => {
loadingToast.remove();
alert('支付窗口已打开。支付完成后,题库权限将自动激活,您可以稍后刷新页面查看。');
}, 2000);
});
};
fileManagementContent.appendChild(buyBankLink);
fileManagementContent.appendChild(onlineBankSection);
const { section: delaySettingsContainer, content: delaySettingsContent } = createCollapsibleSection('⏱️ 自动化延迟', 'u-collapse-delay');
const answerDelayContainer = document.createElement('div');
answerDelayContainer.className = 'u-helper-input-row';
const answerDelayLabel = document.createElement('label');
answerDelayLabel.textContent = '答案填入延迟';
answerDelayLabel.className = 'u-helper-label';
const answerDelayInput = document.createElement('input');
answerDelayInput.type = 'number';
answerDelayInput.min = '100';
answerDelayInput.max = '5000';
answerDelayInput.value = localStorage.getItem('u-answer-delay') || '800';
answerDelayInput.className = 'u-helper-input';
answerDelayInput.addEventListener('change', () => {
localStorage.setItem('u-answer-delay', answerDelayInput.value);
});
const pageDelayContainer = document.createElement('div');
pageDelayContainer.className = 'u-helper-input-row';
const pageDelayLabel = document.createElement('label');
pageDelayLabel.textContent = '页面切换延迟';
pageDelayLabel.className = 'u-helper-label';
const pageDelayInput = document.createElement('input');
pageDelayInput.type = 'number';
pageDelayInput.min = '1000';
pageDelayInput.max = '10000';
pageDelayInput.value = localStorage.getItem('u-page-delay') || '3500';
pageDelayInput.className = 'u-helper-input';
pageDelayInput.addEventListener('change', () => {
localStorage.setItem('u-page-delay', pageDelayInput.value);
});
answerDelayContainer.appendChild(answerDelayLabel);
answerDelayContainer.appendChild(answerDelayInput);
pageDelayContainer.appendChild(pageDelayLabel);
pageDelayContainer.appendChild(pageDelayInput);
delaySettingsContent.appendChild(answerDelayContainer);
delaySettingsContent.appendChild(pageDelayContainer);
const keepAliveContainer = document.createElement('div');
keepAliveContainer.className = 'u-helper-input-row';
keepAliveContainer.style.marginTop = '10px';
keepAliveContainer.style.paddingTop = '10px';
keepAliveContainer.style.borderTop = '1px solid #e8e8e8';
keepAliveContainer.style.display = 'flex';
keepAliveContainer.style.justifyContent = 'space-between';
keepAliveContainer.style.alignItems = 'center';
const keepAliveLabel = document.createElement('label');
keepAliveLabel.textContent = '自动保活';
keepAliveLabel.className = 'u-helper-label';
keepAliveLabel.title = '防止学习超时,自动模拟用户活动';
const keepAliveSwitch = document.createElement('label');
keepAliveSwitch.className = 'keep-alive-switch';
const keepAliveCheckbox = document.createElement('input');
keepAliveCheckbox.type = 'checkbox';
keepAliveCheckbox.id = 'keepAliveToggle';
const keepAliveSlider = document.createElement('span');
keepAliveSlider.className = 'keep-alive-slider';
keepAliveSwitch.appendChild(keepAliveCheckbox);
keepAliveSwitch.appendChild(keepAliveSlider);
keepAliveCheckbox.addEventListener('change', () => {
keepAliveSystem.toggle();
});
keepAliveContainer.appendChild(keepAliveLabel);
keepAliveContainer.appendChild(keepAliveSwitch);
delaySettingsContent.appendChild(keepAliveContainer);
let isDragging = false;
let currentX;
let currentY;
let initialX;
let initialY;
let xOffset = 0;
let yOffset = 0;
function dragStart(e) {
if (e.type === "mousedown") {
initialX = e.clientX - xOffset;
initialY = e.clientY - yOffset;
}
isDragging = true;
}
function dragEnd(e) {
initialX = currentX;
initialY = currentY;
isDragging = false;
}
function drag(e) {
if (isDragging) {
e.preventDefault();
if (e.clientX) {
currentX = e.clientX - initialX;
currentY = e.clientY - initialY;
xOffset = currentX;
yOffset = currentY;
container.style.transform = `translate(${currentX}px, ${currentY}px)`;
}
}
}
titleBar.addEventListener('mousedown', dragStart);
document.addEventListener('mousemove', drag);
document.addEventListener('mouseup', dragEnd);
let isMinimized = false;
minimizeButton.addEventListener('click', () => {
isMinimized = !isMinimized;
if (isMinimized) {
contentContainer.classList.add('u-minimized');
} else {
contentContainer.classList.remove('u-minimized');
}
minimizeButton.innerHTML = isMinimized ? '+' : '⚊';
container.style.width = isMinimized ? 'auto' : '320px';
});
const autoSelectButton = document.createElement('button');
autoSelectButton.className = 'u-helper-btn u-helper-btn-primary';
autoSelectButton.innerHTML = '自动选择答案';
autoSelectButton.style.fontSize = '15px';
autoSelectButton.style.fontWeight = '600';
autoSelectButton.style.padding = '12px 18px';
const autoRunButton = document.createElement('button');
autoRunButton.id = 'auto-run-btn';
autoRunButton.className = 'u-helper-btn u-helper-btn-success';
autoRunButton.innerHTML = '开始挂机';
autoRunButton.style.fontSize = '15px';
autoRunButton.style.fontWeight = '600';
autoRunButton.style.padding = '12px 18px';
autoSelectButton.addEventListener('click', () => {
autoSelectAnswers();
});
autoRunButton.addEventListener('click', () => {
toggleAutoRun();
});
const addRippleEffect = (button) => {
button.addEventListener('mousedown', (e) => {
const rect = button.getBoundingClientRect();
const ripple = document.createElement('span');
ripple.className = 'u-ripple';
ripple.style.left = `${e.clientX - rect.left}px`;
ripple.style.top = `${e.clientY - rect.top}px`;
button.appendChild(ripple);
setTimeout(() => ripple.remove(), 600);
});
};
[autoSelectButton, autoRunButton].forEach(addRippleEffect);
const footerBar = document.createElement('div');
footerBar.className = 'u-helper-footer';
footerBar.innerHTML = 'By 恶搞之家';
buttonContainer.appendChild(minimizeButton);
titleBar.appendChild(buttonContainer);
contentContainer.appendChild(aiConfigSection);
contentContainer.appendChild(fileManagementSection);
contentContainer.appendChild(delaySettingsContainer);
const { section: voiceSettingsSection, content: voiceSettingsContent } = createCollapsibleSection('🎵 语音设置', 'u-collapse-voice');
const voiceToggleContainer = document.createElement('div');
voiceToggleContainer.style.cssText = `
display: flex;
align-items: center;
justify-content: space-between;
padding: 12px;
background: linear-gradient(135deg, rgba(72, 187, 120, 0.1) 0%, rgba(56, 161, 105, 0.1) 100%);
border-radius: 8px;
border: 1px solid rgba(72, 187, 120, 0.2);
margin-bottom: 12px;
`;
const voiceToggleLabel = document.createElement('label');
voiceToggleLabel.style.cssText = `
display: flex;
align-items: center;
gap: 10px;
cursor: pointer;
font-size: 14px;
font-weight: 500;
color: var(--u-text-color-primary);
`;
const voiceToggle = document.createElement('input');
voiceToggle.type = 'checkbox';
voiceToggle.checked = localStorage.getItem('autoPlayRecordEnabled') === 'true';
voiceToggle.style.cssText = `
width: 18px;
height: 18px;
cursor: pointer;
`;
voiceToggle.onchange = (e) => {
window.__autoPlayRecordEnabled = e.target.checked;
localStorage.setItem('autoPlayRecordEnabled', e.target.checked.toString());
const statusText = voiceToggleContainer.querySelector('.voice-status');
if (statusText) {
statusText.textContent = e.target.checked ? '已启用' : '已禁用';
statusText.style.color = e.target.checked ? '#10B981' : '#6B7280';
statusText.style.background = e.target.checked ? 'rgba(16, 185, 129, 0.1)' : 'rgba(107, 114, 128, 0.1)';
}
showRecordNotification(e.target.checked ? '✅ 自动录音已启用' : '⚠️ 自动录音已禁用', e.target.checked ? 'success' : 'info');
};
voiceToggleLabel.appendChild(voiceToggle);
voiceToggleLabel.appendChild(document.createTextNode('启用自动录音'));
const voiceStatusIndicator = document.createElement('span');
voiceStatusIndicator.className = 'voice-status';
voiceStatusIndicator.textContent = voiceToggle.checked ? '已启用' : '已禁用';
voiceStatusIndicator.style.cssText = `
font-size: 12px;
font-weight: 600;
color: ${voiceToggle.checked ? '#10B981' : '#6B7280'};
padding: 4px 12px;
border-radius: 12px;
background: ${voiceToggle.checked ? 'rgba(16, 185, 129, 0.1)' : 'rgba(107, 114, 128, 0.1)'};
`;
voiceToggleContainer.appendChild(voiceToggleLabel);
voiceToggleContainer.appendChild(voiceStatusIndicator);
voiceSettingsContent.appendChild(voiceToggleContainer);
const cloudScoreContainer = document.createElement('div');
cloudScoreContainer.style.cssText = `
display: flex; align-items: center; justify-content: space-between;
padding: 12px; margin-top: 10px; margin-bottom: 10px;
background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
border-radius: 8px; border: 1px solid #90caf9;
transition: all 0.3s;
`;
const cloudScoreLabel = document.createElement('label');
cloudScoreLabel.id = 'cloud-score-label-wrapper';
cloudScoreLabel.style.cssText = `display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; font-weight: bold; color: #1565c0; transition: all 0.3s;`;
const cloudScoreToggle = document.createElement('input');
cloudScoreToggle.type = 'checkbox';
cloudScoreToggle.id = 'u-cloud-score-toggle';
window.__enableOralScoreInjection = localStorage.getItem('u-cloud-score') === 'true';
cloudScoreToggle.checked = window.__enableOralScoreInjection;
cloudScoreToggle.onchange = (e) => {
window.__enableOralScoreInjection = e.target.checked;
localStorage.setItem('u-cloud-score', e.target.checked.toString());
const msg = e.target.checked ? '☁️ 高分模式已开启' : '🛑 高分模式已关闭';
showRecordNotification(msg, e.target.checked ? 'success' : 'info');
};
cloudScoreLabel.appendChild(cloudScoreToggle);
cloudScoreLabel.appendChild(document.createTextNode('高分模式🥇'));
cloudScoreContainer.appendChild(cloudScoreLabel);
voiceSettingsContent.appendChild(cloudScoreContainer);
window.updateHighScoreLockState = function() {
const toggle = document.getElementById('u-cloud-score-toggle');
const wrapper = document.getElementById('cloud-score-label-wrapper');
if (!toggle || !wrapper) return;
let rawPoints = window.userPoints;
if (rawPoints === undefined || rawPoints === null) {
rawPoints = localStorage.getItem('userPoints');
}
const currentPoints = parseInt(rawPoints || 0);
const selectedBank = localStorage.getItem('selectedOnlineBank');
const hasValidBank = selectedBank && selectedBank.trim() !== "";
console.log(`[高分模式锁状态] 当前积分: ${currentPoints}, 是否大于2: ${currentPoints > 2}`);
const canEnable = currentPoints > 2 || hasValidBank;
if (canEnable) {
toggle.disabled = false;
wrapper.style.opacity = '1';
wrapper.style.cursor = 'pointer';
wrapper.style.filter = 'none';
wrapper.title = '点击开启/关闭';
} else {
if (toggle.checked) {
toggle.checked = false;
window.__enableOralScoreInjection = false;
localStorage.setItem('u-cloud-score', 'false');
}
toggle.disabled = true;
wrapper.style.opacity = '0.5';
wrapper.style.cursor = 'not-allowed';
wrapper.style.filter = 'grayscale(100%)';
wrapper.title = `当前积分(${currentPoints})不足,需大于2分或连接题库`;
}
};
setTimeout(window.updateHighScoreLockState, 500);
const audioTypeContainer = document.createElement('div');
audioTypeContainer.style.cssText = `
display: flex;
gap: 10px;
margin-bottom: 12px;
`;
const britishBtn = document.createElement('button');
britishBtn.textContent = '🇬🇧 英音';
britishBtn.className = 'u-helper-btn u-helper-btn-secondary';
britishBtn.style.cssText = `
flex: 1;
padding: 10px;
font-size: 14px;
font-weight: 600;
transition: all 0.3s;
`;
const americanBtn = document.createElement('button');
americanBtn.textContent = '🇺🇸 美音';
americanBtn.className = 'u-helper-btn u-helper-btn-secondary';
americanBtn.style.cssText = `
flex: 1;
padding: 10px;
font-size: 14px;
font-weight: 600;
transition: all 0.3s;
`;
const selectedAudioType = localStorage.getItem('selectedAudioType') || 'british';
window.__selectedAudioType = selectedAudioType;
function updateAudioTypeButtons() {
if (window.__selectedAudioType === 'british') {
britishBtn.style.background = '#48bb78';
britishBtn.style.color = 'white';
americanBtn.style.background = '#fff';
americanBtn.style.color = 'var(--u-text-color-secondary)';
} else {
americanBtn.style.background = '#48bb78';
americanBtn.style.color = 'white';
britishBtn.style.background = '#fff';
britishBtn.style.color = 'var(--u-text-color-secondary)';
}
}
updateAudioTypeButtons();
britishBtn.addEventListener('click', () => {
window.__selectedAudioType = 'british';
localStorage.setItem('selectedAudioType', 'british');
updateAudioTypeButtons();
showRecordNotification('✅ 已选择英音', 'success');
});
americanBtn.addEventListener('click', () => {
window.__selectedAudioType = 'american';
localStorage.setItem('selectedAudioType', 'american');
updateAudioTypeButtons();
showRecordNotification('✅ 已选择美音', 'success');
});
audioTypeContainer.appendChild(britishBtn);
audioTypeContainer.appendChild(americanBtn);
voiceSettingsContent.appendChild(audioTypeContainer);
const voiceDelayContainer = document.createElement('div');
voiceDelayContainer.className = 'u-helper-input-row';
voiceDelayContainer.style.marginBottom = '12px';
const voiceDelayLabel = document.createElement('label');
voiceDelayLabel.className = 'u-helper-label';
voiceDelayLabel.textContent = '播放延迟';
const voiceDelaySelector = document.createElement('select');
voiceDelaySelector.id = 'voice-delay-selector';
voiceDelaySelector.className = 'u-helper-select';
voiceDelaySelector.style.width = '120px';
[
{ value: '500', text: '0.5秒(快速)' },
{ value: '1000', text: '1秒(推荐)' },
{ value: '1500', text: '1.5秒(稳定)' },
{ value: '2000', text: '2秒(保守)' }
].forEach(option => {
const opt = document.createElement('option');
opt.value = option.value;
opt.textContent = option.text;
voiceDelaySelector.appendChild(opt);
});
voiceDelaySelector.value = localStorage.getItem('voiceDelayTime') || '1000';
voiceDelaySelector.addEventListener('change', () => {
localStorage.setItem('voiceDelayTime', voiceDelaySelector.value);
showRecordNotification(`⏱️ 延迟时间已设置为 ${parseInt(voiceDelaySelector.value)/1000}秒`, 'info');
});
voiceDelayContainer.appendChild(voiceDelayLabel);
voiceDelayContainer.appendChild(voiceDelaySelector);
voiceSettingsContent.appendChild(voiceDelayContainer);
const recordDurationContainer = document.createElement('div');
recordDurationContainer.className = 'u-helper-input-row';
const recordDurationLabel = document.createElement('label');
recordDurationLabel.className = 'u-helper-label';
recordDurationLabel.textContent = '录音时长';
const recordDurationSelector = document.createElement('select');
recordDurationSelector.className = 'u-helper-select';
recordDurationSelector.innerHTML = `
`;
const savedRecordDuration = localStorage.getItem('u-helper-record-duration') || '3';
recordDurationSelector.value = savedRecordDuration;
window.__recordDuration = parseInt(savedRecordDuration);
recordDurationSelector.addEventListener('change', function() {
const duration = this.value;
localStorage.setItem('u-helper-record-duration', duration);
window.__recordDuration = parseInt(duration);
console.log('[录音设置] 录音时长已设置为:', duration + '秒');
});
recordDurationContainer.appendChild(recordDurationLabel);
recordDurationContainer.appendChild(recordDurationSelector);
voiceSettingsContent.appendChild(recordDurationContainer);
contentContainer.appendChild(voiceSettingsSection);
const { section: refreshSettingsSection, content: refreshSettingsContent } = createCollapsibleSection('🔄 自动刷新', 'u-collapse-refresh');
const refreshToggleContainer = document.createElement('div');
refreshToggleContainer.className = 'u-helper-input-row';
refreshToggleContainer.style.marginBottom = '12px';
const refreshToggleLabel = document.createElement('label');
refreshToggleLabel.className = 'u-helper-label';
refreshToggleLabel.textContent = '启用自动刷新';
const refreshToggleSwitch = document.createElement('div');
refreshToggleSwitch.className = 'u-helper-switch';
refreshToggleSwitch.innerHTML = '';
const savedRefreshEnabled = localStorage.getItem('u-helper-auto-refresh') === 'true';
if (savedRefreshEnabled) {
refreshToggleSwitch.classList.add('active');
autoRefreshEnabled = true;
}
refreshToggleSwitch.addEventListener('click', function() {
const isActive = this.classList.contains('active');
if (isActive) {
this.classList.remove('active');
localStorage.setItem('u-helper-auto-refresh', 'false');
stopAutoRefresh();
} else {
this.classList.add('active');
localStorage.setItem('u-helper-auto-refresh', 'true');
startAutoRefresh();
}
});
refreshToggleContainer.appendChild(refreshToggleLabel);
refreshToggleContainer.appendChild(refreshToggleSwitch);
refreshSettingsContent.appendChild(refreshToggleContainer);
const resumeRunContainer = document.createElement('div');
resumeRunContainer.className = 'u-helper-input-row';
resumeRunContainer.style.marginBottom = '12px';
resumeRunContainer.style.paddingTop = '10px';
resumeRunContainer.style.borderTop = '1px dashed #eee';
const resumeRunLabel = document.createElement('label');
resumeRunLabel.className = 'u-helper-label';
resumeRunLabel.textContent = '刷新后保持挂机';
resumeRunLabel.title = '勾选后,如果页面被刷新,脚本会自动继续执行挂机任务';
const resumeRunSwitch = document.createElement('div');
resumeRunSwitch.className = 'u-helper-switch';
resumeRunSwitch.innerHTML = '';
const savedResumeState = localStorage.getItem('u-helper-resume-after-refresh') === 'true';
if (savedResumeState) {
resumeRunSwitch.classList.add('active');
}
resumeRunSwitch.addEventListener('click', function() {
const isActive = this.classList.contains('active');
if (isActive) {
this.classList.remove('active');
localStorage.setItem('u-helper-resume-after-refresh', 'false');
showRefreshNotification('🚫 已禁用刷新后自动恢复', 'info');
} else {
this.classList.add('active');
localStorage.setItem('u-helper-resume-after-refresh', 'true');
showRefreshNotification('✅ 已启用刷新后自动恢复', 'success');
}
});
resumeRunContainer.appendChild(resumeRunLabel);
resumeRunContainer.appendChild(resumeRunSwitch);
refreshSettingsContent.appendChild(resumeRunContainer);
const refreshIntervalContainer = document.createElement('div');
refreshIntervalContainer.className = 'u-helper-input-row';
refreshIntervalContainer.style.marginBottom = '12px';
const refreshIntervalLabel = document.createElement('label');
refreshIntervalLabel.className = 'u-helper-label';
refreshIntervalLabel.textContent = '刷新间隔';
const refreshIntervalSelector = document.createElement('select');
refreshIntervalSelector.className = 'u-helper-select';
refreshIntervalSelector.innerHTML = `
`;
const savedRefreshInterval = localStorage.getItem('u-helper-refresh-interval') || '30';
refreshIntervalSelector.value = savedRefreshInterval;
window.__refreshInterval = parseFloat(savedRefreshInterval);
refreshIntervalSelector.addEventListener('change', function() {
const interval = this.value;
localStorage.setItem('u-helper-refresh-interval', interval);
window.__refreshInterval = parseFloat(interval);
let displayTime;
if (parseFloat(interval) < 1) {
displayTime = `${parseFloat(interval) * 60}秒`;
} else {
displayTime = `${interval}分钟`;
}
console.log('[自动刷新] 刷新间隔已设置为:', displayTime);
if (autoRefreshEnabled) {
startAutoRefresh();
}
showRefreshNotification(`⏱️ 刷新间隔已设置为 ${displayTime}`, 'info');
});
refreshIntervalContainer.appendChild(refreshIntervalLabel);
refreshIntervalContainer.appendChild(refreshIntervalSelector);
refreshSettingsContent.appendChild(refreshIntervalContainer);
const popupRefreshContainer = document.createElement('div');
popupRefreshContainer.className = 'u-helper-input-row';
popupRefreshContainer.style.marginBottom = '12px';
const popupRefreshLabel = document.createElement('label');
popupRefreshLabel.className = 'u-helper-label';
popupRefreshLabel.textContent = '拦截弹窗后刷新';
const popupRefreshSwitch = document.createElement('div');
popupRefreshSwitch.className = 'u-helper-switch';
popupRefreshSwitch.innerHTML = '';
const savedPopupRefresh = localStorage.getItem('u-helper-popup-refresh') === 'true';
if (savedPopupRefresh) {
popupRefreshSwitch.classList.add('active');
window.__refreshAfterPopupBlock = true;
}
popupRefreshSwitch.addEventListener('click', function() {
const isActive = this.classList.contains('active');
if (isActive) {
this.classList.remove('active');
localStorage.setItem('u-helper-popup-refresh', 'false');
window.__refreshAfterPopupBlock = false;
showRefreshNotification('🚫 已禁用弹窗拦截后刷新', 'info');
} else {
this.classList.add('active');
localStorage.setItem('u-helper-popup-refresh', 'true');
window.__refreshAfterPopupBlock = true;
showRefreshNotification('✅ 已启用弹窗拦截后刷新', 'success');
}
});
popupRefreshContainer.appendChild(popupRefreshLabel);
popupRefreshContainer.appendChild(popupRefreshSwitch);
refreshSettingsContent.appendChild(popupRefreshContainer);
contentContainer.appendChild(refreshSettingsSection);
const { section: videoSettingsSection, content: videoSettingsContent } = createCollapsibleSection('🎬 视频设置', 'u-collapse-video');
const videoSkipContainer = document.createElement('div');
videoSkipContainer.className = 'u-helper-input-row';
videoSkipContainer.style.marginBottom = '12px';
const videoSkipLabel = document.createElement('label');
videoSkipLabel.className = 'u-helper-label';
videoSkipLabel.textContent = '自动跳过视频';
const videoSkipSwitch = document.createElement('div');
videoSkipSwitch.className = 'u-helper-switch';
videoSkipSwitch.innerHTML = '';
window.__videoSkipEnabled = localStorage.getItem('u-video-skip') === 'true';
if (window.__videoSkipEnabled) {
videoSkipSwitch.classList.add('active');
}
videoSkipSwitch.addEventListener('click', function() {
const isActive = this.classList.contains('active');
if (isActive) {
this.classList.remove('active');
localStorage.setItem('u-video-skip', 'false');
window.__videoSkipEnabled = false;
console.log('[视频助手] 自动跳过已关闭');
} else {
this.classList.add('active');
localStorage.setItem('u-video-skip', 'true');
window.__videoSkipEnabled = true;
console.log('[视频助手] 自动跳过已开启');
document.querySelectorAll('video').forEach(v => {
if (!v.ended && v.duration > 0) {
v.currentTime = v.duration;
}
});
}
});
videoSkipContainer.appendChild(videoSkipLabel);
videoSkipContainer.appendChild(videoSkipSwitch);
videoSettingsContent.appendChild(videoSkipContainer);
const videoSpeedContainer = document.createElement('div');
videoSpeedContainer.className = 'u-helper-input-row';
const videoSpeedLabel = document.createElement('label');
videoSpeedLabel.className = 'u-helper-label';
videoSpeedLabel.textContent = '播放速度';
const videoSpeedSelector = document.createElement('select');
videoSpeedSelector.className = 'u-helper-select';
videoSpeedSelector.style.width = '120px';
['1.0', '1.25', '1.5', '2.0', '2.5', '3.0'].forEach(speed => {
const option = document.createElement('option');
option.value = speed;
option.textContent = `${speed}x`;
videoSpeedSelector.appendChild(option);
});
videoSpeedSelector.value = localStorage.getItem('u-video-speed') || '2.0';
videoSpeedSelector.addEventListener('change', () => {
const newSpeed = parseFloat(videoSpeedSelector.value);
localStorage.setItem('u-video-speed', newSpeed);
document.querySelectorAll('video[data-handled-by-script="true"]').forEach(v => {
v.playbackRate = newSpeed;
console.log(`[视频助手] 已将视频速度调整为 ${newSpeed}x`);
});
});
videoSpeedContainer.appendChild(videoSpeedLabel);
videoSpeedContainer.appendChild(videoSpeedSelector);
videoSettingsContent.appendChild(videoSpeedContainer);
contentContainer.appendChild(videoSettingsSection);
const { section: skipSection, content: skipContent } = createCollapsibleSection('🚫 章节过滤', 'u-collapse-skip');
if (typeof SkipManager !== 'undefined' && SkipManager.initPanel) {
SkipManager.initPanel(skipContent);
} else {
skipContent.innerHTML = '请先在脚本头部添加 SkipManager 代码
';
}
contentContainer.appendChild(skipSection);
contentContainer.appendChild(autoSelectButton);
contentContainer.appendChild(autoRunButton);
contentContainer.appendChild(footerBar);
container.appendChild(titleBar);
container.appendChild(contentContainer);
document.body.appendChild(container);
}
function processSpecialNumbering(answers) {
const result = [];
for (let i = 0; i < answers.length; i++) {
let answer = answers[i];
let lines = answer.split(/\n/).map(line => line.trim()).filter(Boolean);
let processedLines = [];
for (let j = 0; j < lines.length; j++) {
let currentLine = lines[j];
let nextLine = j + 1 < lines.length ? lines[j + 1] : '';
if (/^\d+$/.test(currentLine) && nextLine.match(/^[00][\.\、\)]/)) {
const prefix = currentLine;
const match = nextLine.match(/^[00]([\.\、\)].*)/);
if (match) {
processedLines.push(`${prefix}${match[1]}`);
j++;
} else {
processedLines.push(currentLine);
}
} else {
processedLines.push(currentLine);
}
}
result.push(processedLines.join('\n'));
}
return result;
}
function formatAnswer(answer) {
if (!answer) return '';
const lines = answer.split(/\n/).map(line => line.trim()).filter(Boolean);
return '\n' + lines.join('\n') + '\n';
}
function deduplicateAnswers(answers) {
const uniqueAnswers = new Set();
const result = [];
for (const answer of answers) {
const lowerAnswer = answer.toLowerCase();
if (!uniqueAnswers.has(lowerAnswer)) {
uniqueAnswers.add(lowerAnswer);
result.push(answer);
}
}
return result;
}
function getAnswerType(answerGroup) {
if (!answerGroup || typeof answerGroup !== 'string') return 'unknown';
const lines = answerGroup.split('\n').map(l => l.trim()).filter(Boolean);
if (lines.length === 0) return 'unknown';
const allLinesAreChoiceFormat = lines.every(line => {
const cleanedAnswer = line.replace(/^\d+[\.\、\)]+\s*/, '').trim();
return /^[A-ZА-Я](?:\s*,\s*[A-ZА-Я])*$/.test(cleanedAnswer);
});
if (allLinesAreChoiceFormat) {
return 'choice';
}
return 'fill-in';
}
function getAnswerDelay() {
const baseDelay = parseInt(localStorage.getItem('u-answer-delay') || '800');
const randomFactor = 0.8 + Math.random() * 0.4;
return Math.floor(baseDelay * randomFactor);
}
function getPageDelay() {
return parseInt(localStorage.getItem('u-page-delay') || '3500');
}
function simulateHumanBehavior(element) {
if (!element) return;
const mouseEvents = [
new MouseEvent('mouseover', { bubbles: true }),
new MouseEvent('mouseenter', { bubbles: true }),
];
const focusEvents = [
new Event('focus', { bubbles: true }),
new Event('focusin', { bubbles: true }),
];
setTimeout(() => {
mouseEvents.forEach(event => element.dispatchEvent(event));
}, Math.random() * 200);
setTimeout(() => {
focusEvents.forEach(event => element.dispatchEvent(event));
element.focus();
}, Math.random() * 200 + 100);
}
async function handleSpecialFillInQuestions() {
try {
console.log('检查特殊填空题结构...');
const scoopContainers = document.querySelectorAll('.fe-scoop');
if (!scoopContainers || scoopContainers.length === 0) {
console.log('未找到特殊填空题结构');
return false;
}
console.log(`找到 ${scoopContainers.length} 个特殊填空题`);
const directions = document.querySelector(".layout-direction-container, .abs-direction");
const directionsText = directions ? directions.textContent.trim() : '';
const availableWords = [];
const optionPlaceholders = document.querySelectorAll('.option-placeholder');
optionPlaceholders.forEach(placeholder => {
const word = placeholder.textContent.trim();
if (word) {
availableWords.push(word);
console.log('找到可用填空词:', word);
}
});
if (availableWords.length === 0) {
const wordsList = document.querySelectorAll('.words-color');
wordsList.forEach(word => {
const wordText = word.textContent.trim();
if (wordText) {
availableWords.push(wordText);
console.log('从words-color找到可用填空词:', wordText);
}
});
}
const questions = [];
scoopContainers.forEach((container, index) => {
const numberElement = container.querySelector('.question-number');
const number = numberElement ? numberElement.textContent.trim() : (index + 1).toString();
const paragraphElement = container.closest('p');
const contextText = paragraphElement ? paragraphElement.textContent.trim() : '';
questions.push({
number: number,
context: contextText,
type: 'special-fill-in',
container: container
});
});
if (questions.length === 0) {
console.log('未能提取填空题信息');
return false;
}
let prompt = `请帮我完成以下填空题。\n指示:${directionsText}\n\n`;
if (availableWords.length > 0) {
prompt += "可用词汇(答案必须从以下词汇中选择):\n";
availableWords.forEach(word => {
prompt += `- ${word}\n`;
});
prompt += "\n";
}
questions.forEach(q => {
prompt += `${q.number}. ${q.context}\n`;
});
prompt += "\n请按照以下格式回答每个题目:\n";
prompt += "1. [填空答案]\n2. [填空答案] ...\n";
if (availableWords.length > 0) {
prompt += "注意:答案必须从上面列出的可用词汇中选择。\n";
}
prompt += "注意:只需提供填空的单词或短语,无需解释。\n";
console.log('生成的AI提示:', prompt);
console.log('正在请求AI回答...');
const aiAnswer = await askKimi(prompt);
if (!aiAnswer) {
console.log('未能获取AI答案');
return false;
}
const answers = aiAnswer.split('\n').filter(line => /^\d+\./.test(line));
console.log('AI答案:', answers);
for (let i = 0; i < questions.length; i++) {
const question = questions[i];
const answerLine = answers[i];
if (!answerLine) continue;
const answer = answerLine.replace(/^\d+\.\s*/, '').trim();
console.log(`准备填写题目 ${question.number} 的答案:`, answer);
const inputSelectors = [
'.scoop-input-wrapper input',
'input',
'.comp-abs-input input',
'.input-user-answer input'
];
let input = null;
for (const selector of inputSelectors) {
input = question.container.querySelector(selector);
if (input) {
console.log(`找到填空输入框,使用选择器: ${selector}`);
break;
}
}
if (input) {
await simulateHumanBehavior(input);
input.value = answer + '\n';
console.log(`已添加换行符: ${answer}\\n`);
input.dispatchEvent(new Event('input', { bubbles: true }));
input.dispatchEvent(new Event('change', { bubbles: true }));
input.dispatchEvent(new Event('blur', { bubbles: true }));
} else {
console.log('未找到填空题输入框');
}
await new Promise(resolve => setTimeout(resolve, getAnswerDelay()));
}
return true;
} catch (error) {
console.error('处理特殊填空题时发生错误:', error);
return false;
}
}
async function parseConsoleQuestions() {
try {
await new Promise(resolve => setTimeout(resolve, 1000));
const directions = document.querySelector(".layout-direction-container, .abs-direction");
const directionsText = directions ? directions.textContent.trim() : '';
console.log('题目指示:', directionsText);
console.log('尝试从控制台输出获取题目信息');
const questions = [];
const questionContainers = [
'.question-common-abs-question-container',
'.question-wrap',
'.question-basic',
'.layoutBody-container.has-reply',
'.question-material-banked-cloze.question-abs-question'
];
let mainContainer = null;
for (const selector of questionContainers) {
const container = document.querySelector(selector);
if (container) {
mainContainer = container;
console.log(`找到题目容器: ${selector}`);
break;
}
}
if (!mainContainer) {
console.log('未找到题目容器,使用默认查询');
mainContainer = document;
}
const availableWords = [];
const optionPlaceholders = mainContainer.querySelectorAll('.option-placeholder');
optionPlaceholders.forEach(placeholder => {
const word = placeholder.textContent.trim();
if (word) {
availableWords.push(word);
console.log('找到可用填空词:', word);
}
});
const questionSelectors = [
'.question-common-abs-reply',
'.question-inputbox',
'.question',
'[class*="question"]',
'[class*="stem"]'
];
let questionElements = [];
for (const selector of questionSelectors) {
const elements = mainContainer.querySelectorAll(selector);
if (elements && elements.length > 0) {
questionElements = Array.from(elements);
console.log(`使用选择器 ${selector} 找到题目数量: ${elements.length}`);
break;
}
}
questionElements.forEach((element, index) => {
let questionText = '';
if (element.querySelector('.fe-scoop, .scoop-input-wrapper')) {
const paragraphs = element.querySelectorAll('p');
if (paragraphs.length > 0) {
questionText = Array.from(paragraphs)
.map(p => p.textContent.trim())
.join(' ');
console.log(`从段落中提取填空题文本: ${questionText.substring(0, 50)}${questionText.length > 50 ? '...' : ''}`);
}
}
if (!questionText) {
const contentSelectors = [
'.question-inputbox-header',
'.component-htmlview',
'p',
'.title',
'[class*="content"]',
'strong + span',
'.words-color'
];
for (const selector of contentSelectors) {
const contentElements = element.querySelectorAll(selector);
if (contentElements && contentElements.length > 0) {
questionText = Array.from(contentElements)
.map(el => el.textContent.trim())
.join(' ');
console.log(`使用选择器 ${selector} 找到题目文本`);
break;
}
}
}
if (!questionText) {
questionText = element.textContent.trim();
console.log('使用元素自身文本作为题目内容');
}
questionText = questionText
.replace(/\s+/g, ' ')
.replace(/^\d+\.\s*/, '')
.trim();
let number = (index + 1).toString();
const numberElement = element.querySelector('strong, [class*="number"], [class*="index"]');
if (numberElement) {
const numberMatch = numberElement.textContent.match(/\d+/);
if (numberMatch) {
number = numberMatch[0];
}
}
let type = 'unknown';
if (element.querySelector('.fe-scoop, .scoop-input-wrapper, .comp-abs-input, .input-user-answer') ||
element.classList.contains('fill-blank-reply') ||
element.querySelector('span.question-number')) {
type = 'fill-in';
console.log(`题目 ${number} 是填空题 (通过特殊类识别)`);
} else if (element.querySelector('textarea')) {
type = 'text';
console.log(`题目 ${number} 是文本题`);
} else if (element.querySelector('input[type="text"]')) {
type = 'fill-in';
console.log(`题目 ${number} 是填空题`);
} else if (element.querySelector('input[type="radio"]')) {
type = 'single-choice';
console.log(`题目 ${number} 是单选题`);
} else if (element.querySelector('input[type="checkbox"]') ||
element.querySelector('.MultipleChoice--checkbox-item-34A_-')) {
type = 'multiple-choice';
console.log(`题目 ${number} 是多选题`);
} else if (element.querySelector('ul.single-choice--options-29v2W, ul[class*="single-choice"]')) {
type = 'single-choice';
console.log(`题目 ${number} 是单选题 (普通版)`);
} else if (element.querySelector('.option-wrap, .option.isNotReview, .caption')) {
const options = element.querySelectorAll('.option-wrap, .option.isNotReview');
if (options.length > 0) {
const titleElement = element.querySelector('.ques-title, .component-htmlview.ques-title');
const titleText = titleElement ? titleElement.textContent : '';
if (titleText.includes('多选') ||
titleText.includes('所有') ||
titleText.includes('多个') ||
titleText.includes('multiple')) {
type = 'multiple-choice';
console.log(`题目 ${number} 是多选题 (通过选项和标题识别)`);
} else {
type = 'single-choice';
console.log(`题目 ${number} 是单选题 (通过选项识别)`);
}
}
} else {
const parentElement = element.parentElement;
if (parentElement && (
parentElement.querySelector('.fe-scoop') ||
parentElement.querySelector('.scoop-input-wrapper') ||
parentElement.querySelector('.comp-abs-input')
)) {
type = 'fill-in';
console.log(`题目 ${number} 是填空题 (通过父元素识别)`);
} else if (parentElement && parentElement.querySelector('.option-wrap, .option.isNotReview, .caption')) {
type = 'single-choice';
console.log(`题目 ${number} 是选择题 (通过父元素识别)`);
} else {
type = 'text';
console.log(`题目 ${number} 类型未知,默认为文本题`);
}
}
questions.push({
number: number,
text: questionText,
type: type,
element: element
});
});
let prompt = `请帮我完成以下题目。\n指示:${directionsText}\n\n`;
questions.forEach(q => {
let typeDesc = '';
switch (q.type) {
case 'single-choice':
typeDesc = '【单选题】';
break;
case 'multiple-choice':
typeDesc = '【多选题】';
break;
case 'fill-in':
typeDesc = '【填空题】';
break;
case 'text':
typeDesc = '【文本题】';
break;
default:
typeDesc = '';
}
prompt += `${q.number}. ${typeDesc}${q.text}\n`;
});
prompt += "\n请按照以下格式回答每个题目:\n";
prompt += "1. [答案]\n2. [答案] ...\n\n";
prompt += "注意事项:\n";
prompt += "- 只需提供答案,无需解释\n";
prompt += "- 单选题请直接回答选项内容,例如 'energy' 或 'future'\n";
prompt += "- 多选题请直接回答选项内容,用逗号分隔,例如 'energy, future'\n";
prompt += "- 填空题直接提供单词或短语\n";
prompt += "- 文本题提供完整句子或段落\n";
console.log('生成的AI提示:', prompt);
return {
prompt: prompt,
questions: questions
};
} catch (error) {
console.error('解析题目时发生错误:', error);
return null;
}
}
async function autoSelectAnswers() {
try {
console.log('开始自动选择答案');
const allOptions = document.querySelectorAll('.option.isNotReview, div.option');
let answeredCount = 0;
let totalQuestions = 0;
if (allOptions.length > 0) {
const firstCaption = allOptions[0]?.querySelector('.caption');
const firstLetter = firstCaption ? firstCaption.textContent.trim() : 'A';
const isSpecialType = !['A', 'B', 'C', 'D', 'E', 'F'].includes(firstLetter);
if (isSpecialType) {
totalQuestions = Math.floor(allOptions.length / 2);
} else {
totalQuestions = Array.from(allOptions).filter(opt => {
const caption = opt.querySelector('.caption');
return caption && caption.textContent.trim() === 'A';
}).length;
}
answeredCount = Array.from(allOptions).filter(opt =>
opt.classList.contains('selected') ||
opt.classList.contains('active') ||
opt.querySelector('input[type="radio"]:checked')
).length;
console.log(`📊 答题状态检查: 已答 ${answeredCount}/${totalQuestions} 题`);
if (answeredCount >= totalQuestions && totalQuestions > 0) {
console.log('✅ 所有题目已答完,跳过重复答题');
return true;
}
}
let selectedBank = document.getElementById('online-bank-selector')?.value;
if (!selectedBank) {
const stored = localStorage.getItem('selectedOnlineBank');
if (stored && stored !== "") {
selectedBank = stored;
console.log(`[防扣分机制] 界面下拉框未就绪,强制使用本地缓存配置: "${selectedBank}"`);
}
}
if (selectedBank) {
console.log(`[在线题库] 模式启动,选择的题库: "${selectedBank}"`);
const uid = localStorage.getItem('userId');
const urlIds = (window.location.hash.split('/courseware/')[1] || '').split('/').filter(Boolean);
let exerciseId = null;
const isNormalVersion = Array.from(document.scripts).some(s => /pc-release-/.test(s.src));
if (isNormalVersion) {
console.log('[版本检测] 检测为普通版');
exerciseId = urlIds.length > 1 ? urlIds[urlIds.length - 2] : urlIds[0];
} else {
console.log('[版本检测] 检测为AI版');
exerciseId = urlIds[urlIds.length - 1];
}
if (!exerciseId && urlIds.length > 0) {
exerciseId = urlIds[urlIds.length - 1];
console.log('[备用方案] 采用最后一个ID:', exerciseId);
}
const isU_G_Format = exerciseId && /u\d+g\d+$/.test(exerciseId);
const activeTask = document.querySelector('.pc-header-task-activity');
const isPracticingTask = activeTask && (activeTask.textContent || activeTask.innerText).trim() === 'Practicing';
const hasScoopSelect = document.querySelector('.fe-scoop');
const isMultiPageExercise = (isU_G_Format || isPracticingTask) && !hasScoopSelect;
if (isMultiPageExercise) {
const reason = isU_G_Format ? `ID格式 (${exerciseId})` : `Practicing任务`;
console.log(`[多页教材] 检测到多页教材模式 (原因: ${reason})`);
if (multiPageMode.exerciseId !== exerciseId) {
multiPageMode.pageIndex = 0;
multiPageMode.totalAnswers = [];
multiPageMode.isActive = true;
multiPageMode.exerciseId = exerciseId;
console.log(`[多页教材] 新练习开始,重置页面索引为 0`);
} else {
console.log(`[多页教材] 当前页面索引: ${multiPageMode.pageIndex}`);
}
} else {
if (hasScoopSelect) {
console.log(`[兼容性检测] 发现下拉框题型,已自动切换至常规填充模式以保证兼容性。`);
}
multiPageMode.isActive = false;
multiPageMode.exerciseId = null;
multiPageMode.pageIndex = 0;
multiPageMode.totalAnswers = [];
}
if (!uid) {
alert('无法获取用户UID,无法使用在线题库。');
return false;
}
if (!exerciseId) {
const userInputId = prompt('无法自动识别练习ID,请手动输入练习ID(格式如:u3g162):', 'u3g162');
if (userInputId && /^u\d+g\d+$/i.test(userInputId)) {
exerciseId = userInputId.toLowerCase();
console.log(`[在线题库] 用户手动输入ID: ${exerciseId}`);
} else {
alert('练习ID格式不正确或用户取消输入,无法查询在线题库。');
return false;
}
}
console.log(`[在线题库] 查询参数: UID=${uid}, Course=${selectedBank}, ID=${exerciseId}`);
try {
const answers = await new Promise((resolve, reject) => {
GM_xmlhttpRequest({
method: 'POST',
url: getApiUrl(API_CONFIG.ENDPOINTS.GET_ANSWERS),
headers: { 'Content-Type': 'application/json' },
data: JSON.stringify({ uid: uid, courseName: selectedBank, id: exerciseId }),
onload: res => {
const data = JSON.parse(res.responseText);
if (res.status >= 200 && res.status < 300 && data.status === 'success') {
resolve(data.answers);
} else {
reject(new Error(data.message || `服务器错误: ${res.status}`));
}
},
onerror: err => reject(new Error('网络请求失败'))
});
});
console.log('[在线题库] 获取到答案:', answers);
console.log('[在线题库] 答案类型:', typeof answers, '是否为数组:', Array.isArray(answers));
if (Array.isArray(answers) && answers.length > 0) {
const isSilentMode = localStorage.getItem('u-silent-submit-mode') === 'true';
if (isSilentMode) {
const formattedForInterceptor = {
children: answers.map(ans => {
return { value: Array.isArray(ans) ? ans : [ans] };
})
};
unsafeWindow.__UCAMPUS_ANSWER_CACHE__ = formattedForInterceptor;
showRecordNotification('⚡️ 答案已就绪 (将在提交时自动修正)', 'success');
} else {
unsafeWindow.__UCAMPUS_ANSWER_CACHE__ = null;
}
}
if (!Array.isArray(answers)) {
console.error('[在线题库] 错误:服务器返回的answers不是数组!', answers);
alert('题库数据格式错误,请检查服务器返回的数据。');
return false;
}
if (isMultiPageExercise) {
if (multiPageMode.totalAnswers.length === 0) {
multiPageMode.totalAnswers = [...answers];
console.log(`[多页教材] 存储了 ${answers.length} 个答案供后续使用`);
}
updateMultiPageStatus();
const currentPageQuestionCount = getCurrentPageQuestionCount();
console.log(`[多页教材] 当前页面检测到 ${currentPageQuestionCount} 个题目`);
const startIndex = multiPageMode.pageIndex;
const endIndex = startIndex + currentPageQuestionCount;
const currentPageAnswers = multiPageMode.totalAnswers.slice(startIndex, endIndex);
if (currentPageAnswers.length > 0) {
console.log(`[多页教材] 使用第 ${startIndex + 1} 到第 ${endIndex} 个答案:`, currentPageAnswers);
await fillAnswersForMultiPage(currentPageAnswers);
multiPageMode.pageIndex += currentPageQuestionCount;
console.log(`[多页教材] ✅ 答题完成,页面索引已更新为: ${multiPageMode.pageIndex}`);
console.log(`[多页教材] 下次答题将从第 ${multiPageMode.pageIndex + 1} 个答案开始`);
updateMultiPageStatus();
} else {
console.warn(`[多页教材] 页面索引 ${multiPageMode.pageIndex} 超出答案数组范围 (${multiPageMode.totalAnswers.length})`);
return false;
}
} else {
await fillAnswersFromArray(answers);
}
return true;
} catch (error) {
alert(`[在线题库] 查询失败: ${error.message}`);
return false;
}
}
console.log('AI状态:', { useKimiAI });
if (useKimiAI) {
const specialFillInResult = await handleSpecialFillInQuestions();
if (specialFillInResult) {
console.log('已成功处理特殊填空题');
return true;
}
}
if (useKimiAI) {
console.log('使用AI模式答题');
const questionInfo = await parseConsoleQuestions();
if (!questionInfo) {
console.log('无法获取题目信息');
return false;
}
console.log('正在请求AI回答...');
const aiAnswer = await askKimi(questionInfo.prompt);
if (!aiAnswer) {
console.log('未能获取AI答案');
return false;
}
let answers = [];
const lineAnswers = aiAnswer.split('\n').filter(line => /^\d+\./.test(line.trim()));
if (lineAnswers.length > 0) {
answers = lineAnswers.map(line => line.replace(/^\d+\.\s*/, '').trim());
} else {
const commaAnswers = aiAnswer.split(/,\s*/).filter(part => /^\d+\./.test(part.trim()));
if (commaAnswers.length > 0) {
answers = commaAnswers.map(part => part.replace(/^\d+\.\s*/, '').trim());
} else {
answers = [aiAnswer.trim()];
}
}
console.log('AI答案(解析后):', answers);
console.log('题目数量:', questionInfo.questions.length);
if (answers && answers.length > 0) {
const isSilentMode = localStorage.getItem('u-silent-submit-mode') === 'true';
if (isSilentMode) {
const formattedForInterceptor = {
children: answers.map(ans => ({ value: [ans] }))
};
unsafeWindow.__UCAMPUS_ANSWER_CACHE__ = formattedForInterceptor;
} else {
unsafeWindow.__UCAMPUS_ANSWER_CACHE__ = null;
}
}
console.log('📝 开始逐题处理模式(支持混合题型)...');
await new Promise(resolve => setTimeout(resolve, 500));
for (let i = 0; i < questionInfo.questions.length; i++) {
try {
const question = questionInfo.questions[i];
const answerLine = answers[i] || (i < answers.length ? answers[i] : '');
if (!answerLine) {
console.log(`题目 ${i + 1} 没有对应答案,跳过`);
continue;
}
const answer = String(answerLine).replace(/^\d+\.\s*/, '').trim();
console.log(`准备填写题目 ${question.number} 的答案:`, answer);
await new Promise(resolve => setTimeout(resolve, 200 + Math.random() * 300));
const questionElement = question.element;
if (!questionElement) {
console.log(`题目 ${question.number} 没有找到对应的DOM元素`);
continue;
}
if (question.type === 'fill-in') {
const inputSelectors = [
'input.fill-blank--bc-input-DelG1',
'input[type="text"]',
'.comp-abs-input input',
'.input-user-answer input',
'.scoop-input-wrapper input',
'.fe-scoop input',
'input'
];
let input = null;
for (const selector of inputSelectors) {
input = questionElement.querySelector(selector);
if (input) {
console.log(`找到填空输入框,使用选择器: ${selector}`);
break;
}
}
if (input) {
console.log(`填写填空题答案: ${answer}`);
await simulateHumanBehavior(input);
input.value = answer + '\n';
console.log(`已添加换行符: ${answer}\\n`);
input.dispatchEvent(new Event('input', { bubbles: true }));
input.dispatchEvent(new Event('change', { bubbles: true }));
input.dispatchEvent(new Event('blur', { bubbles: true }));
const submitButton = findSubmitButton(questionElement);
if (submitButton) {
console.log('找到提交按钮,点击提交');
await new Promise(resolve => setTimeout(resolve, 300));
submitButton.click();
}
} else {
console.log('未找到填空题输入框');
}
} else if (question.type === 'text') {
const textareaSelectors = [
'textarea.writing--textarea-36VPs',
'textarea.scoopFill_textarea',
'textarea.question-inputbox-input',
'textarea.question-textarea-content',
'textarea',
'.question-inputbox-input-container textarea',
'.question-inputbox-body textarea'
];
let textarea = null;
for (const selector of textareaSelectors) {
textarea = questionElement.querySelector(selector);
if (textarea) break;
}
if (textarea) {
console.log(`找到文本框,填写答案: ${answer.substring(0, 20)}${answer.length > 20 ? '...' : ''}`);
await simulateHumanBehavior(textarea);
const typeText = async (text, element) => {
const delay = () => Math.floor(Math.random() * 30) + 10;
element.value = '';
element.dispatchEvent(new Event('input', { bubbles: true }));
let currentText = '';
for (let i = 0; i < text.length; i++) {
await new Promise(resolve => setTimeout(resolve, delay()));
currentText += text[i];
element.value = currentText;
element.dispatchEvent(new Event('input', { bubbles: true }));
}
currentText += '\n';
element.value = currentText;
console.log(`已添加换行符: ${text}\\n`);
element.dispatchEvent(new Event('input', { bubbles: true }));
element.dispatchEvent(new Event('change', { bubbles: true }));
};
await typeText(answer, textarea);
} else {
console.log('未找到文本框元素');
}
} else if (question.type === 'single-choice') {
console.log('处理单选题,答案:', answer);
const cleanAnswer = answer.trim();
console.log('清理后的答案:', cleanAnswer);
let targetOption = null;
let targetLetter = null;
let foundByText = false;
const isClassicVersion = questionElement.querySelector('ul.single-choice--options-29v2W, ul[class*="single-choice"]');
let optionsArray = [];
const isSingleLetter = cleanAnswer.length === 1 && /^[A-Za-z]$/.test(cleanAnswer);
if (isClassicVersion) {
console.log('检测到普通U校园版题目结构');
const optionsList = questionElement.querySelectorAll('ul[class*="single-choice"] li label');
optionsArray = Array.from(optionsList);
if (isSingleLetter) {
const letter = cleanAnswer.toUpperCase();
console.log(`答案是单个字母 "${letter}",优先通过字母匹配`);
for (const label of optionsArray) {
const indexSpan = label.querySelector('span[class*="index"]');
if (indexSpan && indexSpan.textContent.trim().replace('.', '') === letter) {
targetOption = label.querySelector('input[type="radio"]');
targetLetter = letter;
console.log(`✅ 通过选项字母找到选项 ${letter}`);
break;
}
}
}
if (!targetOption) {
const cleanAnswerLower = cleanAnswer.toLowerCase();
for (let i = 0; i < optionsArray.length; i++) {
const label = optionsArray[i];
const input = label.querySelector('input[type="radio"]');
const indexSpan = label.querySelector('span[class*="index"]');
const contentDiv = label.querySelector('div.html-view[class*="content"]');
if (input && indexSpan && contentDiv) {
const letter = indexSpan.textContent.trim().replace('.', '');
const contentText = contentDiv.textContent.trim().toLowerCase();
console.log(`选项 ${letter}: "${contentText.substring(0, 30)}..."`);
if (cleanAnswerLower.length > 1 && (contentText === cleanAnswerLower || contentText.includes(cleanAnswerLower))) {
targetOption = input;
targetLetter = letter;
foundByText = true;
console.log(`找到匹配的选项 ${letter}: "${contentText.substring(0, 30)}..."`);
break;
}
}
}
}
} else {
const options = questionElement.querySelectorAll('.option.isNotReview');
optionsArray = Array.from(options);
if (isSingleLetter) {
const letter = cleanAnswer.toUpperCase();
console.log(`答案是单个字母 "${letter}",优先通过字母匹配`);
for (const option of optionsArray) {
const caption = option.querySelector('.caption');
if (caption && caption.textContent.trim() === letter) {
targetOption = option;
targetLetter = letter;
console.log(`✅ 通过选项字母找到选项 ${letter}`);
break;
}
}
}
if (!targetOption) {
const cleanAnswerLower = cleanAnswer.toLowerCase();
for (let i = 0; i < optionsArray.length; i++) {
const option = optionsArray[i];
const content = option.querySelector('.component-htmlview.content');
const caption = option.querySelector('.caption');
if (content && caption) {
const contentText = content.textContent.trim().toLowerCase();
const letter = caption.textContent.trim();
console.log(`选项 ${letter}: "${contentText.substring(0, 30)}..."`);
if (cleanAnswerLower.length > 1 && (contentText === cleanAnswerLower || contentText.includes(cleanAnswerLower))) {
targetOption = option;
targetLetter = letter;
foundByText = true;
console.log(`找到匹配的选项 ${letter}: "${contentText.substring(0, 30)}..."`);
break;
}
}
}
}
}
if (targetOption && targetLetter) {
console.log(`✅ 准备点击选项 ${targetLetter} (${foundByText ? '通过文本匹配' : '通过字母匹配'})`);
await simulateHumanBehavior(targetOption);
if (isClassicVersion && targetOption.tagName === 'INPUT') {
console.log('普通版:直接选中 radio 按钮');
targetOption.checked = true;
targetOption.dispatchEvent(new Event('change', { bubbles: true }));
targetOption.dispatchEvent(new Event('click', { bubbles: true }));
} else {
targetOption.click();
}
console.log(`✅ 已选中选项 ${targetLetter}`);
const submitButton = findSubmitButton(questionElement);
if (submitButton) {
console.log('找到提交按钮,点击提交');
await new Promise(resolve => setTimeout(resolve, 300));
submitButton.click();
}
} else {
console.log(`❌ 未找到匹配的选项: ${cleanAnswer}`);
}
} else if (question.type === 'multiple-choice') {
console.log('处理多选题,答案:', answer);
let options = questionElement.querySelectorAll('.option.isNotReview');
console.log('AI版选项数量:', options.length);
if (options.length === 0) {
options = questionElement.querySelectorAll('.MultipleChoice--checkbox-item-34A_-');
console.log('普通版选项容器数量:', options.length);
if (options.length === 0) {
options = questionElement.querySelectorAll('input[type="checkbox"]');
console.log('复选框数量:', options.length);
}
}
const optionsArray = Array.from(options);
console.log('最终选项数组长度:', optionsArray.length);
const foundOptions = [];
let answerString = answer;
if (Array.isArray(answer)) {
answerString = answer.join(',');
} else if (typeof answer === 'object') {
answerString = JSON.stringify(answer);
}
console.log('处理后的答案字符串:', answerString);
const letterMatches = answerString.match(/[A-Z]/gi);
if (letterMatches && letterMatches.length > 0) {
console.log('检测到选项字母答案:', letterMatches);
for (const option of optionsArray) {
let caption, letter, text;
caption = option.querySelector('.caption');
if (caption) {
letter = caption.textContent.trim();
text = option.querySelector('.component-htmlview.content')?.textContent.trim() || '';
} else {
const optLabel = option.querySelector('.MultipleChoice--checkbox-opt-2F4xY');
if (optLabel) {
letter = optLabel.textContent.trim().replace('.', '');
text = option.querySelector('.html-view')?.textContent.trim() || '';
} else if (option.type === 'checkbox') {
letter = option.value;
const label = option.closest('label') || option.parentElement.querySelector('label');
text = label ? label.textContent.trim() : '';
}
}
console.log(`检查选项 - 字母: "${letter}", 文本: "${text ? text.substring(0, 30) : 'null'}"`);
if (letter && letterMatches.includes(letter.toUpperCase())) {
foundOptions.push({
option: option,
letter: letter,
text: text
});
console.log(`✓ 找到字母匹配的选项 ${letter}`);
}
}
}
if (foundOptions.length === 0) {
let answerForTextMatch = answerString;
const answerParts = answerForTextMatch.split(/[,,、;;\s]+/).filter(part => part.trim().length > 0);
console.log('答案拆分为多个部分:', answerParts);
for (let i = 0; i < optionsArray.length; i++) {
const option = optionsArray[i];
let content, caption, contentText, letter;
content = option.querySelector('.component-htmlview.content');
caption = option.querySelector('.caption');
if (content && caption) {
contentText = content.textContent.trim().toLowerCase();
letter = caption.textContent.trim();
} else {
const optLabel = option.querySelector('.MultipleChoice--checkbox-opt-2F4xY');
const htmlView = option.querySelector('.html-view');
if (optLabel && htmlView) {
letter = optLabel.textContent.trim().replace('.', '');
contentText = htmlView.textContent.trim().toLowerCase();
} else if (option.type === 'checkbox') {
letter = option.value;
const label = option.closest('label') || option.parentElement.querySelector('label');
contentText = label ? label.textContent.trim().toLowerCase() : '';
}
}
if (contentText && letter) {
console.log(`选项 ${letter}: "${contentText}"`);
for (const part of answerParts) {
const cleanPart = part.trim().toLowerCase();
if (contentText === cleanPart || contentText.includes(cleanPart) || cleanPart.includes(contentText)) {
foundOptions.push({
option: option,
letter: letter,
text: contentText
});
console.log(`找到文本匹配的选项 ${letter}: "${contentText}"`);
break;
}
}
}
}
}
if (foundOptions.length > 0) {
console.log(`找到 ${foundOptions.length} 个匹配的选项`);
for (const option of optionsArray) {
if (option.classList.contains('selected')) {
option.click();
await new Promise(resolve => setTimeout(resolve, 100));
}
}
for (const found of foundOptions) {
console.log(`准备点击选项 ${found.letter}: "${found.text}"`);
await simulateHumanBehavior(found.option);
if (found.option.type === 'checkbox') {
found.option.checked = true;
found.option.dispatchEvent(new Event('change', { bubbles: true }));
found.option.dispatchEvent(new Event('click', { bubbles: true }));
} else {
const checkbox = found.option.querySelector('input[type="checkbox"]');
if (checkbox) {
checkbox.checked = true;
checkbox.dispatchEvent(new Event('change', { bubbles: true }));
checkbox.dispatchEvent(new Event('click', { bubbles: true }));
} else {
found.option.click();
}
}
console.log(`已点击选项 ${found.letter}`);
await new Promise(resolve => setTimeout(resolve, Math.random() * 300 + 100));
}
const submitButton = findSubmitButton(questionElement);
if (submitButton) {
console.log('找到提交按钮,点击提交');
await new Promise(resolve => setTimeout(resolve, 300));
submitButton.click();
}
} else {
console.log('未找到匹配的选项:', answer);
}
}
await new Promise(resolve => setTimeout(resolve, getAnswerDelay()));
} catch (questionError) {
console.error(`处理题目 ${i + 1} 时发生错误:`, questionError.message);
console.log('继续处理下一道题...');
}
}
console.log('✅ AI答题循环完成');
return true;
}
const contentInfo = await getContentInfo();
if (!contentInfo || !contentInfo.answers || contentInfo.answers.length === 0) {
console.log('%c未找到匹配的答案,可能为主观题,将自动跳过。', 'color: #f44336; font-weight: bold;');
return false;
}
if (contentInfo.activeTopicName !== lastActiveTopicName) {
currentTopicUsedAnswers.clear();
lastActiveTopicName = contentInfo.activeTopicName;
console.log('%c检测到主题切换,已重置答案使用记录', 'color: #2196F3;');
}
const textareas = document.querySelectorAll('textarea.question-inputbox-input');
if (textareas && textareas.length > 0) {
console.log('%c检测到文本框题,开始自动填写答案', 'color: #4CAF50; font-weight: bold;');
let selectedAnswer = null;
for (const answer of contentInfo.answers) {
if (getAnswerType(answer) === 'fill-in' && !currentTopicUsedAnswers.has(answer)) {
selectedAnswer = answer;
currentTopicUsedAnswers.add(answer);
console.log('%c使用新答案组 (文本题型)', 'color: #2196F3;', answer);
break;
}
}
if (!selectedAnswer) {
for (const answer of contentInfo.answers) {
if (getAnswerType(answer) === 'fill-in') {
selectedAnswer = answer;
console.log('%c所有文本题答案组都已使用,将重用第一组匹配的答案', 'color: #FFA500;');
break;
}
}
}
if (!selectedAnswer) {
console.log('%c未找到适用于当前文本题的答案组。', 'color: #f44336;');
return false;
}
const answerMatches = selectedAnswer.match(/\d+[\.\、\) ][\s\S]*?(?=\d+[\.\、\) ]|$)/g);
if (!answerMatches) {
console.log('%c无法解析答案格式', 'color: #f44336;');
return false;
}
for (let index = 0; index < textareas.length; index++) {
const textarea = textareas[index];
try {
if (answerMatches[index]) {
const rawAnswer = answerMatches[index]
.replace(/^\d+[\.\、\) ]\s*/, '')
.trim();
const parts = rawAnswer.split('|||');
let answer = '';
let answerType = '';
if (parts.length > 1) {
answer = parts[0].trim();
answerType = '填空题';
} else {
answer = parts[0].trim();
answerType = '文本题';
}
await new Promise(resolve => {
setTimeout(() => {
simulateHumanBehavior(textarea);
let currentText = '';
const answerText = answer + '\n';
let charIndex = 0;
const typeNextChar = () => {
if (charIndex < answerText.length) {
currentText += answerText.charAt(charIndex);
textarea.value = currentText;
textarea.dispatchEvent(new Event('input', { bubbles: true }));
const typingDelay = 30 + Math.random() * 80;
charIndex++;
setTimeout(typeNextChar, typingDelay);
} else {
textarea.dispatchEvent(new Event('change', { bubbles: true }));
textarea.dispatchEvent(new Event('blur', { bubbles: true }));
resolve();
}
};
typeNextChar();
}, getAnswerDelay() + index * 500);
});
console.log(`%c第 ${index + 1} 题 (${answerType}) 已填写答案: ${answer}`, 'color: #2196F3;');
} else {
console.log(`%c第 ${index + 1} 题未找到对应答案`, 'color: #f44336;');
}
} catch (error) {
console.error(`填写第 ${index + 1} 题时发生错误:`, error);
}
}
return true;
}
const fillInBlanks = document.querySelectorAll('.fe-scoop');
if (fillInBlanks && fillInBlanks.length > 0) {
console.log('%c检测到填空题,开始自动填写答案', 'color: #4CAF50; font-weight: bold;');
let selectedAnswer = null;
for (const answer of contentInfo.answers) {
if (getAnswerType(answer) === 'fill-in' && !currentTopicUsedAnswers.has(answer)) {
selectedAnswer = answer;
currentTopicUsedAnswers.add(answer);
console.log('%c使用新答案组 (填空题型)', 'color: #2196F3;', answer);
break;
}
}
if (!selectedAnswer) {
for (const answer of contentInfo.answers) {
if (getAnswerType(answer) === 'fill-in') {
selectedAnswer = answer;
console.log('%c所有填空题答案组都已使用,将重用第一组匹配的答案', 'color: #FFA500;');
break;
}
}
}
if (!selectedAnswer) {
console.log('%c未找到适用于当前填空题的答案组。', 'color: #f44336;');
return false;
}
const answerLines = selectedAnswer.split('\n').map(line => line.trim()).filter(Boolean);
if (!answerLines || answerLines.length === 0) {
console.log('%c无法解析答案格式', 'color: #f44336;');
return false;
}
const fillInAnswers = answerLines.map(line => {
return line.replace(/^\d+[\.\、\) ]\s*/, '').trim();
}).filter(answer => {
return !/^[A-Z]$/.test(answer);
});
if (fillInAnswers.length < fillInBlanks.length) {
console.log(`%c警告:找到的填空答案数量 (${fillInAnswers.length}) 少于页面空格数量 (${fillInBlanks.length})。`, 'color: #FFA500;');
}
for (let index = 0; index < fillInBlanks.length; index++) {
const blank = fillInBlanks[index];
try {
const inputContainer = blank.querySelector('.comp-abs-input');
const input = inputContainer ? inputContainer.querySelector('input') : null;
if (input && fillInAnswers[index]) {
const rawAnswer = fillInAnswers[index];
const answer = rawAnswer.split('|||')[0].trim();
await new Promise(resolve => {
setTimeout(() => {
simulateHumanBehavior(input);
let currentText = '';
const answerText = answer + '\n';
let charIndex = 0;
const typeNextChar = () => {
if (charIndex < answerText.length) {
currentText += answerText.charAt(charIndex);
input.value = currentText;
input.dispatchEvent(new Event('input', { bubbles: true }));
const typingDelay = 30 + Math.random() * 80;
charIndex++;
setTimeout(typeNextChar, typingDelay);
} else {
input.dispatchEvent(new Event('change', { bubbles: true }));
input.dispatchEvent(new Event('blur', { bubbles: true }));
resolve();
}
};
typeNextChar();
}, getAnswerDelay() + index * 500);
});
console.log(`%c第 ${index + 1} 题已填写答案: ${answer}`, 'color: #2196F3;');
} else {
console.log(`%c第 ${index + 1} 题未找到输入框或有效答案`, 'color: #f44336;');
}
} catch (error) {
console.error(`填写第 ${index + 1} 题时发生错误:`, error);
}
}
return true;
}
const matchingWrapper = document.querySelector('#sortableListWrapper');
if (matchingWrapper) {
console.log('%c检测到匹配/排序题,开始自动填写答案', 'color: #4CAF50; font-weight: bold;');
const iframe = document.querySelector('iframe#pc-sequence-iframe');
const doc = iframe ? (iframe.contentDocument || iframe.contentWindow.document) : document;
const inputs = doc.querySelectorAll('input[type="text"], input.answer-item-input');
if (!inputs || inputs.length === 0) {
console.log('%c在此类匹配题中未找到输入框。', 'color: #f44336;');
return false;
}
let selectedAnswer = null;
for (const answer of contentInfo.answers) {
if (!currentTopicUsedAnswers.has(answer)) {
selectedAnswer = answer;
currentTopicUsedAnswers.add(answer);
console.log('%c使用新答案组', 'color: #2196F3;', answer);
break;
}
}
if (!selectedAnswer) {
console.log('%c所有答案组都已使用,将重用第一组答案', 'color: #FFA500;');
selectedAnswer = contentInfo.answers[0];
}
const answerMatches = selectedAnswer.match(/\d+[\.\、\)]\s*[A-Z]/g);
if (!answerMatches) {
console.log('%c无法解析匹配题答案格式 (e.g., "1) D 2) C ...")', 'color: #f44336;');
return false;
}
const answers = answerMatches.map(ans => ans.replace(/\d+[\.\、\)]\s*/, '').trim());
for (let index = 0; index < inputs.length; index++) {
const input = inputs[index];
if (answers[index]) {
await new Promise(resolve => {
setTimeout(() => {
simulateHumanBehavior(input);
input.value = answers[index];
input.dispatchEvent(new Event('input', { bubbles: true }));
setTimeout(() => {
input.dispatchEvent(new Event('blur', { bubbles: true }));
resolve();
}, 100 + Math.random() * 200);
}, getAnswerDelay() + index * 400);
});
console.log(`%c匹配题 ${index + 1} 已填写答案: ${answers[index]}`, 'color: #2196F3;');
}
}
return true;
}
const choiceContainer = document.querySelector('.question-common-abs-choice');
const optionDivs = document.querySelectorAll('div.option');
if (!choiceContainer && (!optionDivs || optionDivs.length === 0)) {
console.log('%c当前页面既不是选择题也不是填空题也不是文本框题', 'color: #f44336; font-weight: bold;');
return false;
}
const questions = choiceContainer
? document.querySelectorAll('.question-common-abs-reply')
: document.querySelectorAll('.question-common-abs-banked-cloze');
if (!questions || questions.length === 0) {
console.log('%c未找到题目', 'color: #f44336; font-weight: bold;');
return false;
}
console.log('%c开始自动选择答案', 'color: #4CAF50; font-weight: bold;');
let selectedAnswer = null;
for (const answer of contentInfo.answers) {
if (getAnswerType(answer) === 'choice' && !currentTopicUsedAnswers.has(answer)) {
selectedAnswer = answer;
currentTopicUsedAnswers.add(answer);
console.log('%c使用新答案组 (选择题型)', 'color: #2196F3;', answer);
break;
}
}
if (!selectedAnswer) {
for (const answer of contentInfo.answers) {
if (getAnswerType(answer) === 'choice') {
selectedAnswer = answer;
console.log('%c所有选择题答案组都已使用,将重用第一组匹配的答案', 'color: #FFA500;');
break;
}
}
}
if (!selectedAnswer) {
console.log('%c未找到适用于当前选择题的答案组。', 'color: #f44336;');
return false;
}
for (let questionIndex = 0; questionIndex < questions.length; questionIndex++) {
const question = questions[questionIndex];
await new Promise(resolve => setTimeout(resolve,
getAnswerDelay() * (1 + questionIndex * 0.5) + Math.random() * 300));
const options = choiceContainer
? question.querySelectorAll('.option.isNotReview')
: question.querySelectorAll('div.option');
if (!options || options.length === 0) {
console.log(`%c第 ${questionIndex + 1} 题未找到选项`, 'color: #f44336;');
continue;
}
const answerPattern = /(\d+)[\.\、\)]\s*([A-K](?:\s*,\s*[A-K])*)/g;
const answers = [];
let match;
answerPattern.lastIndex = 0;
while ((match = answerPattern.exec(selectedAnswer)) !== null) {
const questionNum = parseInt(match[1]);
const answerChoices = match[2].split(/\s*,\s*/);
answers[questionNum - 1] = answerChoices;
}
if (answers.length > 0 && questionIndex < answers.length) {
const answerChoices = answers[questionIndex];
if (answerChoices && answerChoices.length > 0) {
console.log(`%c第 ${questionIndex + 1} 题检测到答案: ${answerChoices.join(', ')}`, 'color: #2196F3;');
for (let letterIndex = 0; letterIndex < answerChoices.length; letterIndex++) {
const letter = answerChoices[letterIndex];
let targetOption = null;
for (let i = 0; i < options.length; i++) {
const caption = options[i].querySelector('.caption');
if (caption && caption.textContent.trim() === letter) {
targetOption = options[i];
break;
}
}
if (targetOption) {
await new Promise(resolve => {
setTimeout(() => {
const isSelected = targetOption.classList.contains('selected');
if (!isSelected) {
targetOption.dispatchEvent(new MouseEvent('mouseover', { bubbles: true }));
setTimeout(() => {
targetOption.click();
console.log(`%c第 ${questionIndex + 1} 题已选择选项 ${letter}`, 'color: #2196F3;');
setTimeout(resolve, 100 + Math.random() * 200);
}, 100 + Math.random() * 300);
} else {
console.log(`%c第 ${questionIndex + 1} 题选项 ${letter} 已经被选中`, 'color: #FFA500;');
resolve();
}
}, getAnswerDelay() + letterIndex * 200);
});
} else {
console.log(`%c第 ${questionIndex + 1} 题未找到选项 ${letter}`, 'color: #f44336;');
}
}
} else {
console.log(`%c第 ${questionIndex + 1} 题未找到答案`, 'color: #f44336;');
}
} else {
console.log(`%c第 ${questionIndex + 1} 题未找到答案`, 'color: #f44336;');
}
}
return true;
} catch (error) {
console.error('自动选择答案时发生错误:', error);
return false;
}
}
async function getContentInfo() {
try {
const breadcrumbs = document.querySelectorAll('.ant-breadcrumb-link span');
const navigationPath = Array.from(breadcrumbs).map(span => span.textContent.trim());
const chapterContent = navigationPath.length >= 2 ? navigationPath[1] : '未找到章节内容';
const topicElement = document.querySelector(".pc-header-tasks-container .pc-task.pc-header-task-activity");
const topicElementSecond = document.querySelector(".pc-header-tasks-container .pc-task.pc-header-task-activity.pc-task-last");
const topicFirstPart = topicElement ? topicElement.textContent.trim() : '';
const topicSecondPart = topicElementSecond ? topicElementSecond.textContent.trim() : '';
const topicContent = [topicFirstPart, topicSecondPart].filter(Boolean).join(' : ');
const finalTopicContent = topicContent || '未找到主题内容';
const tabContainer = document.querySelector('.pc-tab-container');
const allTopics = tabContainer ? tabContainer.querySelectorAll('.ant-col') : [];
const totalTopics = allTopics.length;
const allTopicNames = [];
allTopics.forEach((topic, index) => {
const topicDiv = topic.querySelector('.pc-tab-view-container');
if (topicDiv) {
const isActive = topic.classList.contains('pc-header-tab-activity');
allTopicNames.push({
index: index + 1,
name: topicDiv.textContent.trim(),
isActive: isActive
});
}
});
let activeTopicName = '';
let nextTopicName = '';
let foundActive = false;
for (let i = 0; i < allTopicNames.length; i++) {
if (foundActive) {
nextTopicName = allTopicNames[i].name;
break;
}
if (allTopicNames[i].isActive) {
activeTopicName = allTopicNames[i].name;
foundActive = true;
}
}
console.log('%c当前页面信息', 'color: #2196F3; font-weight: bold; font-size: 14px;');
console.log('导航路径:', navigationPath);
console.log('章节内容:', chapterContent);
console.log('主题内容:', finalTopicContent);
console.log('主题总数:', totalTopics);
console.log('当前选中的主题:', activeTopicName || '未找到选中的主题');
console.log('下一个主题:', nextTopicName || '没有下一个主题');
console.log('\n%c所有主题列表', 'color: #2196F3; font-weight: bold; font-size: 14px;');
allTopicNames.forEach(topic => {
console.log(`${topic.index}. ${topic.name} ${topic.isActive ? '(当前选中)' : ''}`);
});
return {
chapter: chapterContent,
topic: finalTopicContent,
totalTopics: totalTopics,
activeTopicName: activeTopicName,
nextTopicName: nextTopicName,
allTopics: allTopicNames,
answers: []
};
} catch (error) {
console.error('获取内容时发生错误:', error);
return null;
}
}
let isAutoRunning = localStorage.getItem('u-auto-running') === 'true';
let autoRunTimeoutId = null;
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
function updateAutoRunButtonUI() {
const btn = document.getElementById('auto-run-btn');
if (!btn) return;
if (isAutoRunning) {
btn.innerHTML = '停止挂机';
btn.style.background = 'linear-gradient(135deg, #F59E0B 0%, #EF4444 100%)';
btn.className = 'u-helper-btn u-helper-btn-danger';
} else {
btn.innerHTML = '开始挂机';
btn.style.background = 'linear-gradient(135deg, #10B981 0%, #06B6D4 100%)';
btn.className = 'u-helper-btn u-helper-btn-success';
}
}
function findFooterButtonByText(text) {
const selectors = [
'#pc-foot a, #pc-foot button',
'#footerContainer button',
'.submit-bar-pc--btn-1_Xvo',
'button[class*="submit"]',
'button[class*="btn"]'
];
for (const selector of selectors) {
const footerButtons = document.querySelectorAll(selector);
for (const btn of footerButtons) {
if (btn.textContent.replace(/\s/g, '').includes(text)) {
return btn;
}
}
}
return null;
}
function findSubmitButton(container = document) {
const selectors = [
'button[type="submit"]',
'button[class*="submit"]',
'button[class*="confirm"]',
'.submit-bar-pc--btn-1_Xvo',
'.btns-submit button.submit-btn',
'button.submit-btn',
];
for (const selector of selectors) {
try {
const button = container.querySelector(selector);
if (button) {
const buttonText = (button.textContent || '').toLowerCase();
if (buttonText.includes('提交') ||
buttonText.includes('submit') ||
buttonText.includes('确定') ||
buttonText.includes('确认') ||
selector.includes('submit') ||
selector.includes('confirm')) {
return button;
}
}
} catch (e) {
console.warn('选择器执行失败:', selector, e.message);
}
}
const footerContainer = container.querySelector('#footerContainer') ||
document.querySelector('#footerContainer');
if (footerContainer) {
const footerButtons = footerContainer.querySelectorAll('button');
for (const button of footerButtons) {
const text = (button.textContent || '').trim();
if (text.includes('提交') || text === 'Submit' || text === '确定' || text === '确认') {
return button;
}
}
}
const allButtons = container.querySelectorAll('button');
for (const button of allButtons) {
const text = (button.textContent || '').trim();
if (text === '提交' || text === 'Submit' || text === '确定' || text === '确认') {
return button;
}
}
return null;
}
function handleSubmitConfirmDialog() {
const dialogSelectors = [
'[class*="dialog"]',
'[role="dialog"]',
'.modal',
'[class*="modal"]'
];
for (const selector of dialogSelectors) {
const dialog = document.querySelector(selector);
if (dialog && dialog.style.display !== 'none' && dialog.offsetParent !== null) {
const dialogText = dialog.textContent;
if (dialogText.includes('确认要提交') ||
dialogText.includes('小U只记录你第一次答题的得分') ||
dialogText.includes('确认提交') ||
dialogText.includes('submit')) {
console.log('[提交确认] 检测到提交确认弹窗');
const confirmButtons = dialog.querySelectorAll('button');
for (const button of confirmButtons) {
const buttonText = button.textContent.trim().toLowerCase();
if (buttonText === '确认' ||
buttonText === 'confirm' ||
buttonText === 'ok' ||
buttonText === '提交') {
console.log('[提交确认] 找到确认按钮,准备点击');
setTimeout(() => {
button.click();
console.log('[提交确认] 已点击确认按钮');
}, 500 + Math.random() * 500);
return true;
}
}
}
}
}
return false;
}
function setupSubmitConfirmHandler() {
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.type === 'childList') {
mutation.addedNodes.forEach((node) => {
if (node.nodeType === Node.ELEMENT_NODE) {
if (node.matches && (
node.matches('[class*="dialog"]') ||
node.matches('[role="dialog"]') ||
node.matches('.modal') ||
node.matches('[class*="modal"]')
)) {
setTimeout(() => {
handleSubmitConfirmDialog();
}, 100);
}
const dialogs = node.querySelectorAll && node.querySelectorAll('[class*="dialog"], [role="dialog"], .modal, [class*="modal"]');
if (dialogs && dialogs.length > 0) {
setTimeout(() => {
handleSubmitConfirmDialog();
}, 100);
}
}
});
}
});
});
observer.observe(document.body, {
childList: true,
subtree: true
});
console.log('[提交确认] 已启动提交确认弹窗监听器');
}
async function handleVocabularyCards() {
console.log('[挂机] 检测到词汇卡片学习页面,开始自动点击下一个...');
let cardCount = 0;
while (cardCount < 300) {
const nextButton = document.querySelector("#main-content > div > div > div > div.layoutBody-container > div > div > div.vocContainer > div.vocActions > div.action.next");
if (!nextButton || nextButton.classList.contains('disabled')) {
console.log(`[挂机] 词汇卡片处理完成,共处理 ${cardCount} 个卡片。准备跳转到下一任务。`);
return;
}
if (window.__autoPlayRecordEnabled) {
console.log(`[挂机] 检查第 ${cardCount + 1} 个词汇卡片是否有录音题...`);
const recordingHandled = await handleVocabularyRecording();
if (recordingHandled) {
console.log(`[挂机] 第 ${cardCount + 1} 个词汇卡片的录音题已处理完成`);
await waitForScoreAppear();
}
}
await sleep(500 + Math.random() * 1000);
nextButton.dispatchEvent(new MouseEvent('mouseover', { bubbles: true }));
await sleep(100 + Math.random() * 200);
console.log(`[挂机] 点击第 ${cardCount + 1} 个词汇卡片的"下一个"按钮`);
nextButton.click();
cardCount++;
await sleep(800 + Math.random() * 500);
}
console.log(`[挂机] 已达到最大处理数量限制 (${cardCount})`);
}
async function waitForVideosToEnd() {
let videos = Array.from(document.querySelectorAll('video')).filter(v => !v.ended && v.duration > 0);
if (videos.length === 0) {
console.log('[挂机] 页面上没有需要等待的视频,继续执行。');
return;
}
console.log(`[挂机] 检测到 ${videos.length} 个视频,正在监控播放状态...`);
videos.forEach(v => {
if (v.paused) {
v.muted = true;
v.play().catch(e => console.warn('[挂机] 视频播放请求被拦截:', e));
}
const savedSpeed = localStorage.getItem('u-video-speed') || '2.0';
v.playbackRate = parseFloat(savedSpeed);
});
return new Promise((resolve) => {
const checkTimer = setInterval(() => {
const currentVideos = Array.from(document.querySelectorAll('video')).filter(v => !v.ended && v.duration > 0);
if (currentVideos.length === 0) {
console.log('[挂机] 视频已全部处理完毕(结束或移除)。');
clearInterval(checkTimer);
resolve();
}
if (window.__videoSkipEnabled) {
currentVideos.forEach(v => {
if (v.duration > 0) v.currentTime = v.duration;
});
}
}, 2000);
setTimeout(() => {
clearInterval(checkTimer);
resolve();
}, 600000);
});
}
async function runNextStep() {
if (!isAutoRunning) return;
console.log("runNextStep: 开始执行");
if (await handleGenericCommentSection()) {
console.log("评论区已处理,等待1.5秒后尝试进入下一页...");
await sleep(1500);
}
if (await handleVocabularyCards()) {
console.log("词汇卡片已处理");
}
try {
const vocContainer = document.querySelector("#main-content > div > div > div > div.layoutBody-container > div > div > div.vocContainer");
const discussionTextarea = document.querySelector("#bottom > div > div > div.discussion-cloud-bottom > div.discussion-cloud-bottom-textArea-container > div.ant-input-textarea.ant-input-textarea-show-count.discussion-cloud-bottom-textArea > textarea");
if (vocContainer) {
await handleVocabularyCards();
} else if (discussionTextarea) {
await handleDiscussionPage();
}
else {
let recordingHandled = false;
if (window.__autoPlayRecordEnabled) {
recordingHandled = await handleRecordingQuestions();
if (recordingHandled) {
console.log('[挂机] 录音题已处理,准备提交...');
}
}
console.log('[挂机] 尝试自动选择答案...');
const foundAnswers = await autoSelectAnswers();
if (foundAnswers || recordingHandled) {
console.log('[挂机] 页面内容已处理 (录音或答题),准备提交。');
await sleep(getAnswerDelay());
const submitButton = findFooterButtonByText('提交');
if (submitButton) {
const waitTime = getPageDelay();
console.log(`[挂机] 任务完成,强制停留 ${waitTime}ms (模拟检查) 后点击提交...`);
await sleep(waitTime);
submitButton.click();
await sleep(2500);
} else {
console.log('[挂机] 未找到提交按钮,可能已提交或无需提交');
}
} else {
console.log('[挂机] 未找到答案且无录音操作,可能为主观题,将直接尝试导航。');
await sleep(500);
}
}
await waitForVideosToEnd();
console.log('[挂机] 内容处理/提交完毕,查找下一步操作进行导航...');
const userPageDelay = getPageDelay();
const nextQuestionButton = findFooterButtonByText('下一题');
if (nextQuestionButton) {
console.log(`[挂机] 本页任务完成,强制停留 ${userPageDelay}ms 后点击"下一题"...`);
await sleep(userPageDelay);
console.log('[挂机] 操作: 点击 "下一题"');
nextQuestionButton.click();
autoRunTimeoutId = setTimeout(runNextStep, 5000);
return;
}
const navigatedToSubTopic = await navigateToNextSubTopic();
if (navigatedToSubTopic) {
autoRunTimeoutId = setTimeout(runNextStep, 5000);
return;
}
const navigatedByToc = await navigateToNextTocItem();
if (navigatedByToc) {
autoRunTimeoutId = setTimeout(runNextStep, 5000);
return;
}
console.log('[挂机] 结束: 未找到任何可执行的导航操作。');
isAutoRunning = false;
updateAutoRunButtonUI();
} catch (error) {
console.error('[挂机] 执行步骤时发生错误:', error);
isAutoRunning = false;
updateAutoRunButtonUI();
}
}
async function navigateToNextSubTopic() {
console.log('[挂机] 尝试导航到下一个子主题 (横向Tab)...');
const tabSystems = [
{
name: "子任务Tabs",
containerSelector: '.pc-header-tasks-container',
tabSelector: '.pc-task',
activeClass: 'pc-header-task-activity'
},
{
name: "主任务Tabs",
containerSelector: '.pc-tab-container',
tabSelector: '.ant-col',
activeClass: 'pc-header-tab-activity'
}
];
for (const system of tabSystems) {
const container = document.querySelector(system.containerSelector);
if (!container) continue;
const tabs = Array.from(container.querySelectorAll(system.tabSelector));
if (tabs.length <= 1) continue;
const activeIndex = tabs.findIndex(tab => tab.classList.contains(system.activeClass));
if (activeIndex === -1) continue;
if (activeIndex + 1 < tabs.length) {
const nextTab = tabs[activeIndex + 1];
const clickable = nextTab.querySelector('.pc-tab-view-container') || nextTab;
const nextTabName = (clickable.textContent || nextTab.title || '未知').trim();
const userPageDelay = getPageDelay();
console.log(`[挂机] 准备导航到下一个子主题: "${nextTabName}",强制停留 ${userPageDelay}ms...`);
await sleep(userPageDelay);
clickable.dispatchEvent(new MouseEvent('mouseover', { bubbles: true }));
await sleep(200);
clickable.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
await sleep(50);
clickable.dispatchEvent(new MouseEvent('mouseup', { bubbles: true }));
clickable.click();
return true;
} else {
console.log(`[挂机] 在 ${system.name} 中已是最后一个Tab。`);
}
}
console.log('[挂机] 未找到可切换的下一个子主题。');
return false;
}
async function navigateToNextTocItem() {
console.log('[挂机] 🔄 正在寻找跳转路径...');
let tocItems = [];
let activeIndex = -1;
let nextItemIsSkipped = false;
const activeElement = document.querySelector('.pc-menu-activity') ||
document.querySelector('li.group.active') ||
document.querySelector('.pc-slider-menu-node.active');
if (activeElement) {
const tocContainer = activeElement.closest('.pc-slider-content-menu, .pc-slier-menu-container') ||
activeElement.closest('.menu--u3menu-3Xu4h') ||
document.querySelector('#sidemenu');
if (tocContainer) {
const allItems = Array.from(tocContainer.querySelectorAll(
'div[data-role="node"], div[data-role="micro"], li.group.courseware'
));
tocItems = allItems.filter(item => item.offsetParent !== null);
activeIndex = tocItems.indexOf(activeElement);
if (activeIndex !== -1 && activeIndex + 1 < tocItems.length) {
const checkNextItem = tocItems[activeIndex + 1];
const nameEl = checkNextItem.querySelector('span') || checkNextItem;
const checkName = (nameEl.textContent || '').trim();
if (typeof SkipManager !== 'undefined' && SkipManager.shouldSkip(checkName)) {
console.log(`[挂机] 🛡️ 预判检测: 下一章 "${checkName}" 在跳过列表中。`);
nextItemIsSkipped = true;
}
}
}
}
const continueBtn = document.querySelector('.question-common-course-page .btn, .question-common-course-page a');
if (continueBtn && continueBtn.offsetParent !== null && continueBtn.textContent.includes('继续学习')) {
if (nextItemIsSkipped) {
console.log('[挂机] ⚠️ 下一章需跳过,因此忽略“继续学习”按钮,转为目录强制跳转。');
} else {
console.log('[挂机] 👉 发现“继续学习”按钮且下一章安全,点击跳转...');
continueBtn.click();
return true;
}
}
if (activeIndex !== -1) {
let targetIndex = activeIndex + 1;
while (targetIndex < tocItems.length) {
const nextItem = tocItems[targetIndex];
const nameEl = nextItem.querySelector('.pc-menu-node-name') ||
nextItem.querySelector('span') ||
nextItem.querySelector('.name a') ||
nextItem;
const rawName = nameEl.textContent || '';
const nextItemName = rawName.trim().split('\n')[0];
if (typeof SkipManager !== 'undefined' && SkipManager.shouldSkip(nextItemName)) {
console.log(`[挂机] 🚫 章节 "${nextItemName}" 在跳过列表中,自动跳过...`);
targetIndex++;
continue;
}
const userPageDelay = getPageDelay();
console.log(`[挂机] 🟢 锁定目标章节: "${nextItemName}"`);
console.log(`[挂机] ⏳ 强制停留 ${userPageDelay}ms 后进入...`);
await sleep(userPageDelay);
nextItem.scrollIntoView({ behavior: 'smooth', block: 'center' });
await sleep(500);
nextItem.click();
const innerSpan = nextItem.querySelector('span');
if (innerSpan) innerSpan.click();
return true;
}
console.warn('[挂机] ⚠️ 已遍历完剩余所有目录,未找到可执行章节 (均在跳过列表中)');
}
console.log('[挂机] ⚠️ 目录导航未执行,尝试点击页面底部“下一页”按钮...');
const nextBtnSelectors = [
'.next-page-btn', '.btn-next', '.next-step', '.lay-page-next',
'.layout-pagination .next', '.test-bottom-next', '.ant-btn-primary',
'button', 'a', 'div.btn', 'span.btn'
];
for (let sel of nextBtnSelectors) {
const btns = document.querySelectorAll(sel);
for (let btn of btns) {
if (btn && btn.offsetParent !== null && !btn.classList.contains('disabled')) {
const text = btn.textContent.trim();
if (['下一页', '下一题', 'Next', 'Next Page', '确定', '提交'].some(k => text === k || text.includes(k))) {
if (btn.className.includes('pre') || btn.className.includes('prev')) continue;
if (nextItemIsSkipped) {
console.warn('[挂机] 🚫 警告:下一页可能是跳过章节,但目录跳转失败。暂停操作以防误入。');
return false;
}
console.log(`[挂机] 👉 [备用策略] 发现按钮 (${text}),点击跳转...`);
btn.click();
return true;
}
}
}
}
console.error('[挂机] ❌ 结束: 无法找到任何跳转路径');
return false;
}
function toggleAutoRun() {
isAutoRunning = !isAutoRunning;
localStorage.setItem('u-auto-running', isAutoRunning.toString());
updateAutoRunButtonUI();
if (isAutoRunning) {
console.log('自动挂机已启动...');
window.isAutoModeRunning = true;
runNextStep();
} else {
if (autoRunTimeoutId) {
clearTimeout(autoRunTimeoutId);
autoRunTimeoutId = null;
}
window.isAutoModeRunning = false;
console.log('自动挂机已手动停止。');
}
}
function autoResumeIfNeeded() {
if (!isAutoRunning) return;
console.log('[自动恢复] ♻️ 检测到刷新前处于挂机状态,准备恢复...');
window.isAutoModeRunning = true;
updateAutoRunButtonUI();
showRecordNotification('⏳ 等待页面资源加载...', 'info');
let checkCount = 0;
const maxChecks = 60;
const waitForPageReady = () => {
const hasMenu = document.querySelector('.pc-slier-menu-container') || document.querySelector('.pc-menu-node-name');
const hasActiveItem = document.querySelector('.pc-menu-activity');
const hasContent = document.querySelector('.layoutBody-container');
const isLoading = document.querySelector('.ant-spin-spinning');
if ((hasActiveItem || hasMenu || hasContent) && !isLoading) {
console.log(`[自动恢复] ✅ 页面加载完毕 (耗时 ${checkCount}s),3秒后继续执行...`);
showRecordNotification('🚀 页面就绪,继续挂机', 'success');
setTimeout(() => {
runNextStep();
}, 3000);
} else {
checkCount++;
if (checkCount > maxChecks) {
console.warn('[自动恢复] ⚠️ 等待超时,尝试强制启动...');
showRecordNotification('⚠️ 等待超时,强制继续...', 'warning');
runNextStep();
} else {
console.log(`[自动恢复] 页面未完全就绪 (目录: ${!!hasMenu}, 选中项: ${!!hasActiveItem}, Loading: ${!!isLoading})... ${checkCount}/${maxChecks}`);
setTimeout(waitForPageReady, 1000);
}
}
};
setTimeout(waitForPageReady, 1000);
}
function handleVideo(video) {
if (video.dataset.handledByScript) return;
video.dataset.handledByScript = 'true';
console.log('[视频助手] 发现视频,开始处理:', video);
const setPlaybackRate = () => {
const targetSpeed = parseFloat(localStorage.getItem('u-video-speed') || '2.0');
if (video.playbackRate !== targetSpeed) {
video.playbackRate = targetSpeed;
console.log(`[视频助手] 视频倍速已设置为 ${targetSpeed}x`);
}
};
const attemptPlay = () => {
video.muted = true;
const playPromise = video.play();
if (playPromise !== undefined) {
playPromise.then(() => {
console.log('[视频助手] 视频已自动播放。');
setPlaybackRate();
}).catch(error => {
console.warn('[视频助手] 自动播放失败,可能是浏览器策略限制。等待用户交互后再次尝试。');
const playOnInteraction = () => {
video.play();
setPlaybackRate();
document.body.removeEventListener('click', playOnInteraction, true);
};
document.body.addEventListener('click', playOnInteraction, { once: true, capture: true });
});
}
};
if (video.readyState >= 3) {
attemptPlay();
} else {
video.addEventListener('canplay', attemptPlay, { once: true });
}
video.addEventListener('ratechange', () => {
setTimeout(setPlaybackRate, 100);
});
video.addEventListener('playing', setPlaybackRate);
video.addEventListener('pause', () => {
setTimeout(() => {
const popup = document.querySelector('.question-video-popup');
if (popup && popup.offsetParent !== null) {
console.log('[视频助手] 视频暂停,检测到弹窗问题,开始处理...');
handleVideoPopupQuestions(popup);
}
}, 200);
});
}
function setupVideoHandler() {
document.querySelectorAll('video').forEach(handleVideo);
const observer = new MutationObserver((mutationsList) => {
for (const mutation of mutationsList) {
mutation.addedNodes.forEach(node => {
if (node.nodeType === Node.ELEMENT_NODE) {
if (node.tagName === 'VIDEO') {
handleVideo(node);
} else if (node.querySelectorAll) {
node.querySelectorAll('video').forEach(handleVideo);
}
}
});
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
console.log('已启动视频自动播放和倍速调整功能。');
}
async function handleVideoPopupQuestions(popupElement) {
if (popupElement.dataset.handledByRandomSelect) return;
popupElement.dataset.handledByRandomSelect = 'true';
console.log('[视频弹题助手] 检测到视频中的弹窗问题,准备随机选择...');
await sleep(500);
const options = popupElement.querySelectorAll('.option.isNotReview');
if (options.length > 0) {
await sleep(1000 + Math.random() * 1500);
const randomIndex = Math.floor(Math.random() * options.length);
const randomOption = options[randomIndex];
const optionCaption = randomOption.querySelector('.caption')?.textContent.trim() || `选项 ${randomIndex + 1}`;
console.log(`[视频弹题助手] 随机选择选项: ${optionCaption}`);
randomOption.dispatchEvent(new MouseEvent('mouseover', { bubbles: true }));
await sleep(150 + Math.random() * 200);
randomOption.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
await sleep(50 + Math.random() * 50);
randomOption.dispatchEvent(new MouseEvent('mouseup', { bubbles: true }));
randomOption.click();
console.log('[视频弹题助手] 已成功点击选项。');
await sleep(500 + Math.random() * 300);
const confirmButton = popupElement.querySelector('button.submit-btn');
if (confirmButton && !confirmButton.disabled) {
console.log('[视频弹题助手] 找到"确定"按钮,正在点击...');
confirmButton.click();
console.log('[视频弹题助手] 已点击"确定"按钮。');
} else {
console.log('[视频弹题助手] 未找到或"确定"按钮不可用。');
}
} else {
console.log('[视频弹题助手] 未在弹窗中找到可选选项。');
}
}
function setupVideoPopupObserver() {
const observer = new MutationObserver(() => {
const popup = document.querySelector('.question-video-popup');
if (popup && popup.offsetParent === null) {
if (popup.dataset.handledByRandomSelect) {
console.log('[视频弹题助手] 弹窗已隐藏,重置处理标记以便下次使用。');
delete popup.dataset.handledByRandomSelect;
}
}
});
observer.observe(document.body, {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ['style', 'class', 'hidden']
});
console.log('已启动视频内弹窗问题状态监视器。');
}
async function handleDiscussionPage() {
const textarea = document.querySelector("#bottom > div > div > div.discussion-cloud-bottom > div.discussion-cloud-bottom-textArea-container > div.ant-input-textarea.ant-input-textarea-show-count.discussion-cloud-bottom-textArea > textarea");
const submitButton = document.querySelector("#bottom > div > div > div.discussion-cloud-bottom > div.discussion-cloud-bottom-btns > div > div.btns-submit.student-btns-submit > button");
if (submitButton && !submitButton.disabled) {
let commentText = localStorage.getItem('u-default-comment');
const selectedBank = document.getElementById('online-bank-selector')?.value;
const hasOnlineBank = selectedBank && selectedBank.trim() !== '';
if (useKimiAI && hasOnlineBank) {
console.log('[讨论区] AI模式已启用且有在线题库,评论使用AI分析...');
try {
const discussionTitle = document.querySelector('#top .discussion-title p, #top .discussion-title');
const titleText = discussionTitle ? discussionTitle.textContent.trim() : '';
const discussionQuestions = document.querySelector('#top .question-common-abs-material .component-htmlview, #top .text-material-wrapper');
const questionsText = discussionQuestions ? discussionQuestions.textContent.trim() : '';
if (titleText || questionsText) {
console.log('[讨论区] 讨论标题:', titleText);
console.log('[讨论区] 讨论问题:', questionsText);
const prompt = `请帮我回答以下讨论问题。请用英语回答,回答要简洁、有深度,大约50-100词。
讨论主题:${titleText}
讨论问题:
${questionsText}
要求:
1. 用英语回答
2. 回答要有实质性内容,不要太简单
3. 回答要自然、像是真实学生的想法
4. 如果有多个问题,简要回答每个问题
5. 总字数控制在50-100词左右
6. 不要加标题或序号,直接给出答案段落`;
const aiResponse = await askKimi(prompt);
if (aiResponse && aiResponse.trim()) {
commentText = aiResponse.trim();
console.log('[讨论区] AI生成的评论:', commentText);
} else {
console.log('[讨论区] AI未返回有效内容,使用默认评论');
}
} else {
console.log('[讨论区] 未找到讨论内容,使用默认评论');
}
} catch (error) {
console.error('[讨论区] AI分析失败:', error);
console.log('[讨论区] 使用默认评论');
}
} else if (useKimiAI && !hasOnlineBank) {
console.log(`[讨论区] AI已启用但无在线题库,为节省积分用于答题,评论使用默认文本 "${commentText}"`);
} else {
console.log(`[讨论区] AI未启用,使用默认评论文本 "${commentText}"`);
}
await sleep(1000 + Math.random() * 500);
textarea.dispatchEvent(new Event('focus', { bubbles: true }));
const nativeTextareaSetter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, "value").set;
nativeTextareaSetter.call(textarea, commentText);
textarea.dispatchEvent(new Event('input', { bubbles: true }));
await sleep(200);
textarea.dispatchEvent(new Event('blur', { bubbles: true }));
console.log('[讨论区] 已输入评论:', commentText.substring(0, 50) + (commentText.length > 50 ? '...' : ''));
await sleep(500 + Math.random() * 500);
if (!submitButton.disabled) {
submitButton.click();
console.log('[讨论区] 已点击发布按钮');
await sleep(2500);
}
} else {
console.log('[讨论区] 发布按钮不可用或未找到,跳过');
}
}
function setupPopupHandler() {
console.log('🛡️ 全局弹窗拦截器已启动 (MutationObserver版)');
const checkAndClickModal = (modalNode) => {
if (!modalNode || modalNode.style?.display === 'none') return;
const confirmContent = modalNode.querySelector('.ant-modal-confirm-content');
if (confirmContent && confirmContent.textContent.includes('本单元仅记录第一次作答的得分')) {
const okBtn = modalNode.querySelector('.system-info-cloud-ok-button') || modalNode.querySelector('.ant-btn-primary');
if (okBtn) {
console.log(`[自动确认] ⚡️ 秒杀 "本单元仅记录" 弹窗`);
okBtn.click();
return;
}
}
const confirmButton = modalNode.querySelector('.ant-btn-primary');
if (confirmButton && confirmButton.offsetParent !== null) {
const rawText = confirmButton.textContent || confirmButton.innerText || '';
const buttonText = rawText.replace(/\s/g, '');
const confirmKeywords = ['确定', '确认', '我知道了', '知道了', 'OK', '好的', '继续', '提交'];
const shouldClick = confirmKeywords.some(keyword => buttonText.includes(keyword));
if (shouldClick) {
console.log(`[自动确认] ⚡️ 捕获通用弹窗,点击按钮: "${rawText.trim()}"`);
confirmButton.click();
}
}
};
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
mutation.addedNodes.forEach((node) => {
if (node.nodeType !== 1) return;
if (node.classList && node.classList.contains('ant-modal-wrap')) {
checkAndClickModal(node);
}
else if (node.querySelector) {
const modal = node.querySelector('.ant-modal-wrap');
if (modal) {
checkAndClickModal(modal);
}
}
});
});
});
observer.observe(document.body, {
childList: true,
subtree: true
});
document.querySelectorAll('.ant-modal-wrap').forEach(checkAndClickModal);
}
function setupAnswerInterceptor() {
const SERVER_API = getApiUrl(API_CONFIG.ENDPOINTS.INJECT);
const TARGET_URL_KEYWORD = '/course/api/v3/newExploration/submit';
function hasRecordButtonOnPage() {
const btn = document.querySelector('.record-icon, .button-record, .record-fill-icon');
return btn !== null;
}
const originalXHROpen = XMLHttpRequest.prototype.open;
const originalXHRSend = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype._originalSend = originalXHRSend;
XMLHttpRequest.prototype.open = function(method, url, ...args) {
this._url = url;
this._method = method;
return originalXHROpen.apply(this, [method, url, ...args]);
};
XMLHttpRequest.prototype.send = function(data) {
const isTargetUrl = this._url && this._url.includes(TARGET_URL_KEYWORD);
const isFeatureEnabled = window.__enableOralScoreInjection;
if (isFeatureEnabled && isTargetUrl && hasRecordButtonOnPage()) {
console.log('[U助手-云端] 🎤 检测到页面有录音按钮,强制进行云端改分...');
GM_xmlhttpRequest({
method: "POST",
url: SERVER_API,
headers: { "Content-Type": "application/json" },
data: data,
onload: (response) => {
if (response.status === 200) {
try {
const resData = JSON.parse(response.responseText);
if (resData && resData.quesDatas) {
showRecordNotification('☁️ 高分成功!', 'success');
const finalPayload = JSON.stringify(resData);
XMLHttpRequest.prototype._originalSend.call(this, finalPayload);
return;
}
} catch (e) {
console.error('[U助手-云端] 解析失败:', e);
}
} else {
showRecordNotification('❌ 云端服务器错误', 'error');
}
XMLHttpRequest.prototype._originalSend.call(this, data);
},
onerror: (err) => {
console.error('[U助手-云端] 网络请求错误:', err);
XMLHttpRequest.prototype._originalSend.call(this, data);
}
});
return;
}
if (this._url && window.__sortableAnswers__ &&
(this._url.includes('submit') || this._url.includes('answer'))) {
try {
let payload = (typeof data === 'string') ? JSON.parse(data) : data;
let modified = false;
if (payload && payload.quesDatas && Array.isArray(payload.quesDatas)) {
payload.quesDatas.forEach((quesData) => {
if (!quesData.answer) return;
let answerObj = quesData.answer;
let isStringified = false;
if (typeof quesData.answer === 'string') {
try { answerObj = JSON.parse(quesData.answer); isStringified = true; } catch (e) { return; }
}
if (answerObj && answerObj.children && Array.isArray(answerObj.children)) {
const correctAnswers = window.__sortableAnswers__.answers;
if(correctAnswers && correctAnswers.length > 0) {
answerObj.children = correctAnswers.map(letter => ({ value: [letter], isDone: true }));
quesData.answer = isStringified ? JSON.stringify(answerObj) : answerObj;
modified = true;
}
}
});
if (modified) {
data = JSON.stringify(payload);
delete window.__sortableAnswers__;
console.log('[拦截器] 排序题本地修正成功');
}
}
} catch (e) { console.error(e); }
}
return originalXHRSend.apply(this, [data]);
};
const originalFetch = window.fetch;
window.fetch = async function(url, options = {}) {
return originalFetch.apply(this, [url, options]);
};
console.log('[U助手] 智能拦截器 V7 (UI判定版) 已就绪');
}
window.addEventListener('load', () => {
setupAnswerInterceptor();
createFloatingButton();
SubmitInterceptor.init();
setupPopupHandler();
setupMultiPageNavigationListener();
initRecordingFeatures();
setupSubmitConfirmHandler();
if (typeof SkipManager !== 'undefined' && SkipManager.initPanel) {
}
setTimeout(() => {
const isResumeEnabled = localStorage.getItem('u-helper-resume-after-refresh') === 'true';
const wasAutoRunning = localStorage.getItem('u-auto-running') === 'true';
console.log(`[启动检查] 上次状态: ${wasAutoRunning}, 恢复开关: ${isResumeEnabled}`);
if (isResumeEnabled && wasAutoRunning) {
console.log('[自动恢复] ✅ 检测到需要恢复挂机,开始等待页面加载...');
window.isAutoModeRunning = true;
isAutoRunning = true;
updateAutoRunButtonUI();
showRecordNotification('⏳ 等待页面资源加载...', 'info');
let checkCount = 0;
const maxChecks = 30;
const waitForPageReady = () => {
const hasMenu = document.querySelector('.pc-menu-node-name') || document.querySelector('.pc-slier-menu-container');
const hasQuestion = document.querySelector('.question-common-abs-reply') || document.querySelector('.question-wrap');
const hasContent = document.querySelector('.layoutBody-container');
const isLoading = document.querySelector('.ant-spin-spinning');
if ((hasMenu || hasQuestion || hasContent) && !isLoading) {
console.log(`[自动恢复] 🎉 页面加载完毕 (耗时 ${checkCount}s),继续挂机!`);
showRecordNotification('🚀 页面就绪,继续挂机', 'success');
setTimeout(runNextStep, 1000);
} else {
checkCount++;
if (checkCount > maxChecks) {
console.warn('[自动恢复] ⚠️ 等待超时,尝试强制启动...');
showRecordNotification('⚠️ 加载超时,强制尝试...', 'warning');
runNextStep();
} else {
console.log(`[自动恢复] 页面未就绪 (Loading: ${!!isLoading}, Menu: ${!!hasMenu})... ${checkCount}/${maxChecks}`);
setTimeout(waitForPageReady, 1000);
}
}
};
waitForPageReady();
} else if (wasAutoRunning && !isResumeEnabled) {
console.log('[自动恢复] 🛑 刷新后恢复开关未开启,停止挂机。');
localStorage.setItem('u-auto-running', 'false');
isAutoRunning = false;
window.isAutoModeRunning = false;
updateAutoRunButtonUI();
}
}, 1500);
setTimeout(() => {
if (typeof showAnnouncement === 'function') {
showAnnouncement(true);
}
}, 2000);
});
async function fillAnswersFromArray(answers) {
const questions = document.querySelectorAll('.question-common-abs-reply, .question-common-abs-banked-cloze');
if (questions.length === 0) {
console.warn('[在线题库] 未在页面上找到题目容器。');
return;
}
if (questions.length !== answers.length) {
console.warn(`[在线题库] 警告:页面上有 ${questions.length} 道题,但获取到 ${answers.length} 个答案,可能不匹配。`);
}
for (let i = 0; i < answers.length; i++) {
if (i >= questions.length) break;
const question = questions[i];
const answerLetter = answers[i];
const options = question.querySelectorAll('.option.isNotReview, div.option');
let targetOption = null;
for (const option of options) {
const caption = option.querySelector('.caption');
if (caption && caption.textContent.trim() === answerLetter) {
targetOption = option;
break;
}
}
if (targetOption) {
console.log(`[在线题库] 第 ${i + 1} 题,选择答案: ${answerLetter}`);
targetOption.click();
await new Promise(r => setTimeout(r, 200 + Math.random() * 200));
} else {
console.error(`[在线题库] 第 ${i + 1} 题,未找到选项: ${answerLetter}`);
}
}
}
async function fillAnswersFromArray(answers) {
console.log('[在线题库] 开始填写答案,共', answers.length, '题');
const sortableWrapper = document.querySelector('#sortableListWrapper, .sortable-list-wrapper');
if (sortableWrapper) {
const questions = sortableWrapper.querySelectorAll('.sortable-list-question-no');
const options = sortableWrapper.querySelectorAll('.sequence-reply-view-item-text');
const answerMap = {};
for (let i = 0; i < Math.min(answers.length, questions.length); i++) {
answerMap[i] = answers[i].trim().toUpperCase();
}
const hiddenInputs = sortableWrapper.querySelectorAll('input[type="hidden"], input[name*="answer"], input[name*="sequence"]');
if (hiddenInputs.length > 0) {
hiddenInputs.forEach((input, idx) => {
if (answerMap[idx]) {
input.value = answerMap[idx];
}
});
}
const optionMap = new Map();
for (const option of options) {
const optionText = option.textContent.trim();
const match = optionText.match(/^([A-Z])\./);
if (match) {
optionMap.set(match[1], option);
}
}
const correctOrder = [];
for (let i = 0; i < Math.min(answers.length, questions.length); i++) {
const answerLetter = answerMap[i];
const targetQuestion = questions[i];
correctOrder.push(targetQuestion);
const targetOption = optionMap.get(answerLetter);
if (targetOption) {
correctOrder.push(targetOption);
}
}
while (sortableWrapper.firstChild) {
sortableWrapper.removeChild(sortableWrapper.firstChild);
}
correctOrder.forEach((element) => {
sortableWrapper.appendChild(element);
});
for (let i = 0; i < Math.min(answers.length, questions.length); i++) {
const answerLetter = answerMap[i];
const targetOption = optionMap.get(answerLetter);
if (!targetOption) continue;
const rect = targetOption.getBoundingClientRect();
const centerX = rect.left + rect.width / 2;
const centerY = rect.top + rect.height / 2;
const touchstartEvent = new TouchEvent('touchstart', {
bubbles: true,
cancelable: true,
touches: [new Touch({
identifier: i,
target: targetOption,
clientX: centerX,
clientY: centerY
})]
});
targetOption.dispatchEvent(touchstartEvent);
await sleep(50);
const touchendEvent = new TouchEvent('touchend', {
bubbles: true,
cancelable: true,
changedTouches: [new Touch({
identifier: i,
target: targetOption,
clientX: centerX,
clientY: centerY + 2
})]
});
targetOption.dispatchEvent(touchendEvent);
await sleep(50);
}
const finalEvents = ['change', 'input', 'update', 'sort'];
finalEvents.forEach(eventType => {
sortableWrapper.dispatchEvent(new Event(eventType, { bubbles: true }));
});
window.__sortableAnswers__ = {
answers: answers,
answerMap: answerMap,
timestamp: Date.now()
};
console.log('[在线题库] 拖动排序题已完成');
await sleep(500);
return;
}
const feScoopTriggers = document.querySelectorAll('.fe-scoop[data-scoop-index]');
if (feScoopTriggers.length > 0) {
const hasTriggers = Array.from(feScoopTriggers).some(el => el.querySelector('.ant-dropdown-trigger'));
const hasInputs = Array.from(feScoopTriggers).some(el => el.querySelector('input, textarea'));
if (!hasTriggers && hasInputs) {
console.log(`[在线题库] 检测到 ${feScoopTriggers.length} 个 fe-scoop 填空题,跳过下拉选择题处理`);
} else if (hasTriggers) {
console.log(`[在线题库] 检测到 ${feScoopTriggers.length} 个 fe-scoop 下拉选择题`);
const questionsToProcess = Math.min(feScoopTriggers.length, answers.length);
for (let i = 0; i < questionsToProcess; i++) {
const scoopElement = feScoopTriggers[i];
const trigger = scoopElement.querySelector('.ant-dropdown-trigger');
if (!trigger) {
console.warn(`[在线题库] 第 ${i + 1} 题未找到触发器,跳过`);
continue;
}
const answerText = answers[i].trim();
const currentAnswerElement = trigger.querySelector('.user-answer-text');
if (currentAnswerElement) {
const currentText = currentAnswerElement.textContent.trim();
if (currentText !== '点击选择' && currentText !== 'Click to select' && currentText !== '') {
if (currentText.toLowerCase() === answerText.toLowerCase()) {
console.log(`[在线题库] 第 ${i + 1} 题已选择正确答案: ${currentText}`);
continue;
}
}
}
console.log(`[在线题库] 第 ${i + 1} 题,准备选择: ${answerText}`);
scoopElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
await new Promise(r => setTimeout(r, 300));
await simulateHumanBehavior(trigger);
trigger.click();
await new Promise(r => setTimeout(r, 800));
const allMenus = document.querySelectorAll('.ant-dropdown-menu.scoop-select');
let targetOption = null;
for (const menu of allMenus) {
const menuStyle = window.getComputedStyle(menu);
const menuParent = menu.closest('.ant-dropdown');
if (menuParent && !menuParent.classList.contains('ant-dropdown-hidden')) {
console.log(`[在线题库] 找到可见菜单`);
const options = menu.querySelectorAll('li.select-option');
console.log(`[在线题库] 菜单中有 ${options.length} 个选项`);
for (const opt of options) {
const optText = opt.textContent.trim();
const menuId = opt.getAttribute('data-menu-id');
console.log(`[在线题库] 检查选项: "${optText}", data-menu-id: ${menuId}`);
if (optText.toLowerCase() === answerText.toLowerCase() ||
optText.includes(answerText) ||
answerText.includes(optText)) {
targetOption = opt;
console.log(`[在线题库] ✓ 找到匹配选项: ${optText}`);
break;
}
if (answerText.length === 1 && menuId) {
const letter = answerText.toUpperCase();
if (menuId.endsWith('-' + letter)) {
targetOption = opt;
console.log(`[在线题库] ✓ 通过字母找到选项: ${optText}`);
break;
}
}
}
if (targetOption) break;
}
}
if (targetOption) {
console.log(`[在线题库] 准备点击选项: ${targetOption.textContent.trim()}`);
await simulateHumanBehavior(targetOption);
targetOption.click();
await new Promise(r => setTimeout(r, 500));
const updatedAnswerElement = trigger.querySelector('.user-answer-text');
if (updatedAnswerElement) {
const selectedText = updatedAnswerElement.textContent.trim();
console.log(`[在线题库] ✓ 第 ${i + 1} 题选择完成: ${selectedText}`);
}
} else {
console.error(`[在线题库] ✗ 第 ${i + 1} 题未找到匹配选项: "${answerText}"`);
document.body.click();
await new Promise(r => setTimeout(r, 300));
}
}
console.log('[在线题库] fe-scoop 下拉选择题处理完成');
return;
}
}
const dropdownSelectors = [
'.ant-select:not(.ant-select-disabled)',
'.ant-select-selector'
];
let initialDropdownQuestions = null;
let dropdownType = '';
for (const selector of dropdownSelectors) {
const elements = document.querySelectorAll(selector);
if (elements.length > 0) {
initialDropdownQuestions = elements;
dropdownType = selector;
console.log(`[在线题库] 检测到 ${elements.length} 个下拉选择题 (${selector})`);
break;
}
}
if (initialDropdownQuestions && initialDropdownQuestions.length > 0) {
const questionsToProcess = Math.min(initialDropdownQuestions.length, answers.length);
for (let i = 0; i < questionsToProcess; i++) {
const currentTriggers = document.querySelectorAll(dropdownType);
if (i >= currentTriggers.length) {
console.error(`[在线题库] 错误:无法找到第 ${i + 1} 题,作答中止。`);
break;
}
const trigger = currentTriggers[i];
const answerText = answers[i].trim();
const currentAnswerElement = trigger.querySelector('.user-answer-text, .ant-select-selection-item');
if (currentAnswerElement) {
const currentText = currentAnswerElement.textContent.trim();
if (currentText !== '点击选择' && currentText !== 'Click to select' && currentText !== '') {
if (currentText === answerText ||
currentText.toLowerCase() === answerText.toLowerCase() ||
currentText === answerText.toUpperCase()) {
console.log(`[在线题库] 第 ${i + 1} 题已选择正确答案: ${currentText}`);
continue;
}
}
}
console.log(`[在线题库] 第 ${i + 1} 题,准备选择: ${answerText}`);
await simulateHumanBehavior(trigger);
trigger.click();
await new Promise(resolve => setTimeout(resolve, 600));
const menuSelectors = [
'.ant-dropdown-menu.scoop-select',
'.ant-select-dropdown:not(.ant-select-dropdown-hidden)',
'.rc-virtual-list',
'.ant-select-item-option'
];
let targetOption = null;
for (const menuSelector of menuSelectors) {
const allMenus = document.querySelectorAll(menuSelector);
for (const menu of allMenus) {
const menuStyle = window.getComputedStyle(menu);
if (menuStyle.display === 'none' || menuStyle.visibility === 'hidden') {
continue;
}
const optionSelectors = [
'li.select-option',
'.ant-select-item-option',
'div.ant-select-item'
];
for (const optSelector of optionSelectors) {
const options = menu.querySelectorAll(optSelector);
if (options.length === 0) continue;
targetOption = Array.from(options).find(opt => {
const text = opt.textContent.trim();
const innerText = opt.innerText?.trim() || '';
if (text.toLowerCase() === answerText.toLowerCase()) return true;
if (innerText.toLowerCase() === answerText.toLowerCase()) return true;
if (answerText.length === 1) {
const answerLetter = answerText.toUpperCase();
if (text === answerLetter ||
text.startsWith(answerLetter + '.') ||
text.startsWith(answerLetter + ' ')) {
return true;
}
}
if (answerText.length === 1) {
const menuId = opt.getAttribute('data-menu-id');
if (menuId && menuId.endsWith('-' + answerText.toUpperCase())) {
return true;
}
}
if (text.includes(answerText) || answerText.includes(text)) {
return true;
}
return false;
});
if (targetOption) break;
}
if (targetOption) break;
}
if (targetOption) break;
}
if (targetOption) {
console.log(`[在线题库] 找到选项: ${targetOption.textContent.trim()}`);
await simulateHumanBehavior(targetOption);
targetOption.click();
await new Promise(r => setTimeout(r, 400));
const updatedTriggers = document.querySelectorAll(dropdownType);
if (i < updatedTriggers.length) {
const updatedTrigger = updatedTriggers[i];
const updatedAnswerElement = updatedTrigger.querySelector('.user-answer-text, .ant-select-selection-item');
if (updatedAnswerElement) {
const selectedText = updatedAnswerElement.textContent.trim();
if (selectedText !== '点击选择' && selectedText !== 'Click to select') {
console.log(`[在线题库] ✓ 第 ${i + 1} 题选择成功: ${selectedText}`);
}
}
}
} else {
console.error(`[在线题库] 第 ${i + 1} 题未找到选项: ${answerText}`);
console.log(`[在线题库] 正在查找的答案文本: "${answerText}"`);
const escEvent = new KeyboardEvent('keydown', {
key: 'Escape',
code: 'Escape',
keyCode: 27,
bubbles: true
});
document.dispatchEvent(escEvent);
await new Promise(r => setTimeout(r, 300));
}
}
console.log('[在线题库] 所有下拉选择题已完成');
return;
}
const fillInInputs = document.querySelectorAll('.fe-scoop input, .comp-abs-input input, textarea.question-inputbox-input, .question-inputbox-input, textarea.question-textarea-content');
if (fillInInputs.length > 0) {
console.log(`[在线题库] 检测到 ${fillInInputs.length} 个填空题`);
for (let i = 0; i < fillInInputs.length; i++) {
if (i >= answers.length) break;
const input = fillInInputs[i];
const answer = answers[i];
if (input.value === answer) {
continue;
}
await simulateHumanBehavior(input);
input.focus();
const isTextarea = input.tagName.toLowerCase() === 'textarea';
const answerWithNewline = answer + '\n';
try {
if (isTextarea) {
const nativeTextareaSetter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, "value").set;
nativeTextareaSetter.call(input, answerWithNewline);
} else {
const nativeInputSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value").set;
nativeInputSetter.call(input, answerWithNewline);
}
} catch (e) {
input.value = answerWithNewline;
}
input.dispatchEvent(new Event('input', { bubbles: true }));
input.dispatchEvent(new Event('change', { bubbles: true }));
input.dispatchEvent(new Event('blur', { bubbles: true }));
await new Promise(r => setTimeout(r, 200 + Math.random() * 200));
}
return;
}
const allOptions = document.querySelectorAll('.option.isNotReview, div.option');
console.log(`[在线题库] 检测到 ${allOptions.length} 个选项,识别为选择题`);
const questionGroups = [];
let currentGroup = [];
const firstCaption = allOptions[0]?.querySelector('.caption');
const firstLetter = firstCaption ? firstCaption.textContent.trim() : 'A';
const isSpecialType = !['A', 'B', 'C', 'D', 'E', 'F'].includes(firstLetter);
console.log(`[在线题库] 题型检测: ${isSpecialType ? '特殊题型(' + firstLetter + ')' : '标准题型(A/B/C/D)'}`);
if (isSpecialType) {
for (let i = 0; i < allOptions.length; i += 2) {
const group = [];
if (allOptions[i]) group.push(allOptions[i]);
if (allOptions[i + 1]) group.push(allOptions[i + 1]);
if (group.length > 0) {
questionGroups.push(group);
}
}
console.log(`[在线题库] 特殊题型分组: ${questionGroups.length} 道题`);
} else {
allOptions.forEach((option) => {
const caption = option.querySelector('.caption');
if (caption) {
const letter = caption.textContent.trim();
if (letter === 'A' && currentGroup.length > 0) {
questionGroups.push([...currentGroup]);
currentGroup = [];
}
currentGroup.push(option);
}
});
if (currentGroup.length > 0) {
questionGroups.push(currentGroup);
}
console.log(`[在线题库] 标准题型分组: ${questionGroups.length} 道题`);
}
if (questionGroups.length > 0) {
if (questionGroups.length !== answers.length) {
console.warn(`[在线题库] 警告:识别出 ${questionGroups.length} 道题,但获取到 ${answers.length} 个答案。`);
}
const questionsToProcess = Math.min(questionGroups.length, answers.length);
for (let i = 0; i < questionsToProcess; i++) {
const optionsGroup = questionGroups[i];
const rawAnswer = answers[i];
let answersToSelect = [];
if (rawAnswer.includes(',')) {
answersToSelect = rawAnswer.split(',').map(letter => letter.trim().toUpperCase());
} else {
answersToSelect = [rawAnswer.trim().toUpperCase()];
}
for (const answerLetter of answersToSelect) {
let targetOption = null;
for (const option of optionsGroup) {
const caption = option.querySelector('.caption');
if (caption && caption.textContent.trim() === answerLetter) {
targetOption = option;
break;
}
}
if (targetOption) {
if (targetOption.classList.contains('selected')) {
continue;
}
await simulateHumanBehavior(targetOption);
targetOption.click();
await new Promise(r => setTimeout(r, 200 + Math.random() * 200));
}
}
}
return;
}
}
function getCurrentPathFromData() {
try {
const breadcrumbs = document.querySelectorAll('.ant-breadcrumb-link span');
if (breadcrumbs.length === 0) {
console.warn('未能找到面包屑(breadcrumb)元素, 路径可能不完整。');
}
const navigationPath = Array.from(breadcrumbs).map(span => span.textContent.trim());
const activeTopicElement = document.querySelector('.pc-header-tab-activity');
const activeTopicName = activeTopicElement ? activeTopicElement.textContent.trim() : '';
const subTopicElement = document.querySelector('.pc-task.pc-header-task-activity');
const subTopicName = subTopicElement ? subTopicElement.textContent.trim() : '';
const pathParts = [...navigationPath];
if (activeTopicName && !pathParts.includes(activeTopicName)) {
pathParts.push(activeTopicName);
}
if (subTopicName && !pathParts.includes(subTopicName)) {
pathParts.push(subTopicName);
}
const fullPath = pathParts.join(' > ');
console.log('生成的当前页面路径:', fullPath);
return fullPath;
} catch (error) {
console.error('获取当前页面路径时出错:', error);
return null;
}
}
async function handleGenericCommentSection() {
const commentTextArea = document.querySelector('textarea.ant-input[placeholder="我来评论"]');
if (!commentTextArea) {
return false;
}
const submitButton = document.querySelector('.btns-submit button.submit-btn');
if (!submitButton) {
return false;
}
if (submitButton.disabled || (!submitButton.disabled && !commentTextArea.value)) {
console.log('[自动评论] 检测到评论框,准备处理...');
} else {
console.log('[自动评论] 评论框已有内容或状态异常,跳过。');
return false;
}
let textToType = localStorage.getItem('u-default-comment') || '';
const selectedBank = document.getElementById('online-bank-selector')?.value;
const hasOnlineBank = selectedBank && selectedBank.trim() !== '';
if (useKimiAI && hasOnlineBank) {
console.log('[自动评论] AI模式已启用且有在线题库,评论使用AI分析...');
try {
const discussionTitle = document.querySelector('#top .discussion-title, .discussion-title');
const titleText = discussionTitle ? discussionTitle.textContent.trim() : '';
const discussionContent = document.querySelector('#top .question-common-abs-material, #top .text-material-wrapper, .question-common-abs-material');
const contentText = discussionContent ? discussionContent.textContent.trim() : '';
if (titleText || contentText) {
console.log('[自动评论] 找到讨论内容');
const prompt = `请帮我回答以下讨论问题。请用英语回答,回答要简洁、自然,大约50-100词。
${titleText ? `讨论主题:${titleText}` : ''}
${contentText ? `讨论内容:\n${contentText}` : ''}
要求:
1. 用英语回答
2. 回答要简洁、有实质性内容
3. 回答要自然、像是真实学生的想法
4. 总字数控制在50-100词左右
5. 不要加标题或序号,直接给出答案段落`;
const aiResponse = await askKimi(prompt);
if (aiResponse && aiResponse.trim()) {
textToType = aiResponse.trim();
console.log('[自动评论] AI生成的评论:', textToType.substring(0, 50) + '...');
}
} else {
console.log('[自动评论] 未找到讨论内容,尝试使用默认评论');
}
} catch (error) {
console.error('[自动评论] AI分析失败:', error);
}
} else if (useKimiAI && !hasOnlineBank) {
console.log(`[自动评论] AI已启用但无在线题库,为节省积分,使用默认文本`);
} else {
console.log(`[自动评论] AI未启用,使用默认评论文本`);
}
if (!textToType || textToType.trim() === '') {
console.warn('[自动评论] ⚠️ 警告:要输入的评论内容为空(默认评论为空且AI未生成),已跳过此题,防止卡死。');
return false;
}
commentTextArea.focus();
const nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, "value").set;
nativeInputValueSetter.call(commentTextArea, textToType);
commentTextArea.dispatchEvent(new Event('input', { bubbles: true }));
console.log('[自动评论] 已输入评论:', textToType.substring(0, 50) + (textToType.length > 50 ? '...' : ''));
let waitCount = 0;
await new Promise(resolve => {
const checkButton = () => {
if (!submitButton.disabled) {
console.log('[自动评论] 发布按钮已激活');
resolve();
} else {
waitCount++;
if (waitCount > 50) {
console.error('[自动评论] ❌ 超时:内容已输入但发布按钮未激活,跳过点击。');
resolve();
} else {
setTimeout(checkButton, 200);
}
}
};
checkButton();
});
if (submitButton.disabled) {
return false;
}
await sleep(500);
console.log('[自动评论] 点击发布按钮...');
submitButton.click();
return true;
}
function analyzePageQuestions() {
const result = {
count: 1,
type: 'unknown',
elements: []
};
console.log(`[多页教材] 🔍 开始分析页面题目结构...`);
const sortableWrapper = document.querySelector('#sortableListWrapper, .sortable-list-wrapper');
if (sortableWrapper) {
const sortableItems = sortableWrapper.querySelectorAll('.sortable-list-question-no');
result.count = sortableItems.length > 0 ? sortableItems.length : 1;
result.type = 'sorting';
result.elements = [sortableWrapper];
console.log(`[多页教材] ✅ 通过排序容器检测到 1 个拖动排序题,需要 ${result.count} 个答案。`);
return result;
}
const classicSortingContainer = document.querySelector('div.sequence-pc--sequence-container-33roc, div[class*="sequence-pc--sequence-container"]');
if (classicSortingContainer) {
const sortableItems = classicSortingContainer.querySelectorAll('div.sequence-pc-card--item-3CfJy, div[class*="sequence-pc-card--item"]');
result.count = sortableItems.length > 0 ? sortableItems.length : 1;
result.type = 'classic_sorting';
result.elements = [classicSortingContainer];
console.log(`[多页教材] ✅ 检测到普通U校园版拖动排序题,需要 ${result.count} 个答案。`);
return result;
}
const fillInInputs = document.querySelectorAll('input.fill-blank--bc-input-DelG1, .fe-scoop input:not([type="hidden"]), .comp-abs-input input, textarea.question-inputbox-input, .question-inputbox-input, textarea.question-textarea-content, textarea.writing--textarea-36VPs, textarea.scoopFill_textarea');
if (fillInInputs.length > 0) {
result.count = fillInInputs.length;
result.type = 'fill_in';
result.elements = Array.from(fillInInputs);
console.log(`[多页教材] ✅ 通过输入框检测到 ${result.count} 个填空题`);
return result;
}
const itestSections = document.querySelectorAll('.itest-section');
if (itestSections.length > 0) {
const allRadioInputs = document.querySelectorAll('.itest-danxuan input[type="radio"]');
const allTextInputs = document.querySelectorAll('.blankinput');
const totalQuestions = new Set();
allRadioInputs.forEach(input => {
const qindex = input.getAttribute('qindex');
if (qindex) totalQuestions.add(qindex);
});
allTextInputs.forEach(input => {
const qindex = input.getAttribute('qindex');
if (qindex) totalQuestions.add(qindex);
});
result.count = totalQuestions.size;
result.type = 'itest_mixed';
result.elements = [document.querySelector('#all-content') || document.body];
console.log(`[多页教材] ✅ 检测到itest混合题型,包含 ${result.count} 个题目`);
console.log(`[多页教材] 单选题数量: ${allRadioInputs.length}, 填空题数量: ${allTextInputs.length}`);
return result;
}
const multipleChoiceContainers = document.querySelectorAll('.MultipleChoice--checkbox-item-34A_-');
if (multipleChoiceContainers.length > 0) {
result.count = 1;
result.type = 'multiple_choice';
result.elements = [document.querySelector('.questions--question-3Yw9p') || document.body];
console.log(`[多页教材] ✅ 检测到普通U校园版多选题,包含 ${multipleChoiceContainers.length} 个选项`);
return result;
}
const classicChoiceContainers = document.querySelectorAll('ul[class*="single-choice"]');
if (classicChoiceContainers.length > 0) {
result.count = classicChoiceContainers.length;
result.type = 'classic_choice';
result.elements = Array.from(classicChoiceContainers);
console.log(`[多页教材] ✅ 检测到普通U校园版 ${result.count} 个单选题`);
return result;
}
const allOptions = document.querySelectorAll('.option.isNotReview, div.option');
if (allOptions.length > 0) {
const questionGroups = [];
let currentGroup = [];
const firstCaption = allOptions[0]?.querySelector('.caption');
const firstLetter = firstCaption ? firstCaption.textContent.trim() : 'A';
const isSpecialType = !['A', 'B', 'C', 'D', 'E', 'F'].includes(firstLetter);
if (isSpecialType) {
for (let i = 0; i < allOptions.length; i += 2) {
const group = [allOptions[i], allOptions[i + 1]].filter(Boolean);
if (group.length > 0) questionGroups.push(group);
}
result.type = 'special_choice';
} else {
allOptions.forEach((option) => {
const caption = option.querySelector('.caption');
if (caption && caption.textContent.trim() === 'A' && currentGroup.length > 0) {
questionGroups.push([...currentGroup]);
currentGroup = [];
}
currentGroup.push(option);
});
if (currentGroup.length > 0) questionGroups.push(currentGroup);
result.type = 'standard_choice';
}
if (questionGroups.length > 0) {
result.count = questionGroups.length;
result.elements = questionGroups;
console.log(`[多页教材] ✅ 通过选择题分组检测到 ${result.count} 个题目 (${result.type})`);
return result;
}
}
const questionContainers = document.querySelectorAll('.question-common-abs-reply, .question-common-abs-banked-cloze');
if (questionContainers.length > 0) {
result.count = questionContainers.length;
result.type = 'containers';
result.elements = Array.from(questionContainers);
console.log(`[多页教材] ⚠️ 回退到容器检测,找到 ${result.count} 个题目容器`);
return result;
}
console.warn(`[多页教材] ⚠️ 无法准确检测到页面题目,默认为1个`);
return result;
}
function getCurrentPageQuestionCount() {
return analyzePageQuestions().count;
}
async function fillAnswersForMultiPage(answers) {
const questionAnalysis = analyzePageQuestions();
const { count, type, elements } = questionAnalysis;
console.log(`[多页教材] 📝 开始填写 ${answers.length} 个答案到 ${count} 个 ${type} 类型的题目`);
if (answers.length < count) {
console.warn(`[多页教材] ⚠️ 答案数量 (${answers.length}) 与题目数量 (${count}) 不匹配`);
}
const questionsToProcess = Math.min(count, answers.length);
switch (type) {
case 'sorting':
console.log(`[多页教材] 检测到排序题,使用在线题库逻辑处理`);
await fillAnswersFromArray(answers);
break;
case 'classic_sorting':
console.log(`[多页教材] 检测到普通U校园版排序题`);
await fillClassicSortingQuestions(elements[0], answers);
break;
case 'containers':
await fillContainerQuestions(elements, answers, questionsToProcess);
break;
case 'fill_in':
await fillInputQuestions(elements, answers, questionsToProcess);
break;
case 'standard_choice':
case 'special_choice':
await fillChoiceQuestions(elements, answers, questionsToProcess, type === 'special_choice');
break;
case 'classic_choice':
await fillClassicChoiceQuestions(elements, answers, questionsToProcess);
break;
case 'multiple_choice':
console.log(`[多页教材] 检测到普通U校园版多选题`);
await fillMultipleChoiceQuestions(elements[0], answers[0]);
break;
case 'itest_mixed':
console.log(`[多页教材] 检测到itest混合题型`);
await fillItestMixedQuestions(elements[0], answers);
break;
default:
console.warn(`[多页教材] ⚠️ 未知题目类型: ${type},尝试使用原始填答逻辑`);
await fillAnswersFromArray(answers);
break;
}
console.log(`[多页教材] ✅ 完成填写 ${questionsToProcess} 个题目`);
}
async function fillItestMixedQuestions(questionElement, answers) {
console.log(`[多页教材] 开始处理itest混合题型,答案数量:`, answers.length);
const allInputs = [];
const radioInputs = document.querySelectorAll('.itest-danxuan input[type="radio"]');
radioInputs.forEach(input => {
const qindex = parseInt(input.getAttribute('qindex'));
if (qindex && !isNaN(qindex)) {
if (!allInputs[qindex - 1]) {
allInputs[qindex - 1] = { type: 'radio', elements: [] };
}
allInputs[qindex - 1].elements.push(input);
}
});
const textInputs = document.querySelectorAll('.blankinput');
textInputs.forEach(input => {
const qindex = parseInt(input.getAttribute('qindex'));
if (qindex && !isNaN(qindex)) {
allInputs[qindex - 1] = { type: 'text', elements: [input] };
}
});
console.log(`[多页教材] 收集到 ${allInputs.filter(Boolean).length} 个题目`);
for (let i = 0; i < Math.min(allInputs.length, answers.length); i++) {
const questionData = allInputs[i];
const answer = answers[i];
if (!questionData || !answer) continue;
console.log(`[多页教材] 处理第 ${i + 1} 题,类型: ${questionData.type},答案:`, answer);
if (questionData.type === 'radio') {
await fillItestRadioQuestion(questionData.elements, answer, i + 1);
} else if (questionData.type === 'text') {
await fillItestTextQuestion(questionData.elements[0], answer, i + 1);
}
await new Promise(resolve => setTimeout(resolve, 300 + Math.random() * 200));
}
console.log('[多页教材] itest混合题型处理完成');
}
async function fillItestRadioQuestion(radioElements, answer, questionNum) {
console.log(`[多页教材] 处理第 ${questionNum} 题单选题,答案: ${answer}`);
let targetLetter = '';
if (typeof answer === 'string') {
const letterMatch = answer.match(/[A-Z]/i);
if (letterMatch) {
targetLetter = letterMatch[0].toUpperCase();
}
}
if (!targetLetter) {
console.warn(`[多页教材] 第 ${questionNum} 题无法解析答案: ${answer}`);
return;
}
for (const radio of radioElements) {
const label = radio.closest('label');
if (label) {
const labelText = label.textContent.trim();
const optionMatch = labelText.match(/^\s*([A-Z])\./);
if (optionMatch && optionMatch[1] === targetLetter) {
console.log(`[多页教材] 第 ${questionNum} 题选择选项 ${targetLetter}`);
radio.checked = true;
radio.dispatchEvent(new Event('change', { bubbles: true }));
radio.dispatchEvent(new Event('click', { bubbles: true }));
break;
}
}
}
}
async function fillItestTextQuestion(textInput, answer, questionNum) {
console.log(`[多页教材] 处理第 ${questionNum} 题填空题,答案: ${answer}`);
if (textInput && answer) {
const answerWithNewline = answer.toString() + '\n';
textInput.value = answerWithNewline;
textInput.dispatchEvent(new Event('input', { bubbles: true }));
textInput.dispatchEvent(new Event('change', { bubbles: true }));
console.log(`[多页教材] 第 ${questionNum} 题填入答案: ${answer} (已添加换行符)`);
}
}
async function fillMultipleChoiceQuestions(questionElement, answer) {
console.log(`[多页教材] 开始处理多选题,答案:`, answer);
let answerString = answer;
if (Array.isArray(answer)) {
answerString = answer.join(',');
} else if (typeof answer === 'object') {
answerString = JSON.stringify(answer);
}
console.log('处理后的答案字符串:', answerString);
const options = document.querySelectorAll('.MultipleChoice--checkbox-item-34A_-');
console.log('找到的选项数量:', options.length);
const letterMatches = answerString.match(/[A-Z]/gi);
if (!letterMatches || letterMatches.length === 0) {
console.warn('[多页教材] 未能从答案中提取到有效字母');
return;
}
console.log('需要选择的选项:', letterMatches);
for (const option of options) {
const optLabel = option.querySelector('.MultipleChoice--checkbox-opt-2F4xY');
if (optLabel) {
const letter = optLabel.textContent.trim().replace('.', '');
if (letterMatches.includes(letter.toUpperCase())) {
console.log(`[多页教材] 选择选项 ${letter}`);
const checkbox = option.querySelector('input[type="checkbox"]');
if (checkbox) {
checkbox.checked = true;
checkbox.dispatchEvent(new Event('change', { bubbles: true }));
checkbox.dispatchEvent(new Event('click', { bubbles: true }));
await new Promise(resolve => setTimeout(resolve, 200 + Math.random() * 300));
}
}
}
}
console.log('[多页教材] 多选题处理完成');
}
async function fillContainerQuestions(containers, answers, questionsToProcess) {
for (let i = 0; i < questionsToProcess; i++) {
const container = containers[i];
const answer = answers[i];
const options = container.querySelectorAll('.option.isNotReview, div.option');
if (options.length > 0) {
let targetOption = null;
for (const option of options) {
const caption = option.querySelector('.caption');
if (caption && caption.textContent.trim() === answer.trim()) {
targetOption = option;
break;
}
}
if (targetOption && !targetOption.classList.contains('selected')) {
console.log(`[多页教材] 第 ${i + 1} 题选择: ${answer}`);
await simulateHumanBehavior(targetOption);
targetOption.click();
await new Promise(r => setTimeout(r, 200 + Math.random() * 200));
}
}
}
}
async function fillInputQuestions(inputs, answers, questionsToProcess) {
for (let i = 0; i < questionsToProcess; i++) {
const input = inputs[i];
const answer = answers[i];
if (input.value === answer) {
continue;
}
console.log(`[多页教材] 第 ${i + 1} 题填写: ${answer}`);
await simulateHumanBehavior(input);
input.focus();
const isTextarea = input.tagName.toLowerCase() === 'textarea';
const answerWithNewline = answer + '\n';
try {
if (isTextarea) {
const nativeTextareaSetter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, "value").set;
nativeTextareaSetter.call(input, answerWithNewline);
} else {
const nativeInputSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value").set;
nativeInputSetter.call(input, answerWithNewline);
}
} catch (e) {
input.value = answerWithNewline;
}
input.dispatchEvent(new Event('input', { bubbles: true }));
input.dispatchEvent(new Event('change', { bubbles: true }));
input.dispatchEvent(new Event('blur', { bubbles: true }));
await new Promise(r => setTimeout(r, 200 + Math.random() * 200));
}
}
async function fillDropdownQuestions(triggers, answers, questionsToProcess) {
for (let i = 0; i < questionsToProcess; i++) {
const trigger = triggers[i];
const answer = answers[i];
console.log(`[多页教材] 第 ${i + 1} 题下拉选择: ${answer}`);
const currentAnswerElement = trigger.querySelector('.user-answer-text, .ant-select-selection-item');
if (currentAnswerElement) {
const currentText = currentAnswerElement.textContent.trim();
if (currentText === answer.trim() ||
currentText.toLowerCase() === answer.toLowerCase()) {
console.log(`[多页教材] 第 ${i + 1} 题已选择正确答案: ${currentText}`);
continue;
}
}
await simulateHumanBehavior(trigger);
trigger.click();
await new Promise(resolve => setTimeout(resolve, 600));
const menuSelectors = [
'.ant-dropdown-menu.scoop-select',
'.ant-select-dropdown:not(.ant-select-dropdown-hidden)',
'.rc-virtual-list'
];
let targetOption = null;
for (const menuSelector of menuSelectors) {
const allMenus = document.querySelectorAll(menuSelector);
for (const menu of allMenus) {
if (window.getComputedStyle(menu).display === 'none') continue;
const options = menu.querySelectorAll('li.select-option, .ant-select-item-option, div.ant-select-item');
targetOption = Array.from(options).find(opt => {
const text = opt.textContent.trim();
return text.toLowerCase() === answer.toLowerCase() ||
text === answer ||
(answer.length === 1 && (text === answer.toUpperCase() || text.startsWith(answer.toUpperCase() + '.')));
});
if (targetOption) break;
}
if (targetOption) break;
}
if (targetOption) {
console.log(`[多页教材] 找到选项: ${targetOption.textContent.trim()}`);
await simulateHumanBehavior(targetOption);
targetOption.click();
await new Promise(r => setTimeout(r, 400));
} else {
console.error(`[多页教材] 第 ${i + 1} 题未找到选项: ${answer}`);
}
}
}
async function fillChoiceQuestions(questionGroups, answers, questionsToProcess, isSpecialType) {
for (let i = 0; i < questionsToProcess; i++) {
const optionsGroup = questionGroups[i];
const answer = answers[i];
console.log(`[多页教材] 第 ${i + 1} 题选择 (${isSpecialType ? '特殊题型' : '标准题型'}): ${answer}`);
let answersToSelect = [];
if (answer.includes(',')) {
answersToSelect = answer.split(',').map(letter => letter.trim().toUpperCase());
} else {
answersToSelect = [answer.trim().toUpperCase()];
}
for (const answerLetter of answersToSelect) {
let targetOption = null;
for (const option of optionsGroup) {
const caption = option.querySelector('.caption');
if (caption && caption.textContent.trim() === answerLetter) {
targetOption = option;
break;
}
}
if (targetOption && !targetOption.classList.contains('selected')) {
await simulateHumanBehavior(targetOption);
targetOption.click();
await new Promise(r => setTimeout(r, 200 + Math.random() * 200));
}
}
}
}
async function fillClassicSortingQuestions(container, answers) {
console.log(`[多页教材] 开始处理普通U校园版排序题,答案:`, answers);
const sortableItems = container.querySelectorAll('div.sequence-pc-card--item-3CfJy, div[class*="sequence-pc-card--item"]');
if (sortableItems.length === 0) {
console.warn('[多页教材] 未找到可排序的项目');
return;
}
const answerMap = {};
for (let i = 0; i < answers.length; i++) {
answerMap[i] = answers[i].trim().toUpperCase();
}
const optionMap = new Map();
sortableItems.forEach(item => {
const captionDiv = item.querySelector('div.sequence-pc-card--caption-item-1Z3e-, div[class*="sequence-pc-card--caption-item"]');
if (captionDiv) {
const letter = captionDiv.textContent.trim().replace('.', '');
optionMap.set(letter, item);
console.log(`[多页教材] 找到排序项: ${letter}`);
}
});
const rows = container.querySelectorAll('table.sequence-pc--sequence-table-1vFDc tbody tr, table[class*="sequence-pc--sequence-table"] tbody tr');
if (rows.length === 0) {
console.warn('[多页教材] 未找到表格行');
return;
}
const correctOrder = [];
for (let i = 0; i < answers.length; i++) {
const answerLetter = answerMap[i];
for (const row of rows) {
const captionDiv = row.querySelector('div.sequence-pc-card--caption-item-1Z3e-, div[class*="sequence-pc-card--caption-item"]');
if (captionDiv) {
const letter = captionDiv.textContent.trim().replace('.', '');
if (letter === answerLetter) {
correctOrder.push(row);
break;
}
}
}
}
const tbody = container.querySelector('table.sequence-pc--sequence-table-1vFDc tbody, table[class*="sequence-pc--sequence-table"] tbody');
if (!tbody) {
console.warn('[多页教材] 未找到 tbody 元素');
return;
}
while (tbody.firstChild) {
tbody.removeChild(tbody.firstChild);
}
correctOrder.forEach((row) => {
tbody.appendChild(row);
});
for (let i = 0; i < answers.length; i++) {
const answerLetter = answerMap[i];
const targetOption = optionMap.get(answerLetter);
if (!targetOption) continue;
const rect = targetOption.getBoundingClientRect();
const centerX = rect.left + rect.width / 2;
const centerY = rect.top + rect.height / 2;
const touchstartEvent = new TouchEvent('touchstart', {
bubbles: true,
cancelable: true,
touches: [new Touch({
identifier: i,
target: targetOption,
clientX: centerX,
clientY: centerY
})]
});
targetOption.dispatchEvent(touchstartEvent);
await sleep(50);
const touchendEvent = new TouchEvent('touchend', {
bubbles: true,
cancelable: true,
changedTouches: [new Touch({
identifier: i,
target: targetOption,
clientX: centerX,
clientY: centerY + 2
})]
});
targetOption.dispatchEvent(touchendEvent);
await sleep(50);
}
const finalEvents = ['change', 'input', 'update', 'sort'];
finalEvents.forEach(eventType => {
container.dispatchEvent(new Event(eventType, { bubbles: true }));
});
window.__sortableAnswers__ = {
answers: answers,
answerMap: answerMap,
timestamp: Date.now()
};
console.log('[多页教材] 普通U校园版排序题处理完成');
await sleep(500);
}
async function fillClassicChoiceQuestions(choiceContainers, answers, questionsToProcess) {
for (let i = 0; i < questionsToProcess; i++) {
const container = choiceContainers[i];
const answer = answers[i];
console.log(`[多页教材] 第 ${i + 1} 题选择 (普通版): ${answer}`);
const cleanAnswer = answer.trim().toLowerCase();
const labels = container.querySelectorAll('li label');
let targetInput = null;
let targetLetter = null;
const isLetterAnswer = cleanAnswer.length === 1 && /^[a-z]$/i.test(cleanAnswer);
if (isLetterAnswer) {
const answerLetter = cleanAnswer.toUpperCase();
for (const label of labels) {
const input = label.querySelector('input[type="radio"]');
const indexSpan = label.querySelector('span[class*="index"]');
if (input && indexSpan) {
const letter = indexSpan.textContent.trim().replace('.', '');
if (letter === answerLetter) {
targetInput = input;
targetLetter = letter;
console.log(`[多页教材] 通过字母匹配找到选项 ${letter}`);
break;
}
}
}
} else {
for (const label of labels) {
const input = label.querySelector('input[type="radio"]');
const indexSpan = label.querySelector('span[class*="index"]');
const contentDiv = label.querySelector('div.html-view[class*="content"]');
if (input && indexSpan && contentDiv) {
const letter = indexSpan.textContent.trim().replace('.', '');
const contentText = contentDiv.textContent.trim().toLowerCase();
if (contentText === cleanAnswer ||
contentText.includes(cleanAnswer) ||
cleanAnswer.includes(contentText)) {
targetInput = input;
targetLetter = letter;
console.log(`[多页教材] 通过内容匹配找到选项 ${letter}`);
break;
}
}
}
}
if (targetInput && !targetInput.checked) {
await simulateHumanBehavior(targetInput);
targetInput.checked = true;
targetInput.dispatchEvent(new Event('change', { bubbles: true }));
targetInput.dispatchEvent(new Event('click', { bubbles: true }));
console.log(`[多页教材] 已选中选项 ${targetLetter}`);
await new Promise(r => setTimeout(r, 200 + Math.random() * 200));
} else if (targetInput && targetInput.checked) {
console.log(`[多页教材] 选项 ${targetLetter} 已经被选中`);
} else {
console.warn(`[多页教材] 未找到匹配的选项: ${answer}`);
}
}
}
function updateMultiPageStatus() {
const statusDiv = document.getElementById('multi-page-status');
const activeSpan = document.getElementById('multi-page-active');
const indexSpan = document.getElementById('multi-page-index');
const totalSpan = document.getElementById('multi-page-total');
if (!statusDiv || !activeSpan || !indexSpan || !totalSpan) return;
if (multiPageMode.isActive) {
statusDiv.style.display = 'block';
activeSpan.textContent = '已启用';
activeSpan.style.color = '#28a745';
indexSpan.textContent = `已用答案: ${multiPageMode.pageIndex}`;
totalSpan.textContent = multiPageMode.totalAnswers.length;
} else {
statusDiv.style.display = 'none';
}
}
function setupMultiPageNavigationListener() {
console.log('[多页教材] 设置导航监听器...');
document.addEventListener('click', (event) => {
const target = event.target;
const isNextButton = target && (
target.textContent?.includes('下一题') ||
target.textContent?.includes('Next') ||
target.textContent?.includes('下一页') ||
target.textContent?.includes('继续') ||
target.classList?.contains('next-btn') ||
target.classList?.contains('btn-next') ||
target.classList?.contains('next') ||
target.closest('button')?.textContent?.includes('下一题') ||
target.closest('button')?.textContent?.includes('Next') ||
target.closest('.btn')?.textContent?.includes('下一题')
);
if (isNextButton && multiPageMode.isActive) {
console.log('[多页教材] 检测到下一题按钮点击。页面索引已在答题后更新,当前索引:', multiPageMode.pageIndex);
console.log('[多页教材] 等待页面内容更新...');
}
});
window.multiPageNext = function() {
if (multiPageMode.isActive) {
console.log(`[多页教材] 手动触发答题,当前索引: ${multiPageMode.pageIndex}`);
autoSelectAnswers();
} else {
console.log('[多页教材] 当前不在多页模式,无法使用此功能');
}
};
window.multiPageReset = function() {
if (multiPageMode.isActive) {
multiPageMode.pageIndex = 0;
console.log('[多页教材] 已重置页面索引为 0');
updateMultiPageStatus();
}
};
window.multiPageStatus = function() {
console.log('[多页教材] 当前状态:', {
isActive: multiPageMode.isActive,
exerciseId: multiPageMode.exerciseId,
pageIndex: multiPageMode.pageIndex,
totalAnswers: multiPageMode.totalAnswers.length,
allAnswers: multiPageMode.totalAnswers
});
if (multiPageMode.isActive) {
const questionAnalysis = analyzePageQuestions();
console.log('[多页教材] 当前页面分析:', questionAnalysis);
const remainingAnswers = multiPageMode.totalAnswers.slice(multiPageMode.pageIndex);
console.log('[多页教材] 剩余答案:', remainingAnswers);
}
};
window.multiPageDebug = function() {
console.log('=== 多页教材调试信息 ===');
const analysis = analyzePageQuestions();
console.log('页面题目分析:', analysis);
console.log('元素统计:');
console.log('- 题目容器:', document.querySelectorAll('.question-common-abs-reply, .question-common-abs-banked-cloze').length);
console.log('- 填空输入框:', document.querySelectorAll('.fe-scoop input:not([type="hidden"]), textarea.question-inputbox-input').length);
console.log('- 下拉框:', document.querySelectorAll('.fe-scoop[data-scoop-index], .ant-dropdown-trigger').length);
console.log('- 选择题选项:', document.querySelectorAll('.option.isNotReview, div.option').length);
console.log('- A选项数量:', Array.from(document.querySelectorAll('.option.isNotReview, div.option')).filter(opt => {
const caption = opt.querySelector('.caption');
return caption && caption.textContent.trim() === 'A';
}).length);
if (multiPageMode.isActive) {
console.log('多页模式状态:', multiPageMode);
console.log('下次将使用的答案:', multiPageMode.totalAnswers.slice(multiPageMode.pageIndex, multiPageMode.pageIndex + analysis.count));
}
console.log('=== 调试信息结束 ===');
return {
analysis,
multiPageMode,
nextAnswers: multiPageMode.isActive ? multiPageMode.totalAnswers.slice(multiPageMode.pageIndex, multiPageMode.pageIndex + analysis.count) : []
};
};
console.log('[多页教材] 导航监听器设置完成。可使用 multiPageNext() 手动切换到下一页');
}
function initAutoRefresh() {
const savedRefreshEnabled = localStorage.getItem('u-helper-auto-refresh') === 'true';
const savedRefreshInterval = localStorage.getItem('u-helper-refresh-interval') || '30';
const savedPopupRefresh = localStorage.getItem('u-helper-popup-refresh') === 'true';
window.__refreshInterval = parseFloat(savedRefreshInterval);
window.__refreshAfterPopupBlock = savedPopupRefresh;
if (savedRefreshEnabled) {
autoRefreshEnabled = true;
startAutoRefresh();
console.log('[自动刷新] ✅ 自动刷新功能已启动');
} else {
console.log('[自动刷新] 自动刷新功能已禁用');
}
console.log('[弹窗拦截] 拦截后刷新设置:', window.__refreshAfterPopupBlock ? '已启用' : '已禁用');
}
function setupPopupInterception() {
const originalAlert = window.alert;
const originalConfirm = window.confirm;
const originalPrompt = window.prompt;
window.alert = function(message) {
console.log('[弹窗拦截] alert弹窗:', message);
if (message &&
!message.includes('匹配成功') &&
!message.includes('不匹配') &&
(
message.includes('在线题库') ||
message.includes('查询失败') ||
message.includes('未找到') ||
message.includes('在该题库中未找到此练习的答案')
)
) {
console.log('[弹窗拦截] 🚫 检测到题库查询失败弹窗,自动拦截');
showRefreshNotification('🚫 题库错误或该题目为主观题/口语题,没有标准答案', 'info');
setTimeout(() => {
console.log('[弹窗拦截] ⏭️ 2秒延迟后继续挂机流程');
continueAutoMode();
}, 2000);
return true;
}
return originalAlert(message);
};
window.confirm = function(message) {
console.log('[弹窗拦截] confirm弹窗:', message);
if (message && (
message.includes('在线题库') ||
message.includes('查询失败') ||
message.includes('未找到')
)) {
console.log('[弹窗拦截] 🚫 检测到题库相关确认弹窗,自动确认');
return true;
}
return originalConfirm(message);
};
window.prompt = function(message, defaultValue) {
console.log('[弹窗拦截] prompt弹窗:', message);
if (message && (
message.includes('在线题库') ||
message.includes('查询失败')
)) {
console.log('[弹窗拦截] 🚫 检测到题库相关输入弹窗,自动返回默认值');
return defaultValue || '';
}
return originalPrompt(message, defaultValue);
};
console.log('[弹窗拦截] ✅ 弹窗拦截功能已启用');
}
function continueAutoMode() {
if (window.isAutoModeRunning) {
console.log('[弹窗拦截] 🔄 继续执行自动挂机模式...');
const continueButtons = document.querySelectorAll(`
.next-btn, .continue-btn, .btn-next,
[class*="next"], [class*="continue"],
.ant-btn-primary, .el-button--primary
`);
if (continueButtons.length > 0) {
console.log('[弹窗拦截] 🖱️ 找到继续按钮,自动点击');
continueButtons[0].click();
} else if (window.__refreshAfterPopupBlock) {
console.log('[弹窗拦截] 🔄 未找到继续按钮,用户已启用刷新选项,准备刷新页面');
setTimeout(() => {
location.reload();
}, 1000);
} else {
console.log('[弹窗拦截] ⏸️ 未找到继续按钮,用户已禁用刷新选项,停止自动操作');
}
}
}
window.showAnnouncement = function(isAutoCheck = false) {
if (!isAutoCheck && typeof showModal === 'function') {
showModal('正在获取公告列表...', 'loading');
}
GM_xmlhttpRequest({
method: 'GET',
url: 'https://eghome.9vvn.com/api/get-announcements',
onload: (response) => {
try {
const res = JSON.parse(response.responseText);
if (res.status === 'success' && Array.isArray(res.data) && res.data.length > 0) {
const latestItem = res.data[0];
const latestId = latestItem.id || latestItem.date;
const lastReadId = localStorage.getItem('u-announcement-last-read');
const hasNew = lastReadId !== String(latestId);
if (isAutoCheck) {
if (hasNew) {
console.log('[公告] 发现新公告,准备弹窗...');
const dot = document.getElementById('u-notice-dot');
if (dot) dot.style.display = 'block';
window.renderAnnouncementModal(res.data);
if (typeof showRecordNotification === 'function') {
showRecordNotification('🔔 发现重要新公告', 'info');
}
} else {
console.log('[公告] 暂无新内容');
}
} else {
window.renderAnnouncementModal(res.data);
}
} else {
if (!isAutoCheck) window.renderAnnouncementModal([]);
}
} catch (e) {
console.error('[公告] 解析失败:', e);
if (!isAutoCheck) window.renderAnnouncementModal([{ title: '数据错误', content: '无法解析服务器数据', date: new Date() }]);
}
},
onerror: (err) => {
console.error('[公告] 请求失败');
if (!isAutoCheck) window.renderAnnouncementModal([{ title: '连接失败', content: '无法连接到公告服务器', date: new Date() }]);
},
ontimeout: () => {
if (!isAutoCheck) alert('请求超时');
}
});
};
window.renderAnnouncementModal = function(list) {
const existing = document.getElementById('u-announcement-modal');
if (existing) existing.remove();
const loadingModal = document.getElementById('u-helper-modal');
if (loadingModal) loadingModal.style.display = 'none';
if (list && list.length > 0) {
const latestItem = list[0];
const latestId = latestItem.id || latestItem.date;
localStorage.setItem('u-announcement-last-read', String(latestId));
const dot = document.getElementById('u-notice-dot');
if (dot) dot.style.display = 'none';
}
let listHtml = '';
if (!list || list.length === 0) {
listHtml = `暂无历史公告
`;
} else {
list.forEach(item => {
const content = (item.content || '').replace(/\n/g, '
');
const time = item.date ? new Date(item.date).toLocaleString('zh-CN', {
month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit'
}) : '';
const isPinned = item.isPinned;
const pinBadge = isPinned ?
`置顶` : '';
const cardStyle = isPinned ?
`background: #fff1f0; border-bottom: 1px solid #ffccc7; padding: 15px 10px; border-radius: 8px;` :
`border-bottom: 1px dashed #eee; padding: 15px 5px;`;
listHtml += `
${pinBadge}${item.title}
${time}
${content}
`;
});
}
const modalHtml = `
🔔 公告列表 (${list ? list.length : 0})
✕
${listHtml}
`;
document.body.insertAdjacentHTML('beforeend', modalHtml);
};
setTimeout(() => {
const btn = document.getElementById('u-notice-btn');
if(btn) {
btn.onclick = (e) => {
e.stopPropagation(); e.preventDefault();
if (typeof window.showAnnouncement === 'function') {
window.showAnnouncement();
} else {
alert('正在连接服务器,请再点一次...');
}
};
}
}, 1000);
function setupDOMPopupInterception() {
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
mutation.addedNodes.forEach((node) => {
if (node.nodeType === Node.ELEMENT_NODE) {
if (node.classList && (
node.classList.contains('product-dialog') ||
node.closest('.product-dialog')
)) {
console.log('[弹窗拦截] 🛡️ 检测到购买弹窗,放行。');
return;
}
const popupSelectors = [
'.ant-modal', '.el-dialog', '.modal', '.popup',
'[class*="dialog"]', '[class*="modal"]', '[class*="popup"]',
'[class*="Dialog"]', '[class*="Modal"]', '[class*="Popup"]'
];
let isPopup = false;
for (const selector of popupSelectors) {
if (node.matches && node.matches(selector)) {
isPopup = true;
break;
}
if (node.querySelector && node.querySelector(selector)) {
isPopup = true;
break;
}
}
if (!isPopup) {
const style = node.style || {};
const hasPopupStyle = (
style.position === 'fixed' ||
style.position === 'absolute'
) && (
style.zIndex && parseInt(style.zIndex) > 1000
);
const hasPopupContent = node.textContent && (
node.textContent.includes('本单元学习时间') ||
node.textContent.includes('是否必修') ||
(node.textContent.includes('学习时间') && node.textContent.includes('必修'))
);
if (hasPopupStyle || hasPopupContent) {
isPopup = true;
}
}
if (isPopup) {
const textContent = node.textContent || '';
console.log('[弹窗拦截] 检测到DOM弹窗:', textContent);
if (textContent.includes('在线题库') ||
textContent.includes('查询失败') ||
textContent.includes('未找到') ||
textContent.includes('在该题库中未找到此练习的答案')) {
console.log('[弹窗拦截] 🚫 检测到题库查询失败DOM弹窗,准备自动关闭');
setTimeout(() => {
const closeButtons = node.querySelectorAll(`
.ant-btn-primary, .el-button--primary, .btn-primary,
.confirm-btn, .ok-btn, .close-btn,
[class*="confirm"], [class*="ok"], [class*="close"]
`);
if (closeButtons.length > 0) {
console.log('[弹窗拦截] 🖱️ 找到关闭按钮,自动点击');
closeButtons[0].click();
} else {
console.log('[弹窗拦截] 🗑️ 未找到关闭按钮,直接移除弹窗');
node.remove();
}
continueAutoMode();
}, 2000);
showRefreshNotification('🚫 题库错误或该题目为主观题/口语题,没有标准答案', 'info');
}
else if (textContent.includes('本单元学习时间') ||
textContent.includes('是否必修') ||
(textContent.includes('学习时间') && textContent.includes('必修'))) {
console.log('[弹窗拦截] 🚫 检测到学习时间弹窗,准备自动关闭');
setTimeout(() => {
const confirmButtons = node.querySelectorAll(`
.ant-btn-primary, .el-button--primary, .btn-primary,
[class*="confirm"], [class*="ok"], button[type="button"]
`);
let confirmButton = null;
const allButtons = node.querySelectorAll('button, span, div[role="button"]');
for (const btn of allButtons) {
if (btn.textContent && btn.textContent.trim() === '确定') {
confirmButton = btn;
break;
}
}
if (confirmButton) {
console.log('[弹窗拦截] 🖱️ 找到确定按钮,自动点击');
confirmButton.click();
} else if (confirmButtons.length > 0) {
console.log('[弹窗拦截] 🖱️ 找到确认按钮,自动点击');
confirmButtons[0].click();
} else {
const closeButton = node.querySelector('.dialog-header-pc--close-yD7oN, [class*="close"]');
if (closeButton) {
console.log('[弹窗拦截] 🖱️ 找到关闭按钮,自动点击');
closeButton.click();
} else {
console.log('[弹窗拦截] 🗑️ 未找到按钮,直接移除弹窗');
node.remove();
}
}
continueAutoMode();
}, 1000);
showRefreshNotification('🚫 检测到学习时间弹窗,1秒后自动关闭', 'info');
}
}
}
});
});
});
observer.observe(document.body, {
childList: true,
subtree: true
});
console.log('[弹窗拦截] ✅ DOM弹窗监听器已启动');
const checkExistingPopups = () => {
const existingPopups = document.querySelectorAll(`
.ant-modal, .el-dialog, .modal, .popup,
[class*="dialog"], [class*="modal"], [class*="popup"],
[class*="Dialog"], [class*="Modal"], [class*="Popup"]
`);
existingPopups.forEach(popup => {
const textContent = popup.textContent || '';
if (textContent.includes('本单元学习时间') ||
textContent.includes('是否必修') ||
(textContent.includes('学习时间') && textContent.includes('必修'))) {
console.log('[弹窗拦截] 🚫 发现现有学习时间弹窗,准备自动关闭');
let confirmButton = null;
const allButtons = popup.querySelectorAll('button, span, div[role="button"]');
for (const btn of allButtons) {
if (btn.textContent && btn.textContent.trim() === '确定') {
confirmButton = btn;
break;
}
}
if (confirmButton) {
console.log('[弹窗拦截] 🖱️ 找到确定按钮,自动点击');
confirmButton.click();
showRefreshNotification('🚫 自动关闭学习时间弹窗', 'info');
} else {
const closeButton = popup.querySelector('.dialog-header-pc--close-yD7oN, [class*="close"]');
if (closeButton) {
console.log('[弹窗拦截] 🖱️ 找到关闭按钮,自动点击');
closeButton.click();
showRefreshNotification('🚫 自动关闭学习时间弹窗', 'info');
}
}
}
});
};
setTimeout(checkExistingPopups, 1000);
setInterval(checkExistingPopups, 5000);
}
function initRecordingFeatures() {
window.__autoPlayRecordEnabled = localStorage.getItem('autoPlayRecordEnabled') === 'true';
window.__selectedAudioType = localStorage.getItem('selectedAudioType') || 'british';
setupRecordingHijack();
setupURLHijack();
setupAudioSrcHijack();
monitorRecordButton();
monitorReplayAudio();
console.log('[U-record] ✅ 录音功能初始化完成');
console.log('[U-record] 自动录音状态:', window.__autoPlayRecordEnabled ? '已启用' : '已禁用');
console.log('[U-record] 音频类型:', window.__selectedAudioType === 'british' ? '英音' : '美音');
initAutoRefresh();
setupPopupInterception();
setupDOMPopupInterception();
window.debugRecording = function() {
console.log('=== 录音功能调试信息 ===');
console.log('自动录音状态:', window.__autoPlayRecordEnabled);
console.log('音频类型:', window.__selectedAudioType);
const allButtons = document.querySelectorAll(`
.record-icon, .record-fill-icon, .button-record,
[class*="record"], .microphone-btn, .mic-button
`);
console.log('找到的录音按钮:', allButtons.length);
allButtons.forEach((btn, index) => {
console.log(`按钮 ${index + 1}:`, btn.className, btn);
});
const activeSlide = document.querySelector('.swiper-slide-active');
if (activeSlide) {
console.log('当前活跃词汇卡片:', activeSlide);
const recordBtn = activeSlide.querySelector('.record-fill-icon, .record-icon, .button-record');
console.log('当前卡片录音按钮:', recordBtn);
const scoreElement = document.querySelector('.practice-score .score, .score-wrapper .score');
console.log('分数元素:', scoreElement);
if (scoreElement) {
console.log('当前分数:', scoreElement.textContent.trim());
}
}
const audios = document.querySelectorAll('audio[src]');
console.log('找到的音频元素:', audios.length);
audios.forEach((audio, index) => {
console.log(`音频 ${index + 1}:`, audio.src);
});
const containers = document.querySelectorAll('.oral-study-sentence, .question-common-abs-reply, .question-vocabulary, .vocContainer');
console.log('找到的题目容器:', containers.length);
containers.forEach((container, index) => {
console.log(`容器 ${index + 1}:`, container.className);
});
console.log('=== 调试信息结束 ===');
console.log('提示:可以在控制台运行 debugRecording() 查看录音相关元素');
};
}
document.addEventListener('DOMContentLoaded', () => {
setupMultiPageNavigationListener();
autoResumeIfNeeded();
window.testSubmitButton = function() {
console.log('=== 测试提交按钮查找 ===');
const submitBtn = findSubmitButton();
console.log('通用查找结果:', submitBtn);
const footerBtn = findFooterButtonByText('提交');
console.log('底部按钮查找结果:', footerBtn);
const dialogHandled = handleSubmitConfirmDialog();
console.log('提交确认弹窗处理结果:', dialogHandled);
const allButtons = document.querySelectorAll('button');
console.log('页面中所有按钮:');
allButtons.forEach((btn, index) => {
const text = btn.textContent.trim();
const classes = btn.className;
if (text.includes('提交') || text.includes('Submit') || classes.includes('submit') ||
text.includes('确认') || text.includes('确定')) {
console.log(` ${index}: "${text}" - 类名: ${classes}`);
}
});
const dialogs = document.querySelectorAll('[class*="dialog"], [role="dialog"], .modal, [class*="modal"]');
console.log('页面中的弹窗元素:', dialogs.length);
dialogs.forEach((dialog, index) => {
if (dialog.offsetParent !== null) {
console.log(` 弹窗 ${index}: 可见 - ${dialog.className}`);
console.log(` 内容: ${dialog.textContent.substring(0, 100)}...`);
}
});
return { submitBtn, footerBtn, dialogHandled };
};
window.testItestQuestions = function() {
console.log('=== 测试itest题型结构 ===');
const itestSections = document.querySelectorAll('.itest-section');
console.log('找到itest sections:', itestSections.length);
itestSections.forEach((section, index) => {
const title = section.querySelector('.title');
const sectionType = section.getAttribute('sectiontype');
console.log(`Section ${index + 1}: ${title ? title.textContent : 'No title'}, Type: ${sectionType}`);
});
const radioInputs = document.querySelectorAll('.itest-danxuan input[type="radio"]');
console.log('找到单选题选项:', radioInputs.length);
const radioQuestions = new Set();
radioInputs.forEach(input => {
const qindex = input.getAttribute('qindex');
const qoo = input.getAttribute('qoo');
if (qindex) radioQuestions.add(qindex);
const label = input.closest('label');
if (label && parseInt(qindex) <= 5) {
console.log(`题目 ${qindex}: ${label.textContent.trim().substring(0, 50)}...`);
console.log(` qoo属性: ${qoo}`);
}
});
console.log('单选题题目数量:', radioQuestions.size);
const textInputs = document.querySelectorAll('.blankinput');
console.log('找到填空题:', textInputs.length);
const textQuestions = new Set();
textInputs.forEach((input, index) => {
const qindex = input.getAttribute('qindex');
if (qindex) textQuestions.add(qindex);
if (index < 5) {
console.log(`填空题 ${qindex}: width=${input.style.width}`);
}
});
console.log('填空题题目数量:', textQuestions.size);
const allQuestions = new Set([...radioQuestions, ...textQuestions]);
console.log('总题目数量:', allQuestions.size);
return {
itestSections,
radioInputs,
textInputs,
radioQuestions: radioQuestions.size,
textQuestions: textQuestions.size,
totalQuestions: allQuestions.size
};
};
window.testMultipleChoice = function() {
console.log('=== 测试多选题处理 ===');
const multipleChoiceContainers = document.querySelectorAll('.MultipleChoice--checkbox-item-34A_-');
console.log('找到普通U校园版多选题选项:', multipleChoiceContainers.length);
multipleChoiceContainers.forEach((container, index) => {
const checkbox = container.querySelector('input[type="checkbox"]');
const optLabel = container.querySelector('.MultipleChoice--checkbox-opt-2F4xY');
const htmlView = container.querySelector('.html-view');
console.log(`选项 ${index + 1}:`);
console.log(` 复选框:`, checkbox);
console.log(` 选项标签:`, optLabel ? optLabel.textContent.trim() : 'null');
console.log(` 内容:`, htmlView ? htmlView.textContent.trim().substring(0, 50) + '...' : 'null');
});
const allCheckboxes = document.querySelectorAll('input[type="checkbox"]');
console.log('页面中所有复选框:', allCheckboxes.length);
const testAnswers = [
['B', 'D'],
'B,D',
'BD',
{ answer: ['B', 'D'] }
];
console.log('=== 测试答案格式处理 ===');
testAnswers.forEach((answer, index) => {
let answerString = answer;
if (Array.isArray(answer)) {
answerString = answer.join(',');
} else if (typeof answer === 'object') {
answerString = JSON.stringify(answer);
}
console.log(`测试答案 ${index + 1}:`, answer, '-> 处理后:', answerString);
const letterMatches = answerString.match(/[A-Z]/gi);
console.log(` 提取的字母:`, letterMatches);
});
return { multipleChoiceContainers, allCheckboxes };
};
initRecordingFeatures();
setupSubmitConfirmHandler();
});
if (document.readyState === 'loading') {
} else {
setupMultiPageNavigationListener();
initRecordingFeatures();
setupSubmitConfirmHandler();
autoResumeIfNeeded();
}