易班考试

理论上所有选择题考试都可以用,需要加QQ获取token,但是只是为了防止滥用,不会收费,也不会发广告,请看下方的详细说明。

Verze ze dne 12. 08. 2023. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         易班考试
// @namespace    http://tampermonkey.net/
// @license Common
// @version      1.1.9
// @description  理论上所有选择题考试都可以用,需要加QQ获取token,但是只是为了防止滥用,不会收费,也不会发广告,请看下方的详细说明。
// @author       木木
// @match        https://exam.yooc.me/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=yooc.me
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function () {
    'use strict';

    function my_replace(text) {
        text = text.replace(new RegExp(/( |	|[\r\n])|\s+|\s+$/g), "");
        return text;
    }

    const localStorage = window.localStorage;

    function set_value(key, value) {
        localStorage.setItem(key, value);
    }

    function get_value(key) {
        return localStorage.getItem(key);
    }

    let token = get_value("token");
    localStorage.clear();
    if (token !== undefined) set_value("token", token); else get_token();

    function get_token() {
        let t = prompt("请输入token(加2995653687发token五个字母获取)", token === undefined ? '' : token);
        if (t.length !== 16) {
            alert("长度不对");
            get_token();
        } else {
            token = t;
            set_value("token", token);
        }
    }


    // let local_str = get_value("tk");
    // if (typeof (local_str) !== "undefined") {
    //         tk = JSON.parse(local_str);
    //     } else {
    //         tk = JSON.parse("{}");
    //     }
    let tk;
    let id;
    // let examuser_id;
    let hook_fetch = window.fetch;
    window.fetch = async function (...args) {
        if (args[0].indexOf("paper") !== -1) {
            id = args[0].slice(args[0].indexOf("yibanId=") + 8)
            // examuser_id = args[0].slice(args[0].indexOf("examuserId=") + 11, args[0].indexOf("&"));
            return await hook_fetch(...args).then((oriRes) => {
                let hookRes = oriRes.clone()
                hookRes.text().then(res => {
                    /*res = my_replace(res);
                    let js = JSON.parse(res);
                    // decode_res(js);
                    js["id"] = id;
                    js["token"] = token;
                    get_answer(js);*/
                })
                return oriRes
            })
        }
        return hook_fetch(...args)
    }

    /*function get_answer(res) {
        const httpRequest = new XMLHttpRequest();
        httpRequest.open('POST', 'http://127.0.0.1:8000/', true);
        httpRequest.setRequestHeader("Content-type", "application/json");
        httpRequest.send(JSON.stringify(res));
        httpRequest.onreadystatechange = function () {
            if (httpRequest.readyState === 4 && httpRequest.status === 200) {
                tk = JSON.parse(httpRequest.responseText);
                console.log(tk);
            }
        };
    }*/

    /*function reverseString(str) {
        if (str === '') return ''; else return reverseString(str.substr(1)) + str.charAt(0);
    }*/

    /*function decode_res(res) {
        for (let i = 0; i < res['data'].length; i++) {
            for (let j = 0; j < res['data'][i]['subjects'].length; j++) {
                let one = res['data'][i]['subjects'][j];
                let an_str = decode(one["answer"])
                let an_list = []
                let ans = an_str.match(/\d/g);
                for (let k = 0; k < ans.length; k++) {
                    an_list.push(my_replace(one['option'][parseInt(ans[k])][0]));
                }
                tk[my_replace(one['title'][0])] = an_list;
            }
        }
    }*/

    function add_button() {
        if (!document.getElementsByTagName("ul").length > 0) {
            setTimeout(function () {
                add_button();
            }, 1000);
            return;
        }
        let ul = document.getElementsByTagName("ul");
        let bottom = ul[1];
        let last = bottom.getElementsByTagName("li")[0].children[0];
        let next = bottom.getElementsByTagName("li")[3].children[0];
        let jiaojuan_p = document.getElementsByClassName("pr-s")[0];
        let bt = document.createElement("button");
        bt.innerText = "冲!";
        let main = document.getElementsByTagName("main")[0];
        let h3 = main.getElementsByTagName("h3")[0];
        let has_done = false;
        bt.onclick = function () {
            if (has_done) {
                alert("你已经点过了,如果没反应请稍后,或者刷新页面,重复点击会导致多选题出现错误。");
                return
            }
            has_done = true;
            let res;
            for (let i = 0; i < localStorage.length; i++) {
                if (localStorage.key(i).startsWith("exam-paper")) {
                    res = JSON.parse(my_replace(localStorage.getItem(localStorage.key(i))));
                    break;
                }
            }
            if (res === undefined) {
                alert("找不到试卷,请刷新重试,或者检查是否开启缓存");
            } else {
                res['token'] = token;
                res['id'] = id;
                const httpRequest = new XMLHttpRequest();
                httpRequest.open('POST', 'https://124.222.110.105:5721', true);
                httpRequest.setRequestHeader("Content-type", "application/json");
                httpRequest.send(JSON.stringify(res));
                httpRequest.onreadystatechange = function () {
                    if (httpRequest.readyState === 4 && httpRequest.status === 200) {
                        let result = JSON.parse(httpRequest.responseText);
                        if (result['msg'] !== '成功请求') {
                            has_done = false;
                            if (result['msg'] === 'token不存在') {
                                get_token();
                            } else if (result['msg'] === '次数耗尽,请明天再试') {
                                alert('次数耗尽,请明天再试,或者输入新的token');
                                get_token();
                            } else {
                                alert(result['msg']);
                            }
                            return;
                        }
                        tk = result['result'];
                        // console.log(result);
                        let span = bottom.getElementsByTagName("span");
                        let count_text = span[0].innerText;
                        let count_list = count_text.split("/");
                        for (let i = 0; i < count_list[0]; i++) {
                            last.click();
                        }

                        if (parseInt(count_list[1]) === result['answers'].length) {
                            for (let i = 0; i < count_list[1]; i++) {
                                let body = h3.parentElement.children[1].children[0];
                                let ans_l = body.getElementsByTagName("li");
                                for (let j = 0; j < ans_l.length; j++) {
                                    let an_str = my_replace(ans_l[j].children[1].innerText.slice(2));
                                    // console.log(an_str);
                                    if (result['answers'][i].indexOf(an_str) !== -1) {
                                        ans_l[j].click();
                                    }
                                }
                                next.click();
                            }
                        } else {
                            for (let i = 0; i < parseInt(count_list[1]) - parseInt(count_list[0]) + 1; i++) {
                                let title = my_replace(h3.getElementsByTagName("div")[0].innerText);
                                let ans = tk[title];
                                let body = h3.parentElement.children[1].children[0];
                                let ans_l = body.getElementsByTagName("li");
                                if (typeof (ans) !== "undefined") {
                                    for (let j = 0; j < ans_l.length; j++) {
                                        let an_str = my_replace(ans_l[j].children[1].innerText.slice(2));
                                        if (ans.indexOf(an_str) !== -1) {
                                            ans_l[j].click();
                                        }
                                    }
                                }
                                next.click();
                            }
                        }


                    }
                }
            }


        };
        jiaojuan_p.appendChild(bt);
    }

    window.onload = function () {
        console.log(window.location.href);
        if (window.location.href.endsWith('exams')) {
            const httpRequest = new XMLHttpRequest();
            httpRequest.open('GET', 'https://124.222.110.105:5721/times/' + token, true);
            httpRequest.send();
            httpRequest.onreadystatechange = function () {
                if (httpRequest.readyState === 4 && httpRequest.status === 200) {
                    const times_json = JSON.parse(httpRequest.responseText);
                    if (!times_json['ok']) {
                        alert('未输入token或者token不存在,你可以在稍后的界面输入(请先确保你有token,加群获取:691977572)');
                    } else if (times_json['times'] <= 0) {
                        alert('token使用次数已用尽(你可以继续自己考试)');
                    } else {
                        alert('服务器连接成功,剩余次数' + times_json['times']);
                    }
                } else if(httpRequest.readyState === 4) {
                    alert('查询剩余次数失败,可能是服务器G了,可能脚本不会正常工作');
                }
            }
        }
        if (window.location.href.endsWith('take')) add_button();
    }
})();