Skip to content

Instantly share code, notes, and snippets.

@normanzb
Created January 9, 2012 02:51
Show Gist options
  • Save normanzb/1580772 to your computer and use it in GitHub Desktop.
Save normanzb/1580772 to your computer and use it in GitHub Desktop.
auto order
var foobar2 = jQuery('#main')[0].contentWindow;
var hack = {};
hack.config = {
today: '2012-01-08',
date: '2012-01-20',
from: 'SMS',
fromText: '三明',
toText: '上海南',
to: 'SNH',
trainCode: '',
timeRange: "00:00--24:00",
roundType: 1
}
function checkHasTicket(value){
return value.indexOf('有') > -1;
}
function waitForOrderWin(success, error){
console.log('wait for order win');
if (!success){return;}
var args = arguments;
try{
console.log('try to visit html');
var html = foobar2.document.body.innerHTML;
console.log('html got')
if (html.indexOf('系统忙') > -1){
console.log('system busy');
error('系统忙');
}
else if(html.indexOf('以上余票信息随时发生变化,仅作参') > -1){
success();
}
else{
throw 'content not found';
}
}
catch(ex){
console.log(ex);
setTimeout(function(){
console.log('args')
waitForOrderWin.apply(window, args);
}, 500);
}
}
function waitForQueryWin(success, error){
console.log('wait for query win');
if (!success){return;}
var args = arguments;
try{
console.log('try to visit html');
var html = foobar2.document.body.innerHTML;
console.log('html got')
if(html.indexOf('简码为车站简拼前两位或三位') > -1){
success();
}
else{
throw 'content not found';
}
}
catch(ex){
console.log(ex);
setTimeout(function(){
console.log('args')
waitForQueryWin.apply(window, args);
}, 500);
}
}
hack.query = function(){
console.log('configuring...');
var $ = foobar2.$;
$('#startdatepicker').val(hack.config.date);
$('#fromStation').val(hack.config.from);
$('#toStation').val(hack.config.to);
$('#trainCode').val(hack.config.trainCode);
$('#startTime').val(hack.config.timeRange);
$('#train_date').val(hack.config.date);
$('#include_student').val(foobar2.getIncludeStudent());
$('#from_station_telecode_name').val(hack.config.fromText);
$('#to_station_telecode_name').val(hack.config.toText);
$('#round_train_date').val(hack.config.today);
$('#round_start_time_str').val(hack.config.timeRange);
$('#start_time_str').val(hack.config.timeRange);
$('#single_round_type').val(hack.config.roundType);
$('#train_pass_type').val(foobar2.getTrainPassType());
$('#train_class_arr').val(foobar2.getTrainClassString());
console.log('loading...');
//异步请求站名
$.ajax( {
url : foobar2.ctx + '/order/querySingleAction.do?method=queryLeftTicket',
type : "GET",
dataType:'text',
data:{
'orderRequest.train_date' : $('#startdatepicker').val(),
'orderRequest.from_station_telecode' : $('#fromStation').val(),
'orderRequest.to_station_telecode' : $('#toStation').val(),
'orderRequest.train_no' : $('#trainCode').val(),
'trainPassType' : foobar2.getTrainPassType(), //QB
'trainClass' : foobar2.getTrainClassString(), //'QB#D#Z#T#K#QT#',
'includeStudent' : foobar2.getIncludeStudent(), //'00' ,
'seatTypeAndNum' : foobar2.getSeanTypeAndNum(), // '',
'orderRequest.start_time_str' : $('#startTime').val()
},
success : function(data, textStatus) {
if(data == "-10"){
alert("您还没有登录或者离开页面的时间过长,请登录系统或者刷新页面");
window.location.href=ctx+"/loginAction.do?method=init";
return;
}
if(data == "-1") {
console.log("服务器忙,加载查询数据失败!");
data = "";
setTimeout(hack.query, 500);
return;
} else if(data !="undefine" &&data.split(",")[0]=="-2"){
console.log(data.split(",")[1]);
data="";
setTimeout(hack.query, 500);
return;
}else {
data=data.replace(/\\\\n/g, String.fromCharCode(10));
}
console.log('done')
hack.data = data;
console.log(data);
foobar2.mygrid.clearAll();
foobar2.mygrid.startFastOperations();
foobar2.mygrid.parse(data,"csv");
foobar2.mygrid.stopFastOperations();
foobar2.dealwithQueryInfo(foobar2.mygrid);
/*if(clickBuyStudentTicket=='Y'){
$("#stu_submitQuery").attr("disabled",false);
}else{
$("#submitQuery").click(sendQueryFunc);
}*/
foobar2.removeLoadMsg();
hack.order(data);
},
error : function(e) {
console.log("服务器忙,加载查询数据失败!");
foobar2.removeLoadMsg();
foobar2.validQueryButton();
if(isStudentTicketDateValid()){
foobar2.stu_validQueryButton();
}
if(clickBuyStudentTicket=='N'){
foobar2.renameButton('research_u');
//$("#submitQuery").click(sendQueryFunc);
}else{
foobar2.stu_renameButton('research_u');
//$("#stu_submitQuery").click(sendQueryFunc);
//$("#stu_submitQuery").attr("disabled",false);
}
setTimeout(hack.query, 500);
}
});
}
hack.getSelected = function(selectStr) {
var selectStr_arr = selectStr.split("#");
var station_train_code=selectStr_arr[0];
var lishi=selectStr_arr[1];
var starttime=selectStr_arr[2];
var trainno=selectStr_arr[3];
var from_station_telecode=selectStr_arr[4];
var to_station_telecode=selectStr_arr[5];
var arrive_time=selectStr_arr[6];
var from_station_name=selectStr_arr[7];
var to_station_name=selectStr_arr[8];
var ypInfoDetail=selectStr_arr[9];
var flag = true;
if (foobar2.checkBeyondMixTicketNum()) {
flag = false;
return;
}
// 该方法在各个页面中分别书写,因为根据页面的不同行为不同,相当于重写
if (flag) {
console.log('tyring to submit form')
foobar2.submitRequest(station_train_code,lishi,starttime,trainno,from_station_telecode,to_station_telecode,arrive_time,from_station_name,to_station_name,ypInfoDetail);
waitForOrderWin(function(){
console.log('order form displayed')
}, function(){
console.log('trying to redirect')
foobar2.location.href='/otsweb/order/querySingleAction.do?method=init';
waitForQueryWin(function(){
if (hack.stop === true){
return;
}
hack.query();
}, function(){
alert('unexpected err')
})
});
}
};
hack.submitRequest = function(station_train_code,lishi,starttime,trainno,from_station_telecode,to_station_telecode,
arrive_time,from_station_name,to_station_name,ypInfoDetail) {
var $ = foobar2.$;
$('#station_train_code').val(station_train_code);
$('#lishi').val(lishi);
$('#train_start_time').val(starttime);
$('#trainno').val(trainno);
$('#from_station_telecode').val(from_station_telecode);
$('#to_station_telecode').val(to_station_telecode);
$('#arrive_time').val(arrive_time);
$('#from_station_name').val(from_station_name);
$('#to_station_name').val(to_station_name);
$('#ypInfoDetail').val(ypInfoDetail);
$('#orderForm').attr("action",
ctx+"/order/querySingleAction.do?method=submutOrderRequest");
$('#orderForm').submit();
}
hack.order = function(data){
var data = data.split(','), sData = {};
// soft seat
sData.softSeat = checkHasTicket(data[12]);
sData.hardBed = checkHasTicket(data[11]);
sData.submitParam = data[16].replace('getSelected', 'hack.getSelected');
if (sData.softSeat || sData.hardBed){
window.fooo = sData.submitParam;
jQuery(sData.submitParam).click();
console.log('try to submit')
}
else{
if (hack.stop === true){
return;
}
hack.query();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment