Greasy Fork is available in English.

QingJiaoHelper

青骄第二课堂小助手: 长期更新 | 2022 知识竞赛 | 跳过视频 | 自动完成所有课程 | 每日领取学分 | 课程自动填充答案

< Feedback on QingJiaoHelper

Review: Good - script works

§
Posted: 06. 12. 2023
Edited: 06. 12. 2023

不能自动答题,这是什么问题?

WindLeaf233Author
§
Posted: 06. 12. 2023

看报错应该是你没登录账号,或者是token失效了。的确有确实登上了账号但报错未登录的情况,试试重新登录账号然后再答题。

§
Posted: 06. 12. 2023

账号是登录的

§
Posted: 14. 12. 2023

async function requestAPI(api, params, data) {
const method = api.method;
const origin = "https://www.2-class.com";
let url = `${origin}/api${api.api}`;

// Replace URL placeholders with actual values
for (const key in params) {
url = url.replaceAll("${" + key + "}", params[key]);
}

// Retrieve browser cookies
const cookies = document.cookie;

if (method === "GET") {
return await axios({
method: "GET",
url,
withCredentials: true, // Include cookies in the request
headers: {
Cookie: cookies, // Pass the cookies in the headers
},
}).then((response) => {
const rdata = response.data;
console.debug(`[${method}] ${url}`, data, rdata);

if (rdata.success === false || rdata.data === null) {
const errorMessage = rdata.errorMsg;
const errorCode = rdata.errorCode;
console.error(`API 返回错误 [${errorCode}]:${errorMessage},请刷新页面重试!`);
return null;
} else {
return rdata;
}
}).catch((reason) => {
showMessage(`请求 API 失败(${reason.code}):${reason.message}\n请将控制台中的具体报错提交!`, "red");
console.error(`请求失败(${reason.status}/${reason.code})→${reason.message}→`, reason.toJSON(), reason.response, reason.stack);
});
} else {
return await axios({
method: "POST",
url,
withCredentials: true, // Include cookies in the request
headers: {
"Content-Type": "application/json;charset=UTF-8",
Cookie: cookies, // Pass the cookies in the headers
},
data,
}).then((response) => {
const rdata = response.data;
console.debug(`[${method}] ${url}`, data, rdata);

if (rdata.success === false || rdata.data === null) {
const errorMessage = rdata.errorMsg;
const errorCode = rdata.errorCode;
console.error(`API 返回错误 [${errorCode}]:${errorMessage},请刷新页面重试!`);
return null;
} else {
return rdata;
}
});
}
}把60行的函数改成这个,这脚本默认请求不带cookie

Post reply

Sign in to post a reply.