-
Notifications
You must be signed in to change notification settings - Fork 15
/
checking-in.js
182 lines (168 loc) · 4.77 KB
/
checking-in.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
/**
* 检查无障碍服务是否已经启用
* auto.waitFor()则会在在无障碍服务启动后继续运行
* https://docs.hamibot.com/reference/widgetsBasedAutomation
*/
const { chanUrl, barkUrl, stepInterval,awakeningDelayTime, quickChecking, checkingTime } =
hamibot.env
auto.waitFor()
// 唤醒设备并解锁
// home()
device.wakeUp()
let { height, width } = device
let x = width / 2
let y1 = (height / 3) * 2
let y2 = height / 3
swipe(x, y1, x + 5, y2, 500)
sleep(awakeningDelayTime)
toastLog('拉起企业微信,准备打卡。。。')
app.launch("com.tencent.wework");
let quick = false
if (quickChecking == 1 || quickChecking == '1') {
quick = quickChecking * 1 == 1
let checkingHour = checkingTime.split(':')[0]
let checkingMin = checkingTime.split(':')[1]
let currentHour = new Date().getHours()
let currentMin = new Date().getMinutes()
if (currentHour > checkingHour * 1) {
// 迟到或者下班卡
quick = false
} else if (currentMin <= checkingMin * 1 && quick) {
quick = true
} else {
// 迟到或者下班卡
quick = false
}
}
if (quick) {
check()
} else {
// 切换到 工作台
stepClick('工作台')
// 切换到打卡页
stepClick('打卡')
}
function stepClick(matchStr) {
console.log('正在匹配 --- ', matchStr)
sleep(stepInterval)
let step = text(matchStr).findOne(1000)
if (step) {
console.log('匹配成功')
// let stepLeft = step.bounds().left + 15
// let stepTop = step.bounds().top + 10
// console.log(stepLeft, stepTop)
if (matchStr !== '打卡') {
// click(stepLeft, stepTop)
while (!click(matchStr));
} else {
while (!click('打卡'));
sleep(stepInterval)
signAction()
}
} else if (matchStr == '打卡') {
console.log('滑动屏幕再次匹配')
let { height, width } = device
let x = width / 2
let y1 = (height / 3) * 2
let y2 = height / 3
let swipeResult = swipe(x, y1, x + 5, y2, 500)
if (swipeResult) {
sleep(stepInterval / 2)
stepClick(matchStr)
}
} else {
console.log('匹配失败,后退再次匹配')
back()
sleep(stepInterval)
stepClick(matchStr)
}
}
// 打卡
function signAction() {
toastLog('signAction 开始执行')
let signIn = text('上班打卡').findOne(1000)
let signOut = text('下班打卡').findOne(1000)
if (signIn) {
let stepLeft = signIn.bounds().left + 10
let stepTop = signIn.bounds().top + 10
click(stepLeft, stepTop)
check()
} else if (signOut) {
let stepLeft = signOut.bounds().left + 10
let stepTop = signOut.bounds().top + 10
click(stepLeft, stepTop)
check()
} else {
toastLog('打卡未完成,正在检查打卡状态')
check()
}
}
// 判断打卡是否完成
function check() {
sleep(stepInterval)
let msg = ''
let flagIn =
textEndsWith('上班·正常').findOne(1000) ||
textStartsWith('上班自动打卡·正常').findOne(1000)
let flagIn2 = textStartsWith('迟到打卡').findOne(1000)
let flagOut =
textEndsWith('下班·正常').findOne(1000) ||
textStartsWith('今日打卡已完成').findOne(1000)
let flagInAdvance =
textStartsWith('你早退了').findOne(1000) &&
textEndsWith('确认打卡').findOne(1000)
if (flagIn) {
toastLog('打卡完成')
msg = '上班打卡成功'
} else if (flagIn2) {
toastLog('打卡完成')
msg = '迟到打卡 完成'
} else if (flagOut) {
toastLog('打卡完成')
msg = '下班打卡成功'
} else if (flagInAdvance) {
toastLog('已经打过上班卡了!')
msg = '已经打过上班卡了!'
} else {
toastLog('打卡失败!')
msg = '打卡失败!'
}
let dd = new Date()
let years = dd.getFullYear()
let mouths = dd.getMonth() + 1
let days = dd.getDate()
let hours = dd.getHours()
let minutes = dd.getMinutes()
mouths = mouths < 10 ? '0' + mouths : mouths
days = days < 10 ? '0' + days : days
hours = hours < 10 ? '0' + hours : hours
minutes = minutes < 10 ? '0' + minutes : minutes
let formatDate =
years + '-' + mouths + '-' + days + ' ' + hours + ':' + minutes
if (chanUrl && chanUrl.trim() !== '') {
let url = chanUrl + '?text=' + msg + formatDate
http.get(url)
}
if (barkUrl && barkUrl.trim() !== '') {
let url = barkUrl + msg + '/' + formatDate
http.get(url)
}
hamibot.postMessage(formatDate + ' ' + msg)
hamibot.exit()
}
// ----------------------------------------
// 下面是第一版
// ----------------------------------------
// sleep(1000)
// while (!click('工作台'));
// console.log('切换到工作台')
// sleep(1000)
// while (!click('打卡'));
// console.log('切换到打卡')
// sleep(1000)
// while (!click('班打卡')) sleep(1000)
// if (text('打卡成功').findOne()) {
// toastLog('打卡成功')
// } else {
// toastLog('打卡失败')
// }