Auto grading

USTC 自动评价 tqm.ustc.edu.cn

目前為 2023-06-08 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Auto grading
// @namespace    http://tampermonkey.net/
// @version      0.4.0
// @description  USTC 自动评价 tqm.ustc.edu.cn
// @author       PRO_2684
// @match        https://tqm.ustc.edu.cn/index.html*
// @icon         https://tqm.ustc.edu.cn/favicon.ico
// @grant        none
// @license      gpl-3.0
// @require      https://greasyfork.org/scripts/468177-%E6%95%99%E5%AD%A6%E8%B4%A8%E9%87%8F%E7%AE%A1%E7%90%86%E5%B9%B3%E5%8F%B0%E6%A0%87%E5%87%86%E7%AD%94%E6%A1%88/code/%E6%95%99%E5%AD%A6%E8%B4%A8%E9%87%8F%E7%AE%A1%E7%90%86%E5%B9%B3%E5%8F%B0%E6%A0%87%E5%87%86%E7%AD%94%E6%A1%88.js?version=1201736
// ==/UserScript==

(function() {
    'use strict';
    let menu_root;
    function append_link() {
        let auto_grade = document.createElement('li');
        auto_grade.innerText = "自动评价";
        auto_grade.onclick = grade;
        auto_grade.setAttribute('class', 'ant-menu-item');
        menu_root.appendChild(auto_grade);
        let ignore_continue = document.createElement('li');
        ignore_continue.innerText = "忽略并转到下一个";
        ignore_continue.onclick = ignore;
        ignore_continue.setAttribute('class', 'ant-menu-item');
        menu_root.appendChild(ignore_continue);
    }
    function grade() {
        let questions = document.querySelectorAll("[class|='index_subject']");
        questions.forEach((question) => {
            let required = Boolean(question.querySelector('[class|="index_necessary"]'));
            if (!required) return;
            let tmp = question.querySelector("[class|='index_title']").querySelectorAll('p');
            let title = tmp[tmp.length - 1].innerText;
            let standard_answer = standard_answers[title];
            console.log(`[Auto grading] ${title}: ${standard_answer}`);
            if (standard_answer) {
                let options = question.querySelectorAll('[style="width: 100%;"]');
                options.forEach((option) => {
                    let is_standard_answer = (standard_answer.indexOf(option.innerText) >= 0);
                    if (is_standard_answer) {
                        option.firstChild.click();
                    }
                });
            }
        });
    }
    function ignore() {
        let ignore_btn = root_node.querySelector("[class|='TaskDetailsMainContent_normalButton']");
        if (ignore_btn && ignore_btn.parentElement.parentElement.parentElement.getAttribute('aria-hidden') == 'false') {
            ignore_btn.click();
        } else {
            console.log("[Auto grading] 未找到忽略按钮!");
        }
        let tabs = root_node.querySelector("[class='ant-tabs-nav-scroll']");
        if (tabs) {
            tabs = tabs.children[0].children[0];
        } else {
            console.log("[Auto grading] 未找到教师/助教列表!");
            return;
        }
        let flag = false;
        let tab;
        for (tab of tabs.children) {
            if (flag) {
                tab.click();
                break;
            } else if (tab.getAttribute('aria-selected') == 'true') {
                flag = true;
            }
        }
    }
    const root_node = document.getElementById('root');
    const config = { attributes: false, childList: true, subtree: true };
    const callback = function(mutations, observer) {
        menu_root = root_node.querySelector('.ant-menu-root');
        if (menu_root) {
            append_link();
            observer.disconnect();
        }
    }
    const observer = new MutationObserver(callback);
    observer.observe(root_node, config);
})();