SRUN3000校园认证系统自动登录系统

自动登录srun3000校园认证系统,登录成功后关闭登录页面返回跳转前页面

目前為 2015-12-14 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         SRUN3000校园认证系统自动登录系统
// @namespace    Kn
// @version      0.2
// @description  自动登录srun3000校园认证系统,登录成功后关闭登录页面返回跳转前页面
// @author       KevinTan
// @match        http://192.0.0.6/*
// @grant        none
// ==/UserScript==
/* jshint -W097 */
'use strict';

// code begin
window.dict = {
    'user_tab_error':'认证程序未启动',
    'username_error':'用户名错误,请在localStorage中修改usernamae字段',
    'non_auth_error':'您无须认证,可直接上网',
    'password_error':'密码错误,清单localStorage中修改password字段',
    'status_error':'用户已欠费,请尽快充值。',
    'available_error':'用户已禁用',
    'ip_exist_error':'您的IP尚未下线,请等待2分钟再试。',
    'usernum_error':'用户数已达上限',
    'online_num_error':'该帐号的登录人数已超过限额\n如果怀疑帐号被盗用,请联系管理员。',
    'mode_error':'系统已禁止WEB方式登录,请使用客户端',
    'time_policy_error':'当前时段不允许连接',
    'flux_error':'您的流量已超支',
    'minutes_error':'您的时长已超支',
    'ip_error':'您的IP地址不合法',
    'mac_error':'您的MAC地址不合法',
    'sync_error':'您的资料已修改,正在等待同步,请2分钟后再试。',

    'logout_ok':'注销成功,请等1分钟后登录。',
    'logout_error':'您不在线上'
};
var GM_log = console.log.bind(console);
window.AutoLogin = function(loginInfo){
    var loginStr="username="+loginInfo.username+"&password="+loginInfo.password+"&drop=0&type=1&n=1";
    GM_log(loginStr);
    var req = new XMLHttpRequest();
    req.open('POST','/cgi-bin/do_login');
    req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    req.send(loginStr);
    req.addEventListener('load',function(e){
        var status = req.responseText;
        var p=/^[\d]+$/;
        if(p.test(status)){
            GM_log('登录成功!');
            //跳转回原来的页面
            var originUrl = (function (){
                var url = window.location.toString().match(/\?(?:url=)?(https?:\/\/.*)$/);
                return url?url[1]||-1:-1;
            })();
            if(originUrl !== -1){
                window.location.href = originUrl;
            }else{
                window.close();
            }
        }else if(status === 'online_num_error'){
            //forcelogout
            req.open('POST','/cgi-bin/force_logout');
            req.send(loginStr);
        }else if(status === 'logout_ok'){
            window.setTimeout(function(){
                window.AutoLogin(loginInfo);
            },60*1000);
        }else if(status === 'non_auth_error'){
            window.close();
        }else{
            GM_log(window.dict[status]);
        }

    }); 
}
if(document.title.indexOf('欢迎使用') !== -1){
    if(window.localStorage.username==null){
        GM_log('缺少登录信息,无法自动登录,请在locastorage中补充你的登录信息');
        return;
    }

    var loginInfo = {
        username:window.localStorage.username,
        password:hex_md5(window.localStorage.password).substr(8,16)
    }
    loginInfo.userName
    window.AutoLogin(loginInfo);
}else if(document.title.indexOf('登录成功') !== -1){
    window.onbeforeunload=null;
    window.onunload=null;
    if(window.opener){
        window.opener.close();
        window.close();
    }
}