// ==UserScript== // @name 普法网(宪法小卫士)课后练习、考试自动答题 // @namespace Ne-21 // @version 1.3.8 // @description 全国学生“学宪法 讲宪法”活动自动答题脚本,因缺少测试账号无法保证每年都能用,欢迎大家提供测试账号以支持此脚本长期可用,测试账号登录信息请发送至我们的邮箱nawlgzs@gmail.com // @author Ne-21 // @match *://static.qspfw.moe.gov.cn/* // @icon https://blog.gocos.cn/wp-content/uploads/2021/07/2021-07-2782.ico // @connect cx.gocos.cn // @run-at document-end // @grant unsafeWindow // @license MIT // @require https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js // @require https://cdn.staticfile.org/limonte-sweetalert2/11.0.1/sweetalert2.all.min.js // ==/UserScript== var _self = unsafeWindow, $ = _self.jQuery || top.jQuery, Swal = Swal || window.Swal, columnId = getQueryVariable("columnId"), answer_list = [], exam_list = [], time = 5e3, // 答题间隔时间,最好为5秒 num = {"A": 1,"B": 2, "C": 3, "D": 4}; (function() { if (window.location.pathname.indexOf('learn_exam.html') != -1) { Swal.fire('宪法小助手提示','点击确定开始考试','info').then(()=>{ Swal.fire({ position: 'top-end', title: '脚本将在5秒后开始自动作答!', showConfirmButton: false, timer: 4000 }) getExam(); let t = setInterval( function() { doExam(t) },time); }) } else if (window.location.pathname.indexOf('learn-practice.html') != -1) { Swal.fire('宪法小助手提示','点击确定开始练习,脚本会自动收录本练习题目数据','info').then(()=>{ getAnswer(columnId); let t = setInterval( function() { doQuestion(t) },time); }) } else if (window.location.pathname.indexOf('learn_practice_list.html') != -1) { Swal.fire('宪法小助手提示','使用说明:
1.做综合评价之前请先把练习做完以收集题目数据。
2.脚本运行故障如综合测评无操作等,请使用Edge浏览器+ScriptCat。
3.问题联系邮箱nawlgzs@gmail.com') } else if (window.location.pathname.indexOf('evaluation.html') != -1) { Swal.fire({ html:`
开发及服务器维护不易,请作者喝一杯奶茶吧~

` }) } })(); // 解析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(){Swal.fire('宪法小助手提示','答题完成','info')},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=" + _self.config.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){ $('#ne21ans')[0] ? $('#ne21ans').html('

正在搜索答案~

') : $('#exam_question').append('

正在搜索答案~

') var cur_topic = $('#currentTopic').text(), tol_topic = $('#totalTopic').text(), questionInfo = exam_list[cur_topic - 1]; $.ajax({ url: 'https://cx.gocos.cn/xf-api/v1/cx?v=3', type: 'POST', data: {'data':encodeURIComponent(JSON.stringify({ '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 var answerText = data[0].answerText $('#ne21ans').html('

参考答案:'+ answerText + '

') $('#exam_answer > div:nth-child(' + num[answer] + ')').click(); } else { var msg = res.msg; Swal.fire('宪法小助手提示',msg,'info') } }, error: function (err) { } }); if (cur_topic == tol_topic) { // 清除Interval的定时器 clearInterval(t); setTimeout(function(){Swal.fire('宪法小助手提示','答题完成,请自己点击交卷!','info')},time / 2); } else{ setTimeout(function(){$('#next_question').click()},time / 2); }; } function upload(question_data) { $.ajax({ url: 'https://cx.gocos.cn/xf-api/v1/upload', type: 'POST', data: {'data':encodeURIComponent(JSON.stringify(question_data))}, async: true, success: function (res) { Swal.fire({ position: 'top-end', title: '本章节测验题目数据已收集完毕!请等待脚本自动答题。', showConfirmButton: false, timer: 1500 }) }, error: function (err) { Swal.fire({ position: 'top-end', title: '发生未知错误,请联系作者!', showConfirmButton: false, timer: 1500 }) } }); }