Spectrum自动登录

此代码是为了帮助用户自动登录马来亚大学的SPeCTRUM系统

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Spectrum Auto Login
// @name:zh-CN   Spectrum自动登录
// @name:zh-TW   Spectrum自动登录
// @name:id      Spectrum Log masuk automatik
// @name:ms      Spectrum Log masuk automatik
// @namespace    http://tampermonkey.net/
// @version      0.3.0
// @license      MIT
// @description  This code is designed to help users automatically log into the University of Malaya's SPeCTRUM system.
// @description:zh-CN  此代码是为了帮助用户自动登录马来亚大学的SPeCTRUM系统
// @description:zh-TW  此代码是为了帮助用户自动登录马来亚大学的SPeCTRUM系统
// @description:ms  Kod ini direka untuk membantu pengguna masuk ke sistem SPeCTRUM Universiti Malaya secara automatik.
// @description:id  Kod ini direka untuk membantu pengguna masuk ke sistem SPeCTRUM Universiti Malaya secara automatik.
// @author       Koukotsukan Neo
// @match        https://sso.um.edu.my/cas/*
// @match        https://spectrum.um.edu.my
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_deleteValue
// @require      http://libs.baidu.com/jquery/2.0.0/jquery.min.js
// ==/UserScript==

(function() {
    const curURL = window.location.href;
    const match = (...patterns) => patterns.some(p => curURL.includes(p));
    if (match("https://sso.um.edu.my/cas/loginAllType?service=https://spectrum.um.edu.my/login/index.php")){
        GM_deleteValue('method');
        GM_deleteValue('uname');
        GM_deleteValue("pwd");
        var z= document.createElement('a');
        z.setAttribute("href","javascript:void(0);");
        z.setAttribute("id","helper");
        z.innerText='Problems with Autofill?';
        document.querySelectorAll("div[class=\"form-group\"]")[0].appendChild(z);
        document.querySelector ("#helper").addEventListener("click", doEd, false);
        if (!document.querySelector("div[class='error']")){
            location.href="https://sso.um.edu.my/cas/loginAllType?service=https%3A%2F%2Fspectrum.um.edu.my%2Flogin%2Findex.php";
        }
    };
    if(match("https://sso.um.edu.my/cas/loginAllType?service=https%3A%2F%2Fspectrum.um.edu.my%2Flogin%2Findex.php")){
        $(document).ready(function(){
            var x=document.getElementById("domain");
            x.innerHTML="<select name=\"domain\" id=\"domain\"><option selected=\"\" value=\"@perdana.um.edu.my\">Student</option><option value=\"@um.edu.my\">Staff</option><option value=\"\">External</option></select>";
            var z= document.createElement('a');
            z.setAttribute("href","javascript:void(0);");
            z.setAttribute("id","helper");
            z.innerText='Problems with Autofill?';
            document.querySelectorAll("div[class=\"form-group\"]")[0].appendChild(z);
            document.querySelector ("#helper").addEventListener("click", doAnother, false);
            if (!GM_getValue('method')){
                $(document).ready(function(){
                    document.querySelector("button[type=submit]").click();
                });
            }else if (GM_getValue('method')== 1){
                $(document).ready(function(){
                    document.querySelector("input[name='uname']").value=GM_getValue('uname');
                    document.querySelector("input[name='password']").value=GM_getValue('pwd');
                    document.querySelector("button[type=submit]").click();
                });
            }
        });
    }else if (match("https://spectrum.um.edu.my")) {
        document.querySelector("span.login").querySelector("a").click();
    }

    function doAnother(se){
        if(!GM_getValue('method')){
            var uname = prompt("Username", "");
            var password = prompt("Password","");
            GM_setValue('uname',uname);
            GM_setValue("pwd", password);
            GM_setValue("method","1");
            location.reload();
        }else if (GM_getValue('method') == 1){
            GM_deleteValue('method');
        };
        if (se == 1){
            location.reload();
        }else if (se == 0){

        }
    };
        function doEd(){
        if(!GM_getValue('method')){
            var uname = prompt("Username", "");
            var password = prompt("Password","");
            GM_setValue('uname',uname);
            GM_setValue("pwd", password);
            GM_setValue("method","1");
            location.href="https://sso.um.edu.my/cas/loginAllType?service=https%3A%2F%2Fspectrum.um.edu.my%2Flogin%2Findex.php";
        }else if (GM_getValue('method') == 1){
            GM_deleteValue('method');
            document.querySelector("button[type=submit]").click();
        };
    };
}
)();