对于 submission 界面可以查看未公布的答案
// ==UserScript==
// @name 一键查看MOOC答案
// @namespace http://tampermonkey.net/
// @version 1.0
// @description 对于已经提交的界面点击按钮跳转到答案
// @match https://mooc2.uestc.edu.cn/exam/*
// @match https://mooc2.uestc.edu.cn/api/*
// @grant none
// @license AGPL-3.0-or-later
// @author 最可爱的小夏同学
// ==/UserScript==
(function() {
'use strict';
const url = window.location.href;
const match = url.match(/exam\/(\d+)\/subjects#\/submission\/(\d+)/);
if (match) {
debugger;
const [_, examId, submissionId] = match;
// 创建按钮
const jumpButton = document.createElement('button');
jumpButton.textContent = '跳转到答案页面';
jumpButton.style.position = 'fixed';
jumpButton.style.top = '20px';
jumpButton.style.right = '20px';
jumpButton.style.zIndex = '1000';
// 添加点击事件
jumpButton.addEventListener('click', function() {
// 跳转到指定的URL
window.location.href = 'https://mooc2.uestc.edu.cn/api/exams/12177/submissions/'+ submissionId;
});
// 将按钮添加到页面中
document.body.appendChild(jumpButton);
}
const api_match = url.match(/exams\/(\d+)\/submissions\/(\d+)/);
if (api_match) {
// 使用fetch API获取数据
fetch(window.location.href)
.then(response => response.json()) // 将响应转换为JSON
.then(data => {
// 清除页面上的其他内容
document.body.innerHTML = '';
// 创建一个新的div元素来显示正确答案
var answersDiv = document.createElement('div');
answersDiv.style.padding = '20px';
// 遍历correct_answers数组,为每个答案创建一个段落<p>元素
data.correct_answers_data.correct_answers.forEach(function(answer) {
// 检查answer是否有content字段
if (answer.content) {
var p = document.createElement('p');
p.innerHTML = answer.content; // 设置段落内容为答案的content
answersDiv.appendChild(p); // 将段落添加到div中
} else if (answer.correct_answers && answer.correct_answers.length > 0) {
// 如果没有content字段,但存在嵌套的correct_answers
answer.correct_answers.forEach(function(nestedAnswer) {
if (nestedAnswer.content) {
var pNested = document.createElement('p');
pNested.innerHTML = nestedAnswer.content; // 设置段落内容为嵌套答案的content
answersDiv.appendChild(pNested); // 将段落添加到div中
}
});
}
});
// 将div添加到body中
document.body.appendChild(answersDiv);
})
.catch(error => {
console.error('Error fetching data:', error);
});
}
})();
如何使用?
- 首先安装油猴插件,请 Google
- 添加新脚本 → 复制进去 → Ctrl + S 保存
- 用 Chrome 浏览器打开成电 MOOC
- 进入任意一个已经提交过的 submission 界面 (不是做题界面,也不是未提交过的界面,而是已经做过的提交记录,这个脚本只能够把没有公布的答案显现出来)
- 此时右上角应该会出现一个按钮,点击跳转到答案界面按钮即可
没有识别到的话可能需要从 exam 重新进入