Greasy Fork

Greasy Fork is available in English.

USTC 助手

为 USTC 学生定制的各类实用功能。

当前为 2022-10-22 提交的版本,查看 最新版本

// ==UserScript==
// @name         USTC Helper
// @name:zh-CN   USTC 助手
// @license      unlicense
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Various useful functions for USTC students.
// @description:zh-CN  为 USTC 学生定制的各类实用功能。
// @author       PRO
// @match        https://mail.ustc.edu.cn/
// @match        https://mail.ustc.edu.cn/coremail/index.jsp*
// @match        https://passport.ustc.edu.cn/*
// @icon         https://passport.ustc.edu.cn/images/favicon.ico
// @grant        none
// ==/UserScript==

(function () {
    'use strict';
    var uhp_config = {
        passport: {
            enabled: true, // If false, all features will be disabled for passport.ustc.edu.cn
            bypass_code: true, // Whether to bypass verification code or not
            focus: true // Whether to focus on "Login" button
        },
        mail: {
            enabled: true, // If false, all features will be disabled for mail.ustc.edu.cn
            focus: true, // Whether to focus on "Login" button
            domain: 'mail.ustc.edu.cn' // Automatically switch to given mail domain
            // Expected values:
            // 'mail.ustc.edu.cn'
            // 'ustc.edu.cn'
            // 'ah.edu.cn'
            // '' (Do nothing)
        }
    };
    switch (window.location.host) {
        case 'mail.ustc.edu.cn':
            if (!uhp_config.mail.enabled) {
                console.info("[USTC Helper] Feature disabled.");
                break;
            }
            if (uhp_config.mail.domain) {
                changeDomain(uhp_config.mail.domain);
                console.info(`[USTC Helper] Domain changed to ${uhp_config.mail.domain}.`);
            }
            if (uhp_config.mail.focus) {
                document.getElementById("login_button").focus();
                console.info("[USTC Helper] Login button focused.");
            }
            break;
        case 'passport.ustc.edu.cn': {
            if (!uhp_config.passport.enabled) {
                console.info("[USTC Helper] Feature disabled.");
                break;
            }
            let form = document.getElementsByClassName('loginForm')[0];
            let options = {
                childList: true,
                attributes: false,
                subtree: true
            }
            function bypass() {
                let showCode = document.getElementsByName('showCode')[0];
                showCode.value = "";
                let code = document.querySelector('#valiCode');
                code.remove();
                console.info("[USTC Helper] Verification code bypassed.");
            }
            function focus() {
                document.getElementById('login').focus();
                console.info("[USTC Helper] Login button focused.");
            }
            function main() {
                if (uhp_config.passport.bypass_code) bypass();
                if (uhp_config.passport.focus) focus();
                observer.disconnect();
            }
            let observer = new MutationObserver(main);
            observer.observe(form, options);
            break;
        }
        default:
            console.error("[USTC Helper] Unexpected host: " + window.location.host);
            break;
    }
})();