// ==UserScript== // @name 超星学习通+ChatGPT自动答题脚本(支持考试和作业,支持新版学习通) // @namespace http://tampermonkey.net/ // @version 0.2 // @license MIT // @description 超星学习通+ChatGPT自动答题脚本(支持考试和作业,支持新版学习通)。直接获取到答案,可以复制答案到剪切板。 // @author Cwyu // @supportURL 1441577495@qq.com // @contributionURL https://afdian.net/a/cwyuu // @match *://mooc1.chaoxing.com/exam-ans/mooc2/exam/preview?* // @match *://mooc1.chaoxing.com/mooc2/work/dowork?* // @icon https://www.google.com/s2/favicons?sz=64&domain=chaoxing.com // @grant GM_addStyle // @grant GM_setValue // @grant GM_getValue // @downloadURL none // ==/UserScript== (function () { "use strict"; // 添加CSS样式 GM_addStyle(` #my-window { position: fixed; top: 10px; left: 10px; width: 491px; height: 308px; background-color: rgba(173, 255, 47, 0.7); border: 1px solid #000; border-radius: 5px; z-index: 9999; overflow: hidden; } #my-window .header { background-color: #000; color: #fff; padding: 5px; font-size: 16px; font-weight: bold; border-radius: 5px 5px 0 0; cursor: move; } #my-window .resizer { position: absolute; bottom: 0; right: 0; width: 20px; height: 20px; background-color: #000; cursor: se-resize; border-radius: 0 0 5px 0; z-index: 1; } #hide-btn { float: right; } #floating-button { position: fixed; top: 20px; left: -45px; width: 50px; height: 50px; background-color: #333; color: #fff; border-radius: 50%; text-align: center; line-height: 50px; cursor: pointer; transition: all 0.3s ease; z-index: 9999; } #floating-button:hover { left: 0; } #floating-button:active { top: 30px; } .buttons { position: absolute; bottom: 10px; left: 10px; display: flex; justify-content: flex-end; } .buttons button { display: block; margin-bottom: 5px; margin-right: 5px; } .buttons input { display: block; margin-bottom: 5px; margin-right: 5px; } .buttons p { display: block; margin-bottom: 5px; margin-right: 5px; } .editing { color: red!important; } `); // 创建窗口元素 const myWindow = document.createElement("div"); myWindow.id = "my-window"; myWindow.innerHTML = `
窗口标题
题目
答案

`; // 创建悬浮球元素 const floatingButton = document.createElement("div"); floatingButton.id = "floating-button"; // 获取页面body元素 const body = document.getElementsByTagName("body")[0]; // 添加窗口和悬浮球到页面 body.appendChild(myWindow); body.appendChild(floatingButton); // 隐藏窗口函数 function hideWindow() { myWindow.style.display = "none"; floatingButton.style.display = "block"; } // 显示窗口函数 function showWindow() { myWindow.style.display = "block"; floatingButton.style.display = "none"; } // 绑定隐藏窗口按钮的click事件 const hideBtn = document.getElementById("hide-btn"); hideBtn.addEventListener("click", hideWindow); // 绑定悬浮球的click事件 floatingButton.addEventListener("click", showWindow); // 初始化隐藏悬浮球 floatingButton.style.display = "none"; // 获取头部元素 const header = myWindow.querySelector('.header'); // 获取调整大小元素 const resizer = myWindow.querySelector('.resizer'); // 处理调整大小事件 resizer.addEventListener('mousedown', function (e) { e.preventDefault(); const { left, top, width, height } = myWindow.getBoundingClientRect(); const startX = e.clientX; const startY = e.clientY; function onMouseMove(e) { const newWidth = Math.max(200, width + (e.clientX - startX)); const newHeight = Math.max(100, height + (e.clientY - startY)); myWindow.style.width = newWidth + 'px'; myWindow.style.height = newHeight + 'px'; } function onMouseUp() { window.removeEventListener('mousemove', onMouseMove); window.removeEventListener('mouseup', onMouseUp); } window.addEventListener('mousemove', onMouseMove); window.addEventListener('mouseup', onMouseUp); }); // 处理移动事件 let isDragging = false; let mouseX = 0; let mouseY = 0; header.addEventListener('mousedown', function (e) { e.preventDefault(); isDragging = true; mouseX = e.clientX; mouseY = e.clientY; }); document.addEventListener('mousemove', function (e) { if (isDragging) { const deltaX = e.clientX - mouseX; const deltaY = e.clientY - mouseY; const newLeft = myWindow.offsetLeft + deltaX; const newTop = myWindow.offsetTop + deltaY; myWindow.style.left = newLeft + 'px'; myWindow.style.top = newTop + 'px'; mouseX = e.clientX; mouseY = e.clientY; } }); document.addEventListener('mouseup', function (e) { isDragging = false; }); const answerCol = document.querySelector('.row .col:nth-child(5)'); let timu; if (document.title == "作业作答") { const divs = document.querySelectorAll('.padBom50.questionLi:not(script)'); const texts = []; divs.forEach(div => { const text = div.textContent.trim().replace(/\s+/g, ' '); texts.push(text); }); timu = texts.map((text) => text.replace(/var\s+wordNum\s*=.*$/gm, "").trim() ); } if (document.title == "整卷预览") { const elements = document.querySelectorAll('div.questionLi:not(script)'); const texts = []; for (let i = 0; i < elements.length; i++) { const element = elements[i]; const text = element.textContent.trim().replace(/\s+/g, ' '); texts.push(text); } timu = texts.map((text) => text.replace(/window\.UEDITOR_CONFIG\.initialFrameWidth.*保存/g, "").trim() ); } console.log(timu); let currentIndex = 0; const col1 = document.querySelector('.row .col:nth-child(2)'); function showText(index) { col1.textContent = timu[index]; } function showNext() { if (currentIndex < timu.length - 1) { currentIndex++; showText(currentIndex); answerCol.textContent = ""; } } function showPrev() { if (currentIndex > 0) { currentIndex--; showText(currentIndex); answerCol.textContent = ""; } } // 绑定按钮点击事件 document.getElementById('prev-btn').addEventListener('click', showPrev); document.getElementById('next-btn').addEventListener('click', showNext); // 显示第一个文本 showText(currentIndex); const refreshBtn = document.getElementById("refresh-btn"); refreshBtn.addEventListener("click", async function () { // 获取输入框元素 var inputElement = document.querySelector('input[name="key"]'); answerCol.textContent = "请等待......"; const data = { "cardNum": inputElement.value, "question": timu[currentIndex] }; const response = await fetch('https://service-75fbid0g-1316165338.gz.apigw.tencentcs.com/release/update', { method: 'POST', headers: { 'Content-Type': 'application/json', 'charset': 'utf-8' }, body: JSON.stringify(data) }); const json = await response.json(); if (json.data == null) { const content = json.msg; answerCol.textContent = content; } else { const content = json.data.answer; answerCol.textContent = content; } }); const copyBtn = document.querySelector('#copy-btn'); copyBtn.addEventListener('click', function () { const answerText = answerCol.textContent; navigator.clipboard.writeText(answerText) .then(() => { console.log('Text copied to clipboard'); }) .catch(err => { console.error('Could not copy text: ', err); }); }); // 获取输入框元素 var inputElement = document.querySelector('input[name="key"]'); // 获取存储的数据 var storedValue = GM_getValue('key'); // 如果存储的数据存在,则将其设置为输入框的值 if (storedValue) { inputElement.value = storedValue; } // 获取按钮元素 var buttonElement = document.querySelector('#save-btn'); // 获取

元素 var pElement = document.getElementById('card_status'); // 当按钮被点击时执行的函数 buttonElement.addEventListener('click', async function () { // 获取输入框的值 var inputValue = inputElement.value; // 存储数据 GM_setValue('key', inputValue); // 发送POST请求 var data = { "cardNum": inputValue }; var response = await fetch('https://service-75fbid0g-1316165338.gz.apigw.tencentcs.com/release/getcard', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }); // 从响应中获取msg字段的值 var json = await response.json(); var msg = json.msg; pElement.textContent = "可用的token余额:" + msg }); // 获取题目元素 const questionElement = document.querySelector("#question"); // 添加双击事件监听器 questionElement.addEventListener("dblclick", function (event) { // 阻止默认行为 event.preventDefault(); // 创建可编辑的 div 元素 const editableDiv = document.createElement("div"); editableDiv.setAttribute("contenteditable", true); editableDiv.textContent = questionElement.textContent; // 用可编辑的 div 元素替换题目元素 questionElement.replaceWith(editableDiv); // 让可编辑的 div 元素获取焦点 editableDiv.focus(); // 给题目元素添加样式类,改变元素文本颜色 editableDiv.classList.add("editing"); // 添加失去焦点事件监听器,保存编辑内容并恢复题目元素 editableDiv.addEventListener("blur", function () { // 保存编辑后的文本内容到 timu 数组 timu[currentIndex] = editableDiv.textContent; // 用编辑后的内容替换可编辑的 div 元素 questionElement.textContent = editableDiv.textContent; editableDiv.replaceWith(questionElement); // 移除题目元素样式类,恢复元素文本颜色 editableDiv.classList.remove("editing"); }); }); })();