forked from diw1/TI-tickets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrab.js
98 lines (93 loc) · 3.18 KB
/
grab.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
const addCode = function(code) {
try {
console.log(`###添加特权码:${code}###`);
document.querySelector("#privilege_val").value = code;
sleep(400).then(() => {
document.getElementsByClassName("privilege_sub")[0].click();
});
} catch (e) {
console.log(e);
}
};
sleep = ms => {
return new Promise(resolve => setTimeout(resolve, ms));
};
const confirm = function() {
console.log("###开始确认订单###");
const url = chrome.runtime.getURL("user.json");
fetch(url)
.then(response => response.json()) //assuming file contains json
.then(item => {
console.log("###选择购票人###");
document.getElementsByClassName("next-checkbox")[0].children[1].click(); //默认勾选首位购票人
sleep(1000).then(() => {
document.getElementsByClassName("express")[0].click(); // 选择自取
sleep(2000).then(() => {
if (document.title === "确认订单") {
console.log("###选择购票人###");
if (
!document
.getElementsByClassName("next-checkbox")[0]
.classList.contains("checked")
) {
document
.getElementsByClassName("next-checkbox")[0]
.children[1].click(); //默认勾选首位购票人
}
//document.getElementsByClassName('next-checkbox')[0].children[1].click() //默认勾选首位购票人
sleep(500).then(() => {
console.log("###确认购买###");
document
.getElementsByClassName("submit-wrapper")[0]
.children[0].click();
});
}
});
//}
});
});
};
const grab = function() {
const url = chrome.runtime.getURL("user.json");
fetch(url)
.then(response => response.json()) //assuming file contains json
.then(item => {
console.log(item);
console.log("###开始抢票###");
addCode(item.code);
console.log(`###选择场次:${item.series}###`);
document
.getElementsByClassName("select_right_list_item")
[item.series - 1].click();
sleep(1000).then(() => {
const button = document.getElementsByClassName("buybtn")[0];
if (button.textContent === "即将开抢") {
console.log("###抢票未开始,刷新页面###");
setTimeout(() => {
window.location.reload();
}, 1000);
} else {
if (item.quantity === 2) {
console.log("###增加一张票,选两张###");
document
.getElementsByClassName("cafe-c-input-number-handler-up")[0]
.click();
sleep(300).then(() => {
console.log("###跳转到确认订单页面###");
document.getElementsByClassName("buybtn")[0].click();
});
} else {
console.log("###跳转到确认订单页面###");
document.getElementsByClassName("buybtn")[0].click();
}
}
sleep(1000).then(() => {
if (document.title === "确认订单") {
console.log("###确认订单###");
confirm();
}
});
});
});
};
grab();