public

12306 Auto Login

  • Download Gist
12306AutoLogin.user.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
/*
12306 Auto Login => A javascript snippet to help you auto login 12306.com.
Copyright (C) 2011 Kevintop
Includes jQuery
Copyright 2011, John Resig
Dual licensed under the MIT or GPL Version 2 licenses.
http://jquery.org/license
 
Includes 12306.user.js
https://gist.github.com/1554666
Copyright (C) 2011 Jingqin Lynn
Released GNU Licenses.
 
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
 
*/
 
// ==UserScript==
// @name 12306 Auto Login
// @author kevintop@gmail.com
// @namespace https://plus.google.com/107416899831145722597
// @description A javascript snippet to help you auto login 12306.com
// @include *://dynamic.12306.cn/otsweb/loginAction.do*
// @include *://dynamic.12306.cn/otsweb/login.jsp*
// ==/UserScript==
function withjQuery(callback, safe){
if(typeof(jQuery) == "undefined") {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js";
 
if(safe) {
var cb = document.createElement("script");
cb.type = "text/javascript";
cb.textContent = "jQuery.noConflict();(" + callback.toString() + ")(jQuery);";
script.addEventListener('load', function() {
document.head.appendChild(cb);
});
}
else {
var dollar = undefined;
if(typeof($) != "undefined") dollar = $;
script.addEventListener('load', function() {
jQuery.noConflict();
$ = dollar;
callback(jQuery);
});
}
document.head.appendChild(script);
} else {
callback(jQuery);
}
}
withjQuery(function($){
//login
var url = "https://dynamic.12306.cn/otsweb/loginAction.do?method=login";
var queryurl = "https://dynamic.12306.cn/otsweb/order/querySingleAction.do?method=init";
function submitForm(){
var submitUrl = url;
$.ajax({
type: "POST",
url: submitUrl,
data: {
"loginUser.user_name": $("#UserName").val()
, "user.password": $("#password").val()
, "randCode": $("#randCode").val()
},
timeout: 30000,
//cache: false,
//async: false,
success: function(msg){
if (msg.indexOf('请输入正确的验证码') > -1) {
alert('请输入正确的验证码!');
};
if (msg.indexOf('当前访问用户过多') > -1|| msg.match(/var\s+isLogin\s*=\s*false/i)) {
reLogin();
}
else {
$('#refreshButton').html("成功,请点车票预订!");
location.replace(queryurl);
};
},
error: function(msg){
reLogin();
},
beforeSend: function(XHR){
//alert("Data Saved: " + XHR);
}
});
}
 
var count = 1;
function reLogin(){
count ++;
$('#refreshButton').html("("+count+")次登录中...");
setTimeout(submitForm, 2000);
}
//初始化
if($("#refreshButton").size()<1){
$("#subLink").after($("<a href='#' style='padding: 5px 10px; background: #2CC03E;border-color: #259A33;border-right-color: #2CC03E;border-bottom-color:#2CC03E;color: white;border-radius: 5px;text-shadow: -1px -1px 0 rgba(0, 0, 0, 0.2);'/>").attr("id", "refreshButton").html("自动登录").click(function() {
alert('开始尝试登录,请点确定后耐心等待!');
count = 1;
$(this).html("(1)次登录中...");
submitForm();
return false;
}));
alert('如果使用自动登录功能,请输入用户名、密码及验证码后,点击自动登录,系统会尝试登录,直至成功!');
}
}, true);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.