Skip to content

Instantly share code, notes, and snippets.

@foreveryan
Forked from kevintop/12306AutoSubmit.user.js
Created January 8, 2012 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foreveryan/1578894 to your computer and use it in GitHub Desktop.
Save foreveryan/1578894 to your computer and use it in GitHub Desktop.
12306 Auto Submit
/*
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 <http://www.gnu.org/licenses/>.
*/
// ==UserScript==
// @name 12306 Auto Submit
// @author kevintop@gmail.com
// @namespace https://plus.google.com/107416899831145722597/none
// @description A javascript snippet to help you auto login 12306.com
// @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 = 1;
var tokenSplitStr = '<input type="hidden" name="org.apache.struts.taglib.html.TOKEN" value="';
function submitForm(){
jQuery.ajax({
url: $("#confirmPassenger").attr('action'),
data: $('#confirmPassenger').serialize(),
type: "POST",
timeout: 30000,
success: function(msg)
{
if(msg.indexOf(tokenSplitStr) > -1){
$("input[name='org.apache.struts.taglib.html.TOKEN']").val(msg.split(tokenSplitStr)[1].split('">')[0]);
}
if (msg.indexOf('输入的验证码不正确') > -1) {
alert('请输入正确的验证码!');
} else if (msg.indexOf('用户过多') > -1) {
reSubmitForm();
}else if (msg.indexOf('确认客票的状态后再尝试后续操作') > -1) {
//alert('呃。。。可能没票了,赶紧返回选别的票吧,否则将继续为你尝试!');
reSubmitForm();
}else if(msg.indexOf('没有足够的票') > -1){
//alert('系统说,没有足够的票了,您还是换个车次吧。。。');
reSubmitForm();
}else if(msg.indexOf('席位已经锁定') > -1){
$('#refreshButton').html("车票预订成功,恭喜!");
location.replace(userInfoUrl);
}else if(msg.indexOf('请不要重复提交') > -1){
//alert('重复提交,继续重试!!!');
reSubmitForm();
}else if(msg.indexOf('席别不能为空') > -1){
alert('席别不能为空');
}else if(msg.indexOf('取消次数过多') > -1){
alert('您取消次数过多,系统不受理,请明天再买吧!!!');
}else{
alert('出错了。。。。 啥错? 我也不知道。。。。。');
};
},
error: function(msg){
reSubmitForm();
}
});
};
function reSubmitForm(){
count ++;
$('#refreshButton').html("("+count+")次自动提交中...");
setTimeout(submitForm, 500);
}
//初始化
if($("#refreshButton").size()<1){
$(".tj_btn").append($("<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)次自动提交中...");
if(window.submit_form_check && !submit_form_check("confirmPassenger") ) {
return;
}
submitForm();
return false;
}));
alert('如果使用自动提交订单功能,请在确认订单正确无误后,再点击自动提交按钮!');
}
}, true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment