吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 8107|回复: 56
收起左侧

[其他原创] 第六届全国学生“学宪法 讲宪法”活动(宪法小卫士)答题脚本

   关闭 [复制链接]
南岸 发表于 2021-8-4 12:51

油猴脚本地址:https://greasyfork.org/zh-CN/scripts/430038

实现功能:自动收录练习答案,自动点击正确选项
注意:考试前请做一遍练习,防止答案出错或没有


// ==UserScript==
// home.php?mod=space&uid=170990         普法网(宪法小卫士)课后练习、考试自动答题
// home.php?mod=space&uid=467642    Ne-21
// home.php?mod=space&uid=1248337      1.2
// @description  第六届全国学生“学宪法 讲宪法”活动
// home.php?mod=space&uid=686208       Ne-21
// home.php?mod=space&uid=195849        https://static.qspfw.moe.gov.cn/xf2021/learn-practice.html*
// @match        https://static.qspfw.moe.gov.cn/xf2021/learn_exam.html*
// home.php?mod=space&uid=593100         https://blog.gocos.cn/wp-content/uploads/2021/07/2021-07-2782.ico
// home.php?mod=space&uid=67665      api.gocos.cn
// @run-at       document-end
// home.php?mod=space&uid=609072        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') {
        getExam();
        let t = setInterval( function() {
            doExam(t)
        },time);
    } else if (window.location.pathname == '/xf2021/learn-practice.html') {
        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<vars.length;i++) {
               var pair = vars[i].split("=");
               if(pair[0] == variable){return pair[1];}
       }
       return(false);
};

// 正则匹配
function getStr(str, start, end) {
    let res = str.match(new RegExp(`${start}(.*?)${end}`))
    return res ? res[1] : null
}

// 获取答案
function getAnswer(columnId) {
    var html = $("html").html(),
        taskId = getStr(html,'&taskId=','`,')

    $.ajax({
        url: _self.config.practice.host + _self.config.practice.practice + "?columnId="+ columnId + "&taskId=" + taskId,
        headers: _self.config.apiConfig.header,
        async: false,
        success: function (res) {
            const { data, status } = res;
            if (status === "0") {
                var question_data = res.data
                var questionBankList = data.questionBankList
                answer_list = questionBankList;
                upload(question_data)
            } else if (status === "1") {
                //无效的columnId(下个接口是chapterId)
                alert("请先学习当前模块");
                window.history.go(-1);
            } else if (status === "-2") {
                alert("请重新登陆");
            } else {

            }
        },
        error: function (err) {
        }
    });
}

// 答题操作
function doQuestion(t) {
    var cur_topic = $('#currentTopic').text(),
        tol_topic = $('#totalTopic').text(),
        answer = answer_list[cur_topic - 1].answer;
    $('#exam_answer > 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) {
        }
    });
}

免费评分

参与人数 10吾爱币 +16 热心值 +8 收起 理由
七日书 + 1 + 1 感谢感谢,太有用了
CiySu + 1 + 1 确实牛逼,满分!
cxywjhcnb + 1 + 1 好用!
jeong + 1 + 1 鼓励转贴优秀软件安全工具和文档!
52pengcheng + 1 我很赞同!
pannifeng + 1 + 1 谢谢@Thanks!
arvin1024 + 1 + 1 用心讨论,共获提升!
Qmx + 1 用心讨论,共获提升!
btzx + 1 + 1 我很赞同!
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

woshiwode 发表于 2022-9-23 14:22
又来第七届了,哈哈
 楼主| 南岸 发表于 2021-10-29 13:06
本帖最后由 南岸 于 2021-10-29 13:32 编辑
これは雲です 发表于 2021-10-28 20:29
大哥,您的服务器最大同接不行呀....
学校组织几个学生来用您的脚本答题,老是api无响应
求解决,感谢! ...

限制ip并发,您可以通过更换ip来解决
byh3025 发表于 2021-8-4 13:03
缘项 发表于 2021-8-4 13:15

支持原创作品,谢谢啦
风子是我 发表于 2021-8-4 13:53
可以批量自动登录么?
xk6999 发表于 2021-8-4 13:57
支持原创作品,谢谢啦
JWL213312 发表于 2021-8-4 14:20
支持原创作品,谢谢啦
yc0205 发表于 2021-8-4 14:21
有点像JS  是用JS编写的吗?
南归不NG 发表于 2021-8-4 14:30
yc0205 发表于 2021-8-4 14:21
有点像JS  是用JS编写的吗?

油猴脚本,js写的
 楼主| 南岸 发表于 2021-8-4 14:46
风子是我 发表于 2021-8-4 13:53
可以批量自动登录么?

自动登录要识别图片验证码,感觉自己用没必要
 楼主| 南岸 发表于 2021-8-4 14:47
yc0205 发表于 2021-8-4 14:21
有点像JS  是用JS编写的吗?

javascript
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-16 18:53

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表