/*
12306 Auto Submit => A javascript snippet to help you auto submit.
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 .
*/
// ==UserScript==
// @name 12306 Auto Submit
// @author kevintop@gmail.com,luobailiang
// @namespace https://plus.google.com/107416899831145722597/none
// @description A javascript snippet to help you auto submit 12306.cn
// @include *://dynamic.12306.cn/otsweb/order/confirmPassengerAction.do*
// ==/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($){
var userInfoUrl = 'https://dynamic.12306.cn/otsweb/sysuser/user_info.jsp';
//var userInfoUrl = 'https://dynamic.12306.cn/otsweb/order/myOrderAction.do?method=queryMyOrderNotComplete&leftmenu=Y';
var count = 0;
var t;
var doing = false;
function submitForm(){
//更改提交列车日期参数
var wantDate = $("#startdatepicker").val();
$("#start_date").val(wantDate);
$("#_train_date_str").val(wantDate);
jQuery.ajax({
url: $("#confirmPassenger").attr('action'),
data: $('#confirmPassenger').serialize(),
type: "POST",
timeout: 60000,
success: function(msg)
{
//Refresh token
var match = msg && msg.match(/org\.apache\.struts\.taglib\.html\.TOKEN['"]?\s*value=['"]?([^'">]+)/i);
var newToken = match && match[1];
if(newToken) {
$("input[name='org.apache.struts.taglib.html.TOKEN']").val(newToken);
}
if( msg.indexOf('payButton') > -1 ) {
//Success!
alert("车票预订成功,恭喜!");
window.location.replace(userInfoUrl);
return;
}else if(msg.indexOf('未处理的订单') > -1){
alert("有未处理的订单!");
window.location.replace(userInfoUrl);
}
var reTryMessage = ['用户过多','确认客票的状态后再尝试后续操作','请不要重复提交'];
for (var i = reTryMessage.length - 1; i >= 0; i--) {
if( msg.indexOf( reTryMessage[i] ) > -1 ) {
showMsg(reTryMessage[i]);
if (doing){
reSubmitForm();
}
return;
}
};
//Parse error message
msg = msg.match(/var\s+message\s*=\s*"([^"]*)/);
stop(msg && msg[1] || '出错了。。。。 啥错? 我也不知道。。。。。');
},
error: function(msg){
showMsg(msg);
reSubmitForm();
}
});
};
function showMsg(msg){
$("#msg_div").html($("#msg_div").html() + "