源码安装
max / 中国大学慕课mooc答题/自动播放脚本(domooc)

// ==UserScript==
// @name         中国大学慕课mooc答题/自动播放脚本(domooc)
// @namespace    www.zkq8.com
// @version      1.7
// @description  自动完成你的mooc考试测验客观题,开启刷课后自动看视频、看课件、自动讨论。使用过程中会上传您的mooc账户信息(包括昵称、ID、邮箱等)以识别用户。觉得好用请点击捐赠作者按钮捐赠我。
// @match        *://*.icourse163.org/*
// @run-at       document-end
// @connect      huan.fm210.cn
// @grant        none
// @require      https://lib.baomitu.com/jquery/3.6.0/jquery.min.js
// @antifeature  ads
// @antifeature  membership
// @license MIT
// ==/UserScript==
 
var conf = {
	title: "MOOC助手",
	time: 100, //平均时间
	learn: 1, //自动答题
	auto: 1, //自动提交
	random: 0, //无匹配答案随机选择
};
//cdn库  https://www.bootcdn.cn/layui/
$('head').append('<link href="https://lib.baomitu.com/layui/2.6.8/css/layui.css" rel="stylesheet" type="text/css" />');
$.getScript("https://lib.baomitu.com/layui/2.6.8/layui.js", function(data, status, jqxhr) {
    layui.use('element', function(){
  var element = layui.element;
});
    	layer.closeAll();
	init();
	window.onhashchange = function() {
		layer.closeAll();
		init();
	};
});
 
function answer1() {
	// CAT_click(document.querySelector(".j-submitBtn"));
	if (conf.num >= conf.inx) {
		var item = $(".u-questionItem").eq(conf.inx - 1);
		var tm = cl_text(item.find(".j-title").find(".f-richEditorText").html());
		tm = cl_text(tm);
		// layer.msg(tm);
		var tminx = item.find(".position").text();
		var tmtype = item.find(".qaCate>span").text();
		conf.pd = 0;
 
		var da = answer_p(tm, item);
        var el="";
		if (da != null) {
 
			if (conf.pd == 0) {
				conf.bad = conf.bad + 1;
				el = $('<tr class="layui-bg-red"><td>' + tminx + '</td><td>' + tm + '</td><td>' + da +
				'</td></tr>');
				$("#content>table>tbody").append(el);
			} else {
				el = $('<tr><td>' + tminx + '</td><td>' + tm + '</td><td>' + da + '</td></tr>');
				$("#content>table>tbody").append(el);
			}
 
		} else {
			conf.bad = conf.bad + 1;
			el = $('<tr class="layui-bg-red"><td>' + tminx + '</td><td>' + tm + '</td><td>暂无答案</td></tr>');
			$("#content>table>tbody").append(el);
		}
		document.querySelector("#msg > blockquote").innerHTML = '共获取<span class="layui-bg-blue">&nbsp;' + conf.num +
			'&nbsp;<\/span>道题目,正在完成第<span class="layui-bg-blue">&nbsp;' + conf.inx + '&nbsp;<\/span>道题目';
	} else {
		clearInterval(conf.f);
		document.querySelector("#msg > blockquote").innerHTML = '共获取<span class="layui-bg-blue">&nbsp;' + conf.num +
			'&nbsp;<\/span>道题目,共<span class="layui-bg-red">&nbsp;' + conf.bad + '&nbsp;<\/span>待完成。';
 
	}
	conf.inx = conf.inx + 1;
	if (conf.num < conf.inx) {
		clearInterval(conf.f);
		document.querySelector("#msg > blockquote").innerHTML = '共获取<span class="layui-bg-blue">&nbsp;' + conf.num +
			'&nbsp;<\/span>道题目,共<span class="layui-bg-red">&nbsp;' + conf.bad + '&nbsp;<\/span>待完成。';
 
	}
}
 
function answer_p(tm, item) {
    var da="";
	tm = tm.replace(/&amp;/g, "").replace(/http.*\/(.+)\./g,"$1").replace(/[^\u4e00-\u9fa5^\w]/g, "");
	for (var i = 0; i < conf.paperdata.length; i++) {
        var ytm=conf.paperdata[i]['tm'].replace(/http.*\/(.+)\./g,"$1").replace(/[^\u4e00-\u9fa5^\w]/g, "");
		if (tm == ytm) {
			var type = $.trim(item.find(".qaCate>span").text()); //题目类型
			switch (conf.paperdata[i]['status']) {
				case -1:
					da = null;
					break;
				case 1:
					da = conf.paperdata[i]['das'];
					if (type == "判断") {
						var tstr = ["正确", "对", "√", "true"];
						conf.pd = conf.pd + 1;
						if (tstr.indexOf(da[0]) > -1) {
							item.find(".choices>li").find(".u-icon-correct").parent().parent().css("border",
								"1px solid red");
						} else {
							item.find(".choices>li").find(".u-icon-wrong").parent().parent().css("border",
								"1px solid red");
						}
 
					} else {
 
						for (var j = 0; j < item.find(".choices>li").length; j++) {
							var xxtemp = cl_text(item.find(".choices>li").eq(j).find(".f-richEditorText").html());
							xxtemp = xxtemp.replace(/&amp;/g, "").replace(/http.*\/(.+)\./g,"$1").replace(/[^\u4e00-\u9fa5^\w]/g, "");
							for (var z = 0; z < da.length; z++) {
								if (xxtemp == da[z].replace(/http.*\/(.+)\./g,"$1").replace(/[^\u4e00-\u9fa5^\w]/g, "")) {
									item.find(".choices>li").eq(j).css("border", "1px solid red");
								}
							}
 
							conf.pd = conf.pd + 1;
						}
					}
 
 
 
 
					break;
				case 2:
					conf.pd = conf.pd + 1;
					da = conf.paperdata[i]['da'];
					if (type == "填空") {
 
						var el = $('<div><h3>答案:<span style="color:green">' + da + '</span></h3><div>');
 
						item.find(".j-title").find(".f-richEditorText").append(el);
					}
					break;
			}
 
			return da;
		}
	}
	return null;
}
function get_url_p(name)
{
       var query = window.location.search.substring(1);
       var vars = query.split("&");
       for (var i=0;i<vars.length;i++) {
               var pair = vars[i].split("=");
               if(pair[0] == name){return pair[1];}
       }
       return(false);
}
function get_answers(aid) {
	var code = 0;
	var da = "";
    var courseid= window.location.href.split("?")[0].split("-")[1];
    var tid=get_url_p("tid");
	$.ajax({
		url: "https://huan.fm210.cn/mooc/index",
		data: {
			"id": aid,
            "courseid":courseid,
            "tid":tid
		},
		dataType: "json",
		async: false,
		type: "get",
		success: function(data) {
			code = data.code;
			if (data.code == 1) {
				da = data.data
			} else {
				layer.msg(data.msg);
			}
		}
 
	})
	if (code == 1) {
 
		return da;
	} else {
		return null;
	}
 
}
 
function cl_text(text) {
	text = text.replace(/<(?!\/?img.+?>)[^<>]*>/g, "");
	text = text.replace(/(<img(?=\s).*?)\s+style=".*?"(.*?\/?>)/g, "$1$2");
	text = text.replace(/http:\/\//g, "https:\/\/");
	text = text.replace(/&#[^;]{2,};/g, "");
	text = text.replace(/\t/g, "");
	text = text.replace(/\n/g, "");
	text = text.replace(/\r/g, "");
	text = text.replace(/&.*?;/g, "");
	return $.trim(text);
 
}
 
function init() {
	var url = location.pathname;
	var urls = window.location.href.split("#")[1].split("?")[0];
 
	// var name = document.querySelector("#courseLearn-inner-box > div > div.u-learn-moduletitle.f-cb > h2");
	layer.closeAll();
	switch (urls) {
		case "/home/course":
			//个人课程主页
			break;
		case "/learn/announce":
			//学习页面
			break;
		case "/learn/testlist":
			//作业页面
			var ids = $("a[id^='auto-id']").id;
			// alert(ids);
			// console.log(ids);
			break;
		case "/learn/examlist":
			//考试页面
			break;
		case "/learn/examObject":
			show();
			conf.id = window.location.href.split("#")[1].split("&id=")[1];
 
			break;
		case "/learn/quiz":
			show();
			conf.id = window.location.href.split("#")[1].split("?id=")[1];
			break;
		case "/learn/hw": //主观题
			layer.msg("别看了不支持这玩意", {
				icon: 5
			});
			break;
 
		default:
		    console.log(123);
 
	};
 
}
 
function show() {
	layer.closeAll();
	layer.open({
		type: 1,
		area: ['500px', '300px'],
		offset: 'rb',
		id: 'msgt',
		closeBtn: 0,
		title: conf.title,
		shade: 0,
		maxmin: true,
		anim: 2,
		content: '<div id="msg" ><blockquote class="layui-elem-quote layui-quote-nm"><button type="button"  class="layui-btn layui-btn-normal start">点我获取题库-请确保在试卷页面点击<button></blockquote>'+
        '<div class="layui-collapse"><div class="layui-colla-item"><h2 class="layui-colla-title">公告</h2><div class="layui-colla-content layui-show"><div>扫描二维码下载APP搜题,题库更全哦~<img src="https://www.chitus.com/ewm/create?config=%7B%22content%22%3A%22https%3A%2F%2Fwww.fenbi.com%2Fdepot%2Ffenbi-search-question%2Findex.html%3Fapp%3Dsouti%26signVendor%3D8DFD180AC8706F9A519739C0F9F42CA6%22%7D" width="100px" /><br>&nbsp;&nbsp;反馈/建议+群:<a href="https://qm.qq.com/cgi-bin/qm/qr?k=kYJMBiYDBazG97Z_L3Nq9ppEexQtXh00&jump_from=webapi=">740894629</a></div></div></div>'
        +'<div id="content"><ul></ul>		<table class="layui-table"> <colgroup> <col width="50"> <col> <col> </colgroup> <thead> <tr> <th>序号</th> <th>题目</th> <th>答案</th> </tr> </thead> <tbody>  </tbody> </table></div></div></div>'
	});
	$(".start").click(function() {
		start();
	})
}
 
function start() {
	conf.num = $(".u-questionItem").length;
	if (conf.num=="") {
		layer.msg("没题目是怎么回事呢,页面对了吗", {
			icon: 5
		});
		return 0;
	}
	conf.inx = 1;
	conf.bad = 0;
	conf.paperdata = get_answers(conf.id);
	conf.f = setInterval(answer1, conf.time);
 
}