Auto login

绕过中科大统一身份认证的验证码并自动聚焦至登录按钮

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Auto login
// @namespace    http://tampermonkey.net/
// @version      0.2
// @license      gpl-3.0
// @description  绕过中科大统一身份认证的验证码并自动聚焦至登录按钮
// @author       PRO
// @match        https://passport.ustc.edu.cn/*
// @icon         https://passport.ustc.edu.cn/images/favicon.ico
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    let form = document.getElementsByClassName('loginForm')[0]; // 登录表格
    let options = { // observer 观察选项
        childList: true, // 观察目标子节点的变化,添加或删除
        attributes: false, // 观察属性变动
        subtree: true // 默认是false,设置为true后可观察后代节点
    }
    function bypass() { // 绕过验证码
        // 将 showCode 设置为空以绕过服务器的验证码校验
        let showCode = document.getElementsByName('showCode')[0];
        showCode.value = "";
        // 移除验证码元素
        let code = document.querySelector('#valiCode');
        code.remove();
    }
    function focus() { // 将焦点移至登录按钮,以便直接按下回车登录
        var button = document.getElementById('login');
        button.focus();
    }
    function main() { // 主函数
        bypass();
        focus();
        observer.disconnect(); // observer 停止观测
    }
    let observer = new MutationObserver(main); // 实例化 observer
    observer.observe(form, options); // 开始观测
})();