-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path12306BookingAssistant.user.js
776 lines (728 loc) · 34.5 KB
/
12306BookingAssistant.user.js
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
/*
* 12306 Auto Query => A javascript snippet to help you book tickets online.
* 12306 Booking Assistant
* Copyright (C) 2011 Hidden
*
* 12306 Auto Query => A javascript snippet to help you book tickets online.
* Copyright (C) 2011 Jingqin Lynn
*
* 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
*
* 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 Booking Assistant
// @version 1.5.3
// @author [email protected]
// @namespace https://github.com/zzdhidden
// @description 12306 订票助手之(自动登录,自动查票,自动订单)
// @include *://dynamic.12306.cn/otsweb/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
// ==/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, window);";
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, window);
});
}
document.head.appendChild(script);
} else {
setTimeout(function() {
//Firefox supports
callback(jQuery, typeof unsafeWindow === "undefined" ? window : unsafeWindow);
}, 30);
}
}
withjQuery(function($, window){
$(document).click(function() {
if( window.webkitNotifications && window.webkitNotifications.checkPermission() != 0 ) {
window.webkitNotifications.requestPermission();
}
});
function notify(str, timeout, skipAlert, audio) {
if( window.webkitNotifications && window.webkitNotifications.checkPermission() == 0 ) {
var notification = webkitNotifications.createNotification(
"http://www.12306.cn/mormhweb/images/favicon.ico", // icon url - can be relative
'12306订票助手', // notification title
str
);
notification.onclose = function() {
if(audio && !audio.paused)
audio.pause();
};
notification.onclick = function() {
this.cancel();
};
if(audio)
audio.play();
notification.show();
if ( timeout ) {
setTimeout(function() {
notification.cancel();
}, timeout);
}
return notification;
} else {
if( !skipAlert ) {
if(audio)
audio.play();
alert( str );
if(audio && !audio.paused)
audio.pause();
}
return null;
}
}
function route(match, fn) {
if( window.location.href.indexOf(match) != -1 ) {
fn();
};
}
function query() {
//query
var maxIncreaseDay = 0 ;
var start_autoIncreaseDay = null ;
var index_autoIncreaseDay = 1 ;
var pools_autoIncreaseDay = [] ;
function __reset_autoIncreaseDays(){
maxIncreaseDay = parseInt( document.getElementById('autoIncreaseDays').value ) || 1 ;
if( maxIncreaseDay > 10 ) {
maxIncreaseDay = 10 ;
}
document.getElementById('autoIncreaseDays').value = maxIncreaseDay ;
start_autoIncreaseDay = null ;
$('#app_next_day,#app_pre_day').addClass('disabled').css('color', '#aaa' );
}
function __unset_autoIncreaseDays(){
if( start_autoIncreaseDay ) {
document.getElementById('startdatepicker').value = start_autoIncreaseDay ;
start_autoIncreaseDay = null ;
}
$('#app_next_day,#app_pre_day').removeClass('disabled').css('color', '#000' );
}
function __date_format( date ) {
var y = date.getFullYear() ;
var m = date.getMonth() + 1 ;
var d = date.getDate() ;
if( m <= 9 ) {
m = '0' + String( m ) ;
} else {
m = String( m ) ;
}
if( d <= 9 ) {
d = '0' + String( d ) ;
} else {
d = String( d );
}
return String(y) + '-' + m + '-' + d ;
}
function __date_parse(txt){
var a = $.map(txt.replace(/^\D+/, '').replace(/\D$/, '' ).split(/\D+0?/) , function(i){
return parseInt(i) ;
}) ;
a[1] -= 1 ;
var date = new Date;
date.setFullYear( a[0] ) ;
date.setMonth( a[1] , a[2] ) ;
date.setDate( a[2] ) ;
return date ;
}
function __set_autoIncreaseDays() {
if( !start_autoIncreaseDay ) {
start_autoIncreaseDay = document.getElementById('startdatepicker').value ;
var date = __date_parse(start_autoIncreaseDay);
pools_autoIncreaseDay = new Array() ;
for(var i = 0 ; i < maxIncreaseDay ; i++) {
pools_autoIncreaseDay.push( __date_format(date) ) ;
date.setTime( date.getTime() + 3600 * 24 * 1000 ) ;
}
index_autoIncreaseDay = 1 ;
return ;
}
if( index_autoIncreaseDay >= pools_autoIncreaseDay.length ) {
index_autoIncreaseDay = 0 ;
}
var value = pools_autoIncreaseDay[index_autoIncreaseDay++];
document.getElementById('startdatepicker').value = value ;
}
function getTimeLimitValues(){
return $.map( [ $('#startTimeHFrom').val() , $('#startTimeMFrom').val(), $('#startTimeHTo').val(), $('#startTimeMTo').val() ] , function(val){
return parseInt(val) || 0 ;
}) ;
}
var isTicketAvailable = false;
var firstRemove = false;
window.$ && window.$(".obj:first").ajaxComplete(function() {
var _timeLimit = getTimeLimitValues();
$(this).find("tr").each(function(n, e) {
if(checkTickets(e, _timeLimit, n )){
isTicketAvailable = true;
highLightRow(e);
}
});
if(firstRemove) {
firstRemove = false;
if (isTicketAvailable) {
if (isAutoQueryEnabled)
document.getElementById("refreshButton").click();
onticketAvailable(); //report
}
else {
//wait for the button to become valid
}
}
}).ajaxError(function() {
if(isAutoQueryEnabled) doQuery();
});
//hack into the validQueryButton function to detect query
var _delayButton = window.delayButton;
window.delayButton = function() {
_delayButton();
if(isAutoQueryEnabled) doQuery();
}
//Trigger the button
var doQuery = function() {
displayQueryTimes(queryTimes++);
firstRemove = true;
__set_autoIncreaseDays();
document.getElementById(isStudentTicket ? "stu_submitQuery" : "submitQuery").click();
}
var $special = $("<input type='text' style='margin-top:-2px;width:200px' placeholder='逗号分隔多个车次,不限制则不填写' />")
//add by 冯岩 begin 2012-01-18
//modified by PeterPanZH 2013-01-24
var $specialOnly = $("<input type='checkbox' id='__chkspecialOnly' style='margin-top:-2px;cursor:pointer' /><label for='__chkspecialOnly' style='margin-right:10px;color: blue;cursor:pointer'>仅显示限定车次</label>");
var $includeCanOder = $("<input type='checkbox' id='__chkIncludeCanOder' style='margin-top:-2px;cursor:pointer' /><label for='__chkIncludeCanOder' style='color: blue;cursor:pointer'>显示可预定车次</label>");
//add by 冯岩 end 2012-01-18
var checkTickets = function(row, time_limit , row_index ) {
var hasTicket = false;
var v1 = $special.val();
var removeOther = $("#__chkspecialOnly").attr("checked");
var includeCanOder = $("#__chkIncludeCanOder").attr("checked");
if( v1 ) {
var v2 = $.trim( $(row).find(".base_txtdiv").text() );
if( v1.indexOf( v2 ) == -1 ) {
//add by 冯岩 begin 2012-01-18
if(removeOther)
{
if(v2 != "")
{
if(includeCanOder)
{
//包括其他可以预定的行
if($(row).find(".yuding_u").size() == 0)
{
$(row).remove();
}
}
else
{
$(row).remove();
}
}
}
//add by 冯岩 end 2012-01-18
return false;
}
}
if( $(row).find("td input.yuding_x[type=button]").length ) {
return false;
}
var cells = $(row).find("td") ;
if( cells.length < 5 ) {
return false ;
}
var _start_time = $.map( $(cells[1]).text().replace(/^\D+|\D+$/, '').split(/\D+0?/) , function(val){
return parseInt(val) || 0 ;
}) ;
while( _start_time.length > 2 ) {
_start_time.shift() ; // remove station name include number
}
if( _start_time[0] < time_limit[0] || _start_time[0] > time_limit[2] ) {
return false ;
}
if( _start_time[0] == time_limit[0] && _start_time[1] < time_limit[1] ){
return false ;
}
if( _start_time[0] == time_limit[2] && _start_time[1] > time_limit[3] ){
return false ;
}
cells.each(function(i, e) {
if(ticketType[i-1]) {
var info = $.trim($(e).text());
if(info != "--" && info != "无") {
hasTicket = true;
highLightCell(e);
}
}
});
return hasTicket;
}
var queryTimes = 0; //counter
var isAutoQueryEnabled = false; //enable flag
//please DIY:
var audio = null;
var onticketAvailable = function() {
if(window.Audio) {
if(!audio) {
audio = new Audio("http://panzihao.cn/msg.mp3");
audio.loop = true;
}
notify("可以订票了!", null, true, audio);
} else {
notify("可以订票了!");
}
}
var highLightRow = function(row) {
$(row).css("background-color", "#D1E1F1");
}
var highLightCell = function(cell) {
$(cell).css("background-color", "#2CC03E");
}
var displayQueryTimes = function(n) {
document.getElementById("refreshTimes").innerHTML = n;
};
var isStudentTicket = false;
//Control panel UI
var uiLeft = $("<div style='float:left;margin-left:30px'></div>")
.append(
$("<div id='timeFilter'>出发日期:<input id='autoIncreaseDays' type='text' value='1' maxLength=2 style='margin-top:-2px;width:18px;' /><label for='autoIncreaseDays'>天循环(最多10天) </label>出发时间:</div>")
)
.append(
$("<div>限定出发车次:</div>")
.append( $special )
.append( $specialOnly)
.append( $includeCanOder )
)
.append(
//Custom ticket type
$("<div>如果只需要刷特定的票种,请在余票信息下面勾选。 </div>")
.append($("<a href='#' style='color: blue;margin-right:10px'>只勾选坐票</a>").click(function() {
$(".hdr tr:eq(2) td").each(function(i,e) {
var val = (this.innerHTML.indexOf("座") != -1 && this.innerHTML.indexOf("无座") === -1);
var el = $(this).find("input").attr("checked", val);
el && el[0] && ( ticketType[el[0].ticketTypeId] = val );
if(el && el[0] && el[0].checked)
$(e).css("color", "#090").find("div").show();
else
$(e).css("color", "#055A78").find("div").hide();
});
return false;
}))
.append($("<a href='#' style='color: blue;margin-right:10px'>只勾选卧铺</a>").click(function() {
$(".hdr tr:eq(2) td").each(function(i,e) {
var val = this.innerHTML.indexOf("卧") != -1;
var el = $(this).find("input").attr("checked", val);
el && el[0] && ( ticketType[el[0].ticketTypeId] = val );
if(el && el[0] && el[0].checked)
$(e).css("color", "#090").find("div").show();
else
$(e).css("color", "#055A78").find("div").hide();
});
return false;
}))
.append($("<a href='#' style='color: blue;'>勾选全部</a>").click(function() {
$(".hdr tr:eq(2) td").each(function(i,e) {
var el = $(this).find("input").attr("checked", true);
el && el[0] && ( ticketType[el[0].ticketTypeId] = true );
if(el && el[0] && el[0].checked)
$(e).css("color", "#090").find("div").show();
});
return false;
}))
);
var uiRight = $("<div style='float:right;margin-right:10px;line-height:22px'></div>")
.append(
$("<button style='cursor:pointer;margin-left:-7px;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() {
if($("#fromStation").val() == "" || $("#toStation").val() == "") {
alert("请填写出发地和到达地!");
return;
}
if($("#fromStation").val() === $("#toStation").val()) {
alert("出发地和到达地不能相同!");
return;
}
if(!isAutoQueryEnabled) {
__reset_autoIncreaseDays() ;
isTicketAvailable = false;
if(audio && !audio.paused) audio.pause();
isAutoQueryEnabled = true;
queryTimes = 1;
doQuery();
this.innerHTML="停止刷票";
}
else {
__unset_autoIncreaseDays();
isAutoQueryEnabled = false;
this.innerHTML="开始刷票";
}
})
)
.append($("<br />"))
.append(
$("<span>").html("尝试次数:").append(
$("<span/>").attr("id", "refreshTimes").text("0")
)
)
.append($("<br />"));
$("<input id='isStudentTicket' type='checkbox' style='cursor:pointer;margin:-2px 5px 0 7px' />")
.change(function(){
isStudentTicket = this.checked ;
})
.appendTo(uiRight);
uiRight.append(
$("<label for='isStudentTicket' style='cursor:pointer'></label>").html("学生票")
);
var ui = $('<div style="margin-top:10px;padding-top:10px;border-top:1px solid #DBE6F4"></div>').append(uiLeft).append(uiRight);
var container = $("div.cx_form");
container.length ?
ui.appendTo(container) : ui.appendTo(document.body);
//$("#gridbox").height(260);
//前一日后一日UI修改
//by PeterPanZH 2013-01-24
$('#startdatepicker').parent("td").width(156);
$('#startdatepicker').width(75).css("margin", "0");
$('<a id="app_pre_day" style="margin:0 -2px 0 0"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAAsTAAALEwEAmpwYAAADD0lEQVRIx9WWP4skVRTFf6+qu2d3ZnYmGMV1EQWRNdJE/ABGLmxgYmSmqeBXEGO/gKmpgaAiuIGBYLTIgoGYCCsiIqzOzp+u6q737rvH4FV3V7c1ZhtYcOlX/arOuffcP6+CJJ7kVfGEr8lq8fEvfykECCGsNwVIQi5yFu6OWW8pk0bNSSnz2TuvhS0Cd/Hu8yfsKqbeXMWyRBa9CXMwgXm5r6vAR189+HcEOTu/Nc6FizAAXwGbQ5JIGbqs3mDZr5f9/3s1tCmPE5iL5Dve996u9mIPvAVuZb3MQgo00cYJokPnbCKQcCD3MqSs/hnxODoVoXjuBXyRQUE0cSQCS0500RmEsPHeB1onh8ed83fn3L4x4cfTxH4dWGRYGLS5ODROYLk8mLUlURa4Q2viNIrjCbx/+zone4F7v3fcvF7TmmizWJjIXCFRMmeRRbsh75MrzqIQcPfWlNdPyivzJC4NjnIBb0w0Bl6LxSCRG4KYWWZYmq/lOY/iIok3nplw59Yes6onlYgu5smZJ1hYIWizCFVNk8YiSLl4kYpEl0m8eFDzwcszTvYqBCQXrk1vnEXneBpoTOs8VJWQXRHBH0tx0an33jmahFKifQUNe9AcHp47tQKtqchrcOj95u4sislK85hYmpgF+PJhx9vfXvLJzwsa07pjk0N0WMSV9gW868t4OA6qYQRrglSkeuFGzeE08OEPDW/eO+fzXzuiF/1jFkpOY5sujl6KAh8h6JKXZCUxN5UqSSK5eOWpCadRvPf1GXe/OefBIyM5KJXSXA7A82q+7OagTUZrMLcyElI/GszLy4eTwEvPzbj/Z+LOp49469V9ZtPSyStg78fKMFlrgiZm9nPxvGi8TbT6ffqoJh5UfPHTgtmzM+LK695cV5wHTcwcWJEn5m2CTXILWHKob06xvmzXHquvNI1I1KRcOjIVSeJAouSbieqw5TFDQP3HidbGTF0H9q5VVA61i+n6INkcNKtGY5DLIe7xtcB8jGBpmfvffU9nTs5ekF2bkaoRT0c+GOY79+F//1XxD0ojDIJuG2hUAAAAAElFTkSuQmCC" alt="前一天" title="前一天" style="height:26px;margin:0 0 1px 0" /></a>').click(function() {
if( $(this).hasClass("disabled") ) {
return false ;
}
var date = __date_parse( document.getElementById('startdatepicker').value );
date.setTime( date.getTime() - 3600 * 24 * 1000 ) ;
document.getElementById('startdatepicker').value = __date_format(date) ;
return false;
}).insertBefore($('#startdatepicker'));
$('<a id="app_pre_day" style="margin:0 0 0 -2px"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAAsTAAALEwEAmpwYAAADGklEQVRIx9WWu44cRRSGv+ru3RnfsISNuaxYCJCcQ0JEwls4ggcgRSJ0jETCI4AckGCJJ0Ai4CZAIsBI5iIbIUBGrHanuqerzoWgqmd2x20yB7R0pOrpnv8/569z/urg7jzOq+ExX920ePfuAw8BQgibhw64O26OqmNmiNTISp4NI2floxuvhDMEZs6bh1fYVcxrmJdQd9Sp4YiBOIiV+7YJ3Pzkm4crUDXuRePYnHAKfAIWg+xOVhjVa8C6rtf190ULfdZ5AjEn2072NdvpWarAZ8ClrNfquAdiknmCZDAa2wrcMaAXpw2BrF7f8RJKydwK+KDgwYlppgLJRjJnFAhhm/1xdp47F7hzrHQEusBWEikVDAqDQK8lodMEmzYV0fKiOr04gziDOn+NxuvX9rhxuCAA96NxNFKei9MLxOysxInZicK8RFmsgG/JMYcopWueOdfw1vUlnz8Qbv0yskrGsm3I5vTqRCng1jrDqY3cEiRlrbAW28jjDiejl+4x6JrAq1c7Xn6y5dbPIx/8NNLgXOgCUQpRaFpiloclyllLFtnpcy03OyfJNu2a1Mnm7DWBN15a8uFrl7h+ueVeNFYCMRfpXB5Rwe9r53h03MHcMYf7K0MNrG68OhsSMfhncP44Ubou0AtcNMrQ7BKkLGV4pAC7O2YQxzqtTSHASyO8/8PAe9/1DINycKWjl9Jd+1b1natgIlADqZZwlIykTlfF/PjXxM1vI7/9mTi4tsDPh80UJysDic0QjNkY6h5InVxxOErO2uDHv5V3vlrx9d2RJ55qeeHZBWt1khTgXMF12rBdgj4LvcBKSsfkag0d8PYXkdvf93Cp4cXn90nmrLIjts1aN2ZYPWaXICblvJY/ZoNUCS7uB27fGTg82CNbmYukpbpsW3edbNf8EedBTMoFKROZdEuQzXn6akeUstZTwD4B+sa8aiPMSBSzlonMpeyJYHLRyVENzmTMaUD/jxOtT0rbBhbLhsagNWdvc5BspTDf4tgM7uVlYDVHsBbly08/YxRD1QqyVb+YUHcznflgWO3ch//9V8W/rpIU6waY0xMAAAAASUVORK5CYII=" alt="后一天" title="后一天" style="height:26px;margin:0 0 1px 0" /></a>').click(function() {
if( $(this).hasClass("disabled") ) {
return false ;
}
var date = __date_parse( document.getElementById('startdatepicker').value );
date.setTime( date.getTime() + 3600 * 24 * 1000 ) ;
document.getElementById('startdatepicker').value = __date_format(date) ;
return false;
}).insertAfter($('#startdatepicker'));
setTimeout(function(){
var box = $('<span style="width:100px;height:18px;line-height:18px;font-size:12px;padding:0px;overflow:hidden;"></span>') ;
function makeSelect(id, max_value, default_value){
var element = $('<select id="' + id + '" style="margin:-2px 0 0 -1px;padding:0px;font-size:12px; line-height:100%; "></select>') ;
for(var i = 0; i <= max_value ; i++) {
element.append(
$('<option value="' + i + '" style="padding:0px;margin:0px;font-size:12px; line-height:100%;" ' + ( default_value == i ? ' selected="selected" ' : '' ) + '>' + ( i <= 9 ? '0' + i : i ) + '</option>' )
)
}
box.append(
$('<span style="padding:0px;overflow:hidden;"></span>') .append(element)
);
return element ;
}
function check(evt){
var tl = getTimeLimitValues() ;
if( tl[0] > tl[2] || (tl[0] == tl[2] && tl[1] > tl[3]) ) {
alert('最早发车时间必须早于最晚发车时间,请重新选择!') ;
return false ;
}
}
makeSelect('startTimeHFrom' , 23 ).change(check) ;
box.append( $('<span>:</span>')) ;
makeSelect('startTimeMFrom' , 59 ).change(check) ;
box.append( $('<span> -- </span>')) ;
makeSelect('startTimeHTo' , 23, 23 ).change(check) ;
box.append( $('<span>:</span>')) ;
makeSelect('startTimeMTo' , 59, 59 ).change(check) ;
box.appendTo( $('#timeFilter') )
}, 10 ) ;
//Ticket type selector & UI
var ticketType = new Array();
var checkbox_list = new Array();
$(".hdr tr:eq(2) td").each(function(i,e) {
ticketType.push(false);
if(i<3) return;
ticketType[i] = true;
$(e).html('<label for="ticketType' + String(i) + '" style="cursor:pointer">' + $(e).text() + '</label>').css("color", "#090").css("position", "relative").prepend('<div style="width:10px;height:10px;position:absolute;float:left;margin:-5px 0 0 0;padding:0;"><img style="width:10px;height:10px;margin:0;" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAKTWlDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVN3WJP3Fj7f92UPVkLY8LGXbIEAIiOsCMgQWaIQkgBhhBASQMWFiApWFBURnEhVxILVCkidiOKgKLhnQYqIWotVXDjuH9yntX167+3t+9f7vOec5/zOec8PgBESJpHmomoAOV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z8p+Vv9563Or59/94vtLz1j82PAL+YvPv655qfNy76uprzrHI8cfvM55PfGm/K3O233vuO+638e9H5ko/ED+UPPR+mPHp9BP9z7nfP78L/eE8/sl0p8zAAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1MAAA6mAAADqYAAAXb5JfxUYAAACSSURBVHjajNAxDgFhFATgb0WiUqglCjcgew8tlUZcQaNWKBRahQs4gMIRtkFBnEBFnODX/GTDkp3k5WXyJjN5k4QQlEEV0jQturUwwibLskPlj0kPE7Thl7CBJa44vqPRRB3nyHdxd3DLOy5wwhwDdDF+ifKOM1wwjXyL1dfX2MepYYh+YT05rHHH41OYlC38OQDtiR0Ul0tWlAAAAABJRU5ErkJggg==" /></div>');
var c = $("<input/>").attr("type", "checkBox").attr("checked", true).attr("id", "ticketType" + String(i)).hide();
c[0].ticketTypeId = i;
c.change(function() {
ticketType[this.ticketTypeId] = this.checked;
if(this.checked)
$(this).parent("td").css("color", "#090").find("div").show();
else
$(this).parent("td").css("color", "#055A78").find("div").hide();
}).appendTo(e);
checkbox_list.push(c);
});
$.each([1, 2], function(){
var c = checkbox_list.pop() ;
c[0].checked = false ;
c.parent("td").css("color", "#055A78").find("div").hide();
ticketType[ c[0].ticketTypeId ] = this.checked ;
});
delete checkbox_list ;
}
route("querySingleAction.do", query);
route("myOrderAction.do?method=resign", query);
route("confirmPassengerResignAction.do?method=cancelOrderToQuery", query);
route("loginAction.do?method=init", function() {
return;
if( !window.location.href.match( /init$/i ) ) {
return;
}
//login
var url = "https://dynamic.12306.cn/otsweb/loginAction.do?method=login";
var queryurl = "https://dynamic.12306.cn/otsweb/order/querySingleAction.do?method=init";
//Check had login, redirect to query url
if( window.parent && window.parent.$ ) {
var str = window.parent.$("#username_ a").attr("href");
if( str && str.indexOf("sysuser/user_info") != -1 ){
window.location.href = queryurl;
return;
}
}
function submitForm(){
var submitUrl = url;
$.ajax({
type: "POST",
url: submitUrl,
data: {
"loginUser.user_name": $("#UserName").val()
, "user.password": $("#password").val()
, "randCode": $("#randCode").val()
},
beforeSend: function( xhr ) {
try{
xhr.setRequestHeader('X-Requested-With', {toString: function(){ return ''; }});
xhr.setRequestHeader('Cache-Control', 'max-age=0');
xhr.setRequestHeader('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8');
}catch(e){};
},
timeout: 30000,
//cache: false,
//async: false,
success: function(msg){
//密码输入错误
//您的用户已经被锁定
if ( msg.indexOf('请输入正确的验证码') > -1 ) {
alert('请输入正确的验证码!');
} else if ( msg.indexOf('当前访问用户过多') > -1 ){
reLogin();
} else if( msg.match(/var\s+isLogin\s*=\s*true/i) ) {
notify('登录成功,开始查询车票吧!');
window.location.replace( queryurl );
} else {
msg = msg.match(/var\s+message\s*=\s*"([^"]*)/);
if( msg && msg[1] ) {
alert( msg && msg[1] );
} else {
reLogin();
}
}
},
error: function(msg){
reLogin();
}
});
}
var count = 1;
function reLogin(){
count ++;
$('#refreshButton').html("("+count+")次登录中...");
setTimeout(submitForm, 2000);
}
//初始化
$("#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() {
count = 1;
$(this).html("(1)次登录中...");
//notify('开始尝试登录,请耐心等待!', 4000);
submitForm();
return false;
}));
alert('如果使用自动登录功能,请输入用户名、密码及验证码后,点击自动登录,系统会尝试登录,直至成功!');
});
//route("confirmPassengerAction.do", submit);
//route("confirmPassengerResignAction.do", submit);
function submit() {
/**
* Auto Submit Order
* From: https://gist.github.com/1577671
* Author: [email protected]
*/
//Auto select the first user when not selected
if( !$("input._checkbox_class:checked").length ) {
try{
//Will failed in IE
$("input._checkbox_class:first").click();
}catch(e){};
}
//passengerTickets
var userInfoUrl = 'https://dynamic.12306.cn/otsweb/order/myOrderAction.do?method=queryMyOrderNotComplete&leftmenu=Y';
var count = 1, freq = 1000, doing = false, timer, $msg = $("<div style='padding-left:470px;'></div>");
function submitForm(){
timer = null;
//更改提交列车日期参数
//var wantDate = $("#startdatepicker").val();
//$("#start_date").val(wantDate);
//$("#_train_date_str").val(wantDate);
jQuery.ajax({
url: $("#confirmPassenger").attr('action'),
data: $('#confirmPassenger').serialize(),
beforeSend: function( xhr ) {
try{
xhr.setRequestHeader('X-Requested-With', {toString: function(){ return ''; }});
xhr.setRequestHeader('Cache-Control', 'max-age=0');
xhr.setRequestHeader('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8');
}catch(e){};
},
type: "POST",
timeout: 30000,
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!
var audio;
if( window.Audio ) {
audio = new Audio("http://panzihao.cn/msg.mp3");
audio.loop = true;
notify("恭喜,车票预订成!", null, true, audio);
}
else {
notify("恭喜,车票预订成!", null, true);
}
setTimeout(function() {
if( confirm("车票预订成,去付款?") ){
window.location.replace(userInfoUrl);
} else {
if(audio && !audio.paused) audio.pause();
}
}, 100);
return;
}else if(msg.indexOf('未处理的订单') > -1){
notify("有未处理的订单!");
window.location.replace(userInfoUrl);
return;
}
var reTryMessage = [
'用户过多'
, '确认客票的状态后再尝试后续操作'
, '请不要重复提交'
, '没有足够的票!'
, '车次不开行'
];
for (var i = reTryMessage.length - 1; i >= 0; i--) {
if( msg.indexOf( reTryMessage[i] ) > -1 ) {
reSubmitForm( reTryMessage[i] );
return;
}
};
// 铁道部修改验证码规则后 update by 冯岩
if( msg.indexOf( "输入的验证码不正确" ) > -1 ) {
$("#img_rrand_code").click();
$("#rand").focus().select();
stop();
return;
}
//Parse error message
msg = msg.match(/var\s+message\s*=\s*"([^"]*)/);
stop(msg && msg[1] || '出错了。。。。 啥错? 我也不知道。。。。。');
},
error: function(msg){
reSubmitForm("网络错误");
}
});
};
function reSubmitForm(msg){
if( !doing )return;
count ++;
$msg.html("("+count+")次自动提交中... " + (msg || ""));
timer = setTimeout( submitForm, freq || 50 );
}
function stop ( msg ) {
doing = false;
$msg.html("("+count+")次 已停止");
$('#refreshButton').html("自动提交订单");
timer && clearTimeout( timer );
msg && alert( msg );
}
function reloadSeat(){
$("select[name$='_seat']").html('<option value="M" selected="">一等座</option><option value="O" selected="">二等座</option><option value="1">硬座</option><option value="3">硬卧</option><option value="4">软卧</option>');
}
//初始化
if($("#refreshButton").size()<1){
// //重置后加载所有席别
// $("select[name$='_seat']").each(function(){this.blur(function(){
// alert(this.attr("id") + "blur");
// })});
////初始化所有席别
//$(".qr_box :checkbox[name^='checkbox']").each(function(){$(this).click(reloadSeat)});
//reloadSeat();
//日期可选
$("td.bluetext:first").html('<input type="text" name="orderRequest.train_date" value="' +$("#start_date").val()+'" id="startdatepicker" style="width: 150px;" class="input_20txt" onfocus="WdatePicker({firstDayOfWeek:1})" />');
$("#start_date").remove();
$(".tj_btn").append($("<a 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);'></a>").attr("id", "refreshButton").html("自动提交订单").click(function() {
//alert('开始自动提交订单,请点确定后耐心等待!');
if( this.innerHTML.indexOf("自动提交订单") == -1 ){
//doing
stop();
} else {
if( window.submit_form_check && !window.submit_form_check("confirmPassenger") ) {
return;
}
count = 0;
doing = true;
this.innerHTML = "停止自动提交";
reSubmitForm();
}
return false;
}));
$(".tj_btn").append("自动提交频率:")
.append($("<select id='freq'><option value='50' >频繁</option><option value='500' selected='' >正常</option><option value='2000' >缓慢</option></select>").change(function() {
freq = parseInt( $(this).val() );
}))
.append($msg);
//alert('如果使用自动提交订单功能,请在确认订单正确无误后,再点击自动提交按钮!');
//铁道路修改验证码规则后 优化 by 冯岩
$("#rand").bind('keydown', function (e) {
var key = e.which;
if (key == 13) {
$("#refreshButton").click();
}
});
}
};
}, true);