// ==UserScript== // @name ZJUCSTAutoLogin // @namespace Kn // @version 0.1 // @description Auto login script of ZJU CST Web Authorization System // @author KevinTan // @match http://192.0.0.6/* // @grant none // @downloadURL none // ==/UserScript== /* jshint -W097 */ 'use strict'; // code begin window.dict = { 'user_tab_error':'认证程序未启动', 'username_error':'用户名错误', 'non_auth_error':'您无须认证,可直接上网', 'password_error':'密码错误', '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('登录成功!'); window.close(); }else{ GM_log(window.dict[status]); 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); } } }); } if(document.title === '欢迎使用浙大软件学院认证计费系统'){ 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 === '登录成功'){ window.onbeforeunload=null; window.onunload=null; if(window.opener){ window.opener.close(); window.close(); } }