forked from MonsterNone/tmall-miao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.js
184 lines (159 loc) · 5.19 KB
/
start.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
if (!auto.service) {
toast('无障碍服务未启动!退出!')
exit()
}
console.show()
console.log('开始完成喵币任务...')
console.log('按音量下键停止')
device.keepScreenDim(60 * 60 * 1000)
function registerKey() {
events.observeKey()
events.onKeyDown('volume_down', function (event) {
console.log('喵币任务脚本停止了')
console.log('请手动切换回主页面')
device.cancelKeepingAwake()
exit()
})
}
threads.start(registerKey)
// 自定义一个findTimeout,find_f是原本的查询器 text('sss').find()
function findTimeout(findF, timeout) {
function findSth() {
result = findF.find()
if (result.nonEmpty()) {
return
}
sleep(50)
findSth()
}
var result
var thread = threads.start(findSth)
thread.join(timeout)
return result.nonEmpty() ? result : null
}
// 查找任务按钮
function findTask() {
var jumpButtonFind = textMatches(/去浏览|去搜索|去完成|签到|逛一逛|去逛逛/) // 找进入任务的按钮,10秒
var jumpButtons = findTimeout(jumpButtonFind, 10000)
if (!jumpButtons) {
return null
}
for (var i = 0; i < jumpButtons.length; i++) {
var taskName, content
try {
taskName = jumpButtons[i].parent().child(0).child(0).text()
content = jumpButtons[i].parent().child(0).child(1).child(0).text()
} catch (err) {
continue
}
if (taskName) {
if (taskName.match(/签到/)) {
console.log('进行“签到”任务')
sleep(1000)
jumpButtons[i].click()
sleep(8000)
return findTask()
}
if (!(taskName.match(/邀请|登录|组队|参与|施肥|浇水|特价版|小鸡|消除|合伙/) || content.match(/小互动/))) {
return [taskName, jumpButtons[i]]
}
}
}
return null
}
function liulan() {
if (textMatches(/.*浏览.*/).findOne(10000)) { // 等待浏览出现
let v = className('android.support.v7.widget.RecyclerView').findOnce() // 滑动
if (v) {
sleep(1000)
v.scrollForward()
}
}
sleep(5000) // 等待15秒
let finish_c = 0
while (finish_c < 100) { // 0.5 * 100 = 50 秒,防止死循环
if (
textMatches(/.*完成.*|.*失败.*|.*上限.*|.*开小差.*|.*休息会呗.*/).exists() || ! text("浏览15秒").exists()) // 等待已完成出现,有可能失败
break
sleep(500)
finish_c++
}
if (finish_c > 99) {
console.log('未检测到任务完成标识。退出。')
console.log('如果你认为这是一个bug请截图反馈。')
console.log('请手动切换回主页面')
device.cancelKeepingAwake()
exit()
}
console.log('任务完成,返回')
if (currentActivity() == 'com.taobao.tao.TBMainActivity') {
var backButton = descContains('返回618列车').findOnce() // 有可能是浏览首页,有可能无法点击
if (backButton) {
if (!backButton.parent().parent().parent().click()) {
back()
}
} else {
back()
}
} else {
back()
}
}
// 打开淘宝活动页面
console.log('正在打开淘宝...')
var url = 'pages.tmall.com/wow/z/hdwk/20210618/singlegame'
app.startActivity({
action: "VIEW",
data: "taobao://" + url
})
sleep(2000)
console.log('等待页面加载...')
try {
text('领喵币').findOne(20000)
console.log('准备打开任务列表')
sleep(5000)
text('领喵币').findOnce().click()
} catch (err) {
console.log(err)
console.log('无法进入任务列表,可能是淘宝更新了页面逻辑,请反馈')
exit()
}
while (true) {
console.log('寻找任务入口...')
var jumpButton = findTask()
if (jumpButton == null) {
// 没有任务之后领取奖励
var awardButtonFind = textMatches(/领取奖励/)
var awardButtons = findTimeout(awardButtonFind, 10000)
if (awardButtons) {
for (var i = 0; i < awardButtons.length; i++) {
console.log('领取累计任务奖励')
awardButtons[i].click()
console.log('等待5秒再次领取...')
sleep(5000)
}
}
console.log('没找到合适的任务。也许任务已经全部做完了。退出。')
console.log('请手动切换回主页面')
device.cancelKeepingAwake()
alert('别忘了在脚本主页领取618红包!')
exit()
}
if (jumpButton[0].match('去浏览店铺领喵币')) {
console.log('进行浏览店铺任务')
jumpButton[1].click()
while (!textContains('任务完成').exists()) {
console.log('进入店铺浏览')
text('逛店最多').findOne(15000).parent().click()
liulan()
sleep(5000)
}
back()
} else {
console.log('进行' + jumpButton[0] + '任务')
jumpButton[1].click()
liulan()
}
console.log('等待页面刷新...')
sleep(5000)
}