-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetC.js
123 lines (101 loc) · 3.2 KB
/
getC.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
var itr;
var retryTime = 3000;
var helperObj;
var settings = {
"YZ": "硬座",
"RZ": "软座",
"YW": "硬卧",
"RW": "软卧",
"ZE": "二等座",
"ZY": "一等座"
};
function gogogo() {
var condition = $("#helper .trainNum .btn-success");
if(condition.size() == 0) {
alert("车次或者日期未填写");
return;
}
var seatTypeS = $("#helper .seatType .btn-success");
if(seatTypeS.size() == 0) {
alert("座位类型未填写");
return;
}
clearInterval(itr);
itr = setInterval(function(){
condition.each(function(i, obj){
superCheck(obj.innerText);
});
$("#query_ticket").trigger("click");
},retryTime);
}
function makeDiv() {
if($("#helper").size() > 0) {
helperObj = $("#helper");
} else {
// bootstrap
$("head").append("<link rel='stylesheet' type='text/css' href='//apps.bdimg.com/libs/todc-bootstrap/3.1.1-3.2.1/todc-bootstrap.min.css'>")
helperObj = $("<div id='helper'></div>");
$("body").append(helperObj);
helperObj.css({
position:"fixed",
left: 0,
top: 0,
height: "240px",
width: "500px",
background: "skyblue",
zIndex: 999999
});
}
helperObj.empty();
var checkboxArr = $("<div class='checkbox trainNum' style='overflow: hidden; margin-bottom: 40px;'></div>");
$("tr .number").each(function(i, obj){
checkboxArr.append("<span style='float: left; margin: 10px 0 0 10px' class='btn btn-default'>" + obj.innerText + "</span>");
});
helperObj.append(checkboxArr);
var seatTyptArr = $("<div class='checkbox seatType' style='overflow: hidden; margin-bottom: 40px;'></div>");
for(var key in settings) {
seatTyptArr.append("<span style='float: left; margin: 10px 0 0 10px' id='" + key + "' class='btn btn-default'>" + settings[key] + "</span>");
}
helperObj.append(seatTyptArr);
helperObj.append("<button onclick='gogogo()' style='width: 100%' class='btn btn-primary'>开抢</button>");
helperObj.find(".checkbox .btn").on("click", function(){
$(this).toggleClass("btn-success");
});
}
function superCheck(trainNum) {
var targets = $("tr .number:contains(" + trainNum + ")").parents("tr");
var seats = targets.find(".t-num,.yes");
seats.each(function(i, obj){
for(var key in settings) {
if(obj.id.indexOf(key) != -1 && $("#" + key).hasClass("btn-success")) {
notifyMe(trainNum , settings[key]);
}
}
})
}
makeDiv();
function notifyMe(trainNum, type) {
clearInterval(itr);
var msg = trainNum + "..." + type;
console.log(msg);
var options = {
tag: "heroqzs",
icon: "http://img.weiyangx.com/2015/11/717A643A7635F4365EFB4EE9784E10E5.jpg"
}
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
}
else if (Notification.permission === "granted") {
var notification = new Notification(msg, options);
}
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
if (permission === "granted") {
var notification = new Notification(msg, options);
}
});
}
var yudingBtn = $("tr .number:contains(" + trainNum + ")").parents("tr").find("td:last-child a");
console.log(yudingBtn);
yudingBtn.trigger("click");
}