// ==UserScript==
// @name Chaoxing AI Helper
// @namespace https://scriptcat.org/
// @version 1.0.0
// @description 学习通 AI 学习辅助工具
// @author ChatGPT
// @match https://study.chaoxing.com/*
// @match https://mooc1.chaoxing.com/*
// @grant GM_addStyle
// @noframes
// ==/UserScript==
(function () {
'use strict';
/************************************************
* 配置区域
************************************************/
const DEEPSEEK_API_KEY = "YOUR_DEEPSEEK_API_KEY";
const MODEL = "deepseek-chat";
/************************************************
* 样式
************************************************/
GM_addStyle(`
#ai-helper-panel{
position:fixed;
top:80px;
right:20px;
width:340px;
max-height:80vh;
overflow:auto;
background:#111827;
color:#fff;
z-index:999999;
border-radius:14px;
padding:16px;
box-shadow:0 0 20px rgba(0,0,0,.35);
font-size:14px;
font-family:Arial;
}
#ai-helper-panel h2{
margin:0 0 12px 0;
font-size:18px;
}
.ai-question{
padding:12px;
margin-bottom:12px;
background:rgba(255,255,255,.05);
border-radius:10px;
}
.ai-title{
font-weight:bold;
margin-bottom:8px;
}
.ai-answer{
color:#34d399;
margin-top:8px;
line-height:1.5;
white-space:pre-wrap;
}
.ai-progress{
margin-top:12px;
color:#93c5fd;
font-size:13px;
}
.ai-btn{
margin-top:10px;
background:#2563eb;
border:none;
color:white;
padding:6px 12px;
border-radius:6px;
cursor:pointer;
}
.ai-btn:hover{
opacity:.9;
}
`);
/************************************************
* 创建悬浮窗
************************************************/
const panel = document.createElement('div');
panel.id = 'ai-helper-panel';
panel.innerHTML = `
AI 学习助手
等待扫描题目...
`;
document.body.appendChild(panel);
const contentEl = document.getElementById('ai-content');
const progressEl = document.getElementById('ai-progress');
/************************************************
* 解析题目
************************************************/
function parseQuestions() {
const questionNodes = document.querySelectorAll('.TiMu');
const results = [];
questionNodes.forEach((node, index) => {
const title =
node.querySelector('.Zy_TItle')?.innerText?.trim() || '';
const options = [];
node.querySelectorAll('li').forEach(li => {
const txt = li.innerText.trim();
if (txt) {
options.push(txt);
}
});
results.push({
index: index + 1,
title,
options,
node
});
});
return results;
}
/************************************************
* DeepSeek API
************************************************/
async function askAI(question) {
const prompt = `
你是一个学习助手。
请分析下面题目并给出推荐答案。
返回格式:
推荐答案:XXX
解析:XXX
题目:
${question.title}
选项:
${question.options.join('\n')}
`;
const response = await fetch(
'https://api.deepseek.com/chat/completions',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${DEEPSEEK_API_KEY}`
},
body: JSON.stringify({
model: MODEL,
messages: [
{
role: 'user',
content: prompt
}
],
temperature: 0.2
})
}
);
const data = await response.json();
return data?.choices?.[0]?.message?.content || 'AI 无返回结果';
}
/************************************************
* 自动高亮选项(不提交)
************************************************/
function highlightAnswer(question, aiText) {
const match = aiText.match(/推荐答案[::]\s*([A-D]+)/i);
if (!match) return;
const answer = match[1].toUpperCase();
const letters = answer.split('');
const options = question.node.querySelectorAll('li');
letters.forEach(letter => {
const index = letter.charCodeAt(0) - 65;
if (options[index]) {
options[index].style.border =
'2px solid #22c55e';
options[index].style.background =
'rgba(34,197,94,.15)';
}
});
}
/************************************************
* 主流程
************************************************/
async function start() {
const questions = parseQuestions();
if (!questions.length) {
contentEl.innerHTML = '未检测到题目';
return;
}
contentEl.innerHTML = '';
for (let i = 0; i < questions.length; i++) {
const q = questions[i];
progressEl.innerText =
`进度:${i + 1} / ${questions.length}`;
const div = document.createElement('div');
div.className = 'ai-question';
div.innerHTML = `
第 ${q.index} 题
${q.title}
AI 分析中...
`;
contentEl.appendChild(div);
try {
const result = await askAI(q);
div.querySelector('.ai-answer').innerText =
result;
highlightAnswer(q, result);
} catch (err) {
console.error(err);
div.querySelector('.ai-answer').innerText =
'AI 调用失败';
}
await sleep(1500);
}
progressEl.innerText = '全部题目分析完成';
}
/************************************************
* 延迟函数
************************************************/
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
/************************************************
* 页面加载后启动
************************************************/
window.addEventListener('load', () => {
setTimeout(() => {
start();
}, 4000);
});
})();