评教脚本

hqu一键评教

// ==UserScript==
// @name         评教脚本
// @namespace    http://tampermonkey.net/
// @version      2025-01-06
// @description  hqu一键评教
// @author       You
// @match        http://jwapp-hqu-edu-cn-s.w.hqu.edu.cn:8118/jwapp/sys/pjapp/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=hqu.edu.cn
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    //#region 工具函数

    function checkSingles() {
        // 单选
        const singles = document.querySelectorAll(".jqx-radiobutton-text"); // 获取全部单选框
        let randint; // 单选偏移量
        let target; // 最终点击目标
        for (let i = 0; i < singles.length; i = i + 5) {
            randint = Math.floor(Math.random() * 2); // 随机偏移量
            target = i + randint;
            singles[target].click(); // 点击单选框
        }

        // 单选部分完成
        // 滚动到页面底部
        window.scrollTo({
            top: document.documentElement.scrollHeight,
            behavior: "smooth",
        });
    }

    function checkMutis() {
        // 多选
        const mutis = document.querySelectorAll(
            '.wjtxQuestionOptionItem div[role="checkbox"]'
        ); // 获取全部多选框
        const flags = [1, 1, 1, 1];
        for (let i = 0; i < Math.floor(1 + Math.random() * 3); i++) {
            randint = Math.floor(Math.random() * 4); // 随机抽选项点
            if (flags[randint]) {
                flags[randint] = 0;
                const checkbox = mutis[randint];
                if (typeof $(checkbox).jqxCheckBox === "function") {
                    $(checkbox).jqxCheckBox("check");
                }
            }
            console.log(randint);
        }
    }

    // 主观题
    function fillText() {
        const textareas = $('textarea.jqx-text-area-element')
        textareas.each(function() {
            $(this).jqxTextArea('val', '好'); // 设置值
            let changeEvent = new Event('change', { bubbles: true, cancelable: true });
            this.dispatchEvent(changeEvent);
        });
    }

    //#endregion



    // 添加按钮到页面
    const button = document.createElement("button");
    button.innerText = "一键评教";
    button.style.position = "absolute";
    button.style.zIndex = "99999";
    button.style.cursor = "move";
    button.style.left = "50%";
    button.style.top = "50%";
    document.body.appendChild(button);

    // 为按钮添加点击事件监听器
    button.addEventListener('click', function() {
        checkSingles();
        checkMutis();
        fillText();
    });

    // 使按钮可拖动
    button.addEventListener('mousedown', function(e) {
        let offsetX = e.clientX - button.getBoundingClientRect().left;
        let offsetY = e.clientY - button.getBoundingClientRect().top;
        function mouseMoveHandler(e) {
            button.style.left = `${e.clientX - offsetX}px`;
            button.style.top = `${e.clientY - offsetY}px`;
        }
        function mouseUpHandler() {
            document.removeEventListener('mousemove', mouseMoveHandler);
            document.removeEventListener('mouseup', mouseUpHandler);
        }
        document.addEventListener('mousemove', mouseMoveHandler);
        document.addEventListener('mouseup', mouseUpHandler);
    });

    // Your code here...
})();