USTC Helper

Various useful functions for USTC students.

As of 22. 10. 2022. See the latest 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         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;
    }
})();