易班考试

理论上所有不限次数的考试都可以用。做题查看试卷之后会自动获取题库。多考几次就可以满分。如果显示404,请打开手机模式(按下f12,在新界面最左上角点击第二个图标),或者使用via浏览器(手机端的可以使用脚本的浏览器)。

Fra og med 17.07.2023. Se den nyeste version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         易班考试
// @namespace    http://tampermonkey.net/
// @license Common
// @version      1.0.4
// @description  理论上所有不限次数的考试都可以用。做题查看试卷之后会自动获取题库。多考几次就可以满分。如果显示404,请打开手机模式(按下f12,在新界面最左上角点击第二个图标),或者使用via浏览器(手机端的可以使用脚本的浏览器)。
// @author       木木
// @match        https://exam.yooc.me/group/*/exam/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=yooc.me
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function () {
    'use strict';
    // 手动添加mate标签
    const addMeta = (name, content) => {
        const meta = document.createElement('meta');
        meta.content = content;
        meta.name = name;
        document.getElementsByTagName('head')[0].appendChild(meta);
    };

    addMeta(
        'http-equiv',
        'Content-Security-Policy',
    );
    addMeta('content', 'upgrade-insecure-requests');

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

    var localStorage = window.localStorage;

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

    function get_value(key) {
        if (localStorage) var v = localStorage.getItem(key);
        if (!v) {
            return;
        }
        return v;
    }

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

    function get_token() {
        let t = prompt("请输入token(加374555748发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);
        }
        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];
        bt.onclick = function () {
            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'] === '成功请求') {
                            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();
                                }
                            }


                        } else if (result['msg'] === 'token不存在') {
                            get_token();
                        } else {
                            alert(result['msg']);
                        }
                    }
                }
            }


        };
        jiaojuan_p.appendChild(bt);
    }

    window.onload = function () {
        add_button();
    }
})();