// ==UserScript== // @name 普法网(宪法小卫士)课后练习、考试自动答题 // @namespace Ne-21 // @version 1.3 // @description 第六届全国学生“学宪法 讲宪法”活动 // @author Ne-21 // @match *://static.qspfw.moe.gov.cn/xf2021/learn-practice.html* // @match *://static.qspfw.moe.gov.cn/xf2021/learn_exam.html* // @icon https://blog.gocos.cn/wp-content/uploads/2021/07/2021-07-2782.ico // @connect api.gocos.cn // @run-at document-end // @grant unsafeWindow // @license MIT // @require http://libs.baidu.com/jquery/2.0.0/jquery.min.js // ==/UserScript== var _self = unsafeWindow, $ = _self.jQuery || top.jQuery, columnId = getQueryVariable("columnId"), answer_list = [], exam_list = [], time = 3000, // 答题间隔时间,最好为3000mss num = {"A": 1,"B": 2, "C": 3, "D": 4}; (function() { if (window.location.pathname == '/xf2021/learn_exam.html') { alert('点击确定开始考试(使用方法视频请关注‘烟雨天青色’公众号回复‘普法网视频’)') getExam(); let t = setInterval( function() { doExam(t) },time); } else if (window.location.pathname == '/xf2021/learn-practice.html') { alert('点击确定开始练习(使用方法视频请关注‘烟雨天青色’公众号回复‘普法网视频’)') getAnswer(columnId); let t = setInterval( function() { doQuestion(t) },time); } })(); // 解析url参数 function getQueryVariable(variable) { var query = window.location.search.substring(1); var vars = query.split("&"); for (var i=0;i div:nth-child(' + num[answer] + ')').click(); if (cur_topic == tol_topic) { // 清除Interval的定时器 clearInterval(t); setTimeout(function(){alert('答题完成')},time / 2) } else{ setTimeout(function(){$('#next_question').click()},time / 2); }; } // 获取考试题目 function getExam(){ var html = $("html").html(), taskId = getStr(html,'taskId=','`,'); $.ajax({ url: _self.config.wexam.host + _self.config.wexam.getPaper + "?taskId=" + taskId, headers: _self.config.apiConfig.header, async: false, success: function (res) { const { data, status, message } = res; if (status === "0") { var question_data = res.data; var paper = question_data.paper; var paperInfo = paper.paperInfo; exam_list = paperInfo; } else { alert('获取考试题目失败!') } }, error: function (err) { } }); } // 考试答题操作 function doExam(t){ var cur_topic = $('#currentTopic').text(), tol_topic = $('#totalTopic').text(), questionInfo = exam_list[cur_topic - 1]; $.ajax({ url: 'https://api.gocos.cn/index.php/cxapi/xf/getAnswer?v=2', type: 'POST', data: { 'question': questionInfo.content, 'answerops':questionInfo.answerOptions, 'topicId': questionInfo.id }, async: false, success: function (res) { if (res.code == 1) { var data = res.data; var answer = data[0].answer $('#exam_answer > div:nth-child(' + num[answer] + ')').click(); } else { var msg = res.msg; alert(msg) } }, error: function (err) { } }); if (cur_topic == tol_topic) { // 清除Interval的定时器 clearInterval(t); setTimeout(function(){alert('答题完成')},time / 2); } else{ setTimeout(function(){$('#next_question').click()},time / 2); }; } function upload(question_data) { $.ajax({ url: 'https://api.gocos.cn/index.php/cxapi/xf/upload', type: 'POST', data: {'data': question_data}, async: true, success: function (res) { }, error: function (err) { } }); }