forked from cehui0303/Tmall_Tickets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
maotai.js
137 lines (83 loc) · 2.15 KB
/
maotai.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
//定时器
var timer = null;
//检测状态
function checkElementState(path,callback){
var ele = document.querySelector(path);
if(ele){
callback && callback();
}else{
console.log('异步加载元素中....' + path );
setTimeout( function(){checkElementState(path,callback);},200);
}
}
//点击购买按钮
function clickBuy(){
console.log('买!');
//票的数量 如果还不可以购买,这个地方获取会失败
var amount = document.getElementsByClassName('mui-amount-increase')[0];
amount && amount.click(); //+1
var btnBuy = document.querySelector('');
}
//结算
function checkOut(){
console.log('结算开始....');
var btn = document.getElementById('J_Go');
if(btn){
btn.click();
}else{
console.log('结算按钮没找到');
}
}
function checkOutAsync(){
checkElementState('#J_Go',checkOut);
}
//提交订单
function submitOrder(){
console.log('提交订单开始....');
checkElementState('.go-btn',function(){
var btn = document.querySelector(".go-btn");
if(btn){
btn.click();
}else{
console.log('提交订单按钮没找到');
}
});
}
//目标时间
var dDate = new Date(); //10点和20点开抢
if( dDate.getHours() < 10 ){
dDate.setHours(9,59,59.2);
}else{
dDate.setHours(19,59,59.2);
}
//dDate.setSeconds( dDate.getSeconds() + 10 );
//进入时间判断循环
function enterTimeCheckLoop(callback){
var date = new Date();
var diff = Date.parse(dDate) - Date.parse(date) ;
console.log(diff);
if(diff < - 900 ){
console.log('时间过了!');
}else if(diff < 500 ) {
callback && callback();
console.log('时间到了!!!');
}else{
setTimeout(function(){ enterTimeCheckLoop(callback);},400);
//console.log('--');
}
}
//主要函数
function main(){
console.log('############################开始抢购茅台############################');
//debugger;
var href = window.location.href;
if(href.indexOf('cart.tmall.com') > -1 ){
//结算页面
//进入时间判断
enterTimeCheckLoop( checkOutAsync );
}else if(href.indexOf('buy.tmall.com') > -1 ){
//提交订单页面
submitOrder();
}
}
main();