// ==UserScript==
// @name 超星学习通+ChatGPT自动答题脚本(支持考试和作业,支持新版学习通)
// @namespace http://tampermonkey.net/
// @license MIT
// @version 0.1
// @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";
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;
}
`);
const myWindow = document.createElement("div");
myWindow.id = "my-window";
myWindow.innerHTML = `
`;
const floatingButton = document.createElement("div");
floatingButton.id = "floating-button";
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";
}
const hideBtn = document.getElementById("hide-btn");
hideBtn.addEventListener("click", hideWindow);
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(/window\.UEDITOR_CONFIG\.initialFrameWidth.*保存/g, "").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);
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)
});
var json = await response.json();
var msg = json.msg;
pElement.textContent = "可用的token余额:" + msg
});
})();