-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path微博日常任务.js
453 lines (407 loc) · 14.9 KB
/
微博日常任务.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
/**
* 刷微博
* 1080 * 2340
* */
let singleSleep = 3;
let step = {
hall2Task: () => {
clickId('redpacketSave')
sleep(3000)
// 去掉积分提示的弹窗
if(textStartsWith('连续签到第').findOnce() != null){
log(clickTar(textStartsWith('连续签到第').findOnce().parent().child(2)))
}
var args = randSwipeArg(1800, 1800);
swipe(args[0], args[1], args[2], args[3], args[4])
sleep(1000)
},
reEnterTask: () => {
clickId('titleLeft')
sleep(500)
step.hall2Task();
},
myWeiBo: () => {
desc('我').findOnce().click()
sleep(1000)
clickTar(text('微博').findOnce())
sleep(2000)
}
}
let doTask = {
关注: () => {
let btn = className('android.widget.Button').text('关注').findOnce();
if(btn == null){
toastLog('任务不存在')
return;
}
btn.click()
sleep(singleSleep * 1000);
let q = 5;
while(--q >= 0 && Guanzhu()){
toastLog(fmt('完成第%s个,休眠%s秒', q, singleSleep))
sleep(singleSleep * 1000);
}
clickId('com.sina.weibo:id/rltitleBack')
},
转发: () => {
let btn = className('android.widget.Button').text('转发').findOnce();
if(btn == null){
toastLog('任务不存在')
return;
}
btn.click()
sleep(singleSleep * 1000);
let q = 2;
while(--q >= 0 && Zhuanfa()){
toastLog(fmt('完成第%s个,休眠%s秒', q, singleSleep))
sleep(singleSleep * 1000);
var args = randSwipeArg(1600, 2000);
swipe(args[0], args[1], args[2], args[3], args[4])
sleep(2000);
}
clickId('com.sina.weibo:id/rltitleBack')
},
评论: () => {
let btn = className('android.widget.Button').text('评论').findOnce();
if(btn == null){
toastLog('任务不存在')
return;
}
btn.click()
sleep(singleSleep * 1000);
let q = 2;
while(--q >= 0 && Pinglun()){
toastLog(fmt('完成第%s个,休眠%s秒', q, singleSleep))
sleep(singleSleep * 1000);
var args = randSwipeArg(1600, 2000);
swipe(args[0], args[1], args[2], args[3], args[4])
sleep(2000);
}
clickId('com.sina.weibo:id/rltitleBack')
},
发微博: () => {
let btn = className('android.widget.Button').text('发微博').findOnce();
if(btn == null){
toastLog('任务不存在')
return;
}
btn.click()
sleep(singleSleep * 1000);
let q = 1;
while(--q >= 0 && Faweibo()){
toastLog(fmt('完成第%s个,休眠%s秒', q, singleSleep))
sleep(singleSleep * 1000);
}
clickId('com.sina.weibo:id/rltitleBack')
},
刷微博: () => {
// clickId('titlebarTabView_hot')
// sleep(3000)
// clickId('com.sina.weibo:id/iv_close')
var i = 0, validCount = 0;
while(true){
++i;
var args = randSwipeArg();
swipe(args[0], args[1], args[2], args[3], args[4])
let process = getProcess();
toastLog(fmt('第%s次滑动:[%s,%s] => [%s,%s]: %s', i, args[0], args[1], args[2], args[3], process))
sleep(2000)
if(process === '没有'){
if(!clickId('complete_rp_iv') && (++validCount > 7)){
toastLog('图标不在了 程序退出')
break;
}
}else{
validCount = 0;
}
}
sleep(2000)
},
collect: () => {
while(className('android.widget.Button').textEndsWith('积分').find().size() > 0){
let cur = className('android.widget.Button').textEndsWith('积分').findOnce()
log(cur.text())
cur.click();
sleep(4000)
}
},
clear: () => {
step.myWeiBo();
let q = 0;
while(true){
// 删除单条
if(!id('contentTextView').exists()){ break; }
let contentDesc = id('contentTextView').findOnce().contentDescription.toString();
let exe = contentDesc.indexOf('TestWeibo:') > -1 || contentDesc.indexOf('Waiting For Delete') > -1;
if(!exe){ break; }
clickId('contentTextView')
sleep(2000)
clickId('com.sina.weibo:id/detail_activity_header_right_button')
sleep(1000)
clickTar(className('android.widget.TextView').text('删除').findOnce())
sleep(300)
clickTar(text('确定'))
sleep(1000)
q++;
// 刷新
clickId('titleSave')
sleep(1000)
clickTar(text('刷新').findOnce())
sleep(3000)
}
toastLog('清理完成')
clickId('com.sina.weibo:id/titleBack')
sleep(1000)
desc('首页').findOnce().click()
},
start: () => {
auto()
toastLog(fmt("设备尺寸:%s*%s \n手机型号:%s \n安卓版本:%s", device.width, device.height, device.model, device.release));
app.launchApp("微博");
sleep(1000);
clickTar(text('跳过').findOnce())
sleep(1000);
step.hall2Task();
doTask.关注();
sleep(1000)
doTask.转发();
sleep(1000)
doTask.评论();
sleep(1000)
doTask.发微博();
sleep(1000)
step.reEnterTask()
doTask.collect();
clickId('titleLeft')
sleep(1000)
doTask.clear();
toastLog('日常任务已完成,开始刷微博')
doTask.刷微博()
sleep(500)
}
}
doTask.start()
function Faweibo() {
toastLog("已尝试点击“发微博”任务按钮");
sleep(1000);
while (text("加载中").findOnce() != null) {
toastLog("正在等待“发微博”加载……");
sleep(2000);
}
if (id("com.sina.weibo:id/titleText").findOnce() != null) {
if (id("com.sina.weibo:id/titleText").findOnce().text() == "发微博") {
toastLog("已处于“发微博”页面");
sleep(2000);
if (Sendtime == null) {
var Sendtime = 1;
} else {
Sendtime++;
}
setText("TestWeibo:" + Sendtime);
sleep(1000);
if (id("com.sina.weibo:id/titleSave").findOnce() != null) {
var FS = id("com.sina.weibo:id/titleSave").findOnce().bounds();
click(FS.centerX(), FS.centerY());
toastLog("已尝试点击“发送”按钮");
sleep(2000);
}
} else {
var CW = id("com.sina.weibo:id/titleText").findOnce().text();
toastLog("处于错误的界面:" + CW + ",即将重新进入活动…");
sleep(2000);
}
} else {
toastLog("未找到微博顶栏标题,即将重新进入活动…");
sleep(2000);
}
}
function Pinglun() {
toastLog("已尝试点击“评论/抢沙发”任务按钮");
sleep(1000);
while (text("加载中").findOnce() != null) {
toastLog("正在等待“评论列表”加载……");
sleep(2000);
}
if (id("com.sina.weibo:id/titleText").findOnce() != null) {
if (id("com.sina.weibo:id/titleText").findOnce().text() == "热门微博" ||
id("com.sina.weibo:id/titleText").findOnce().text() == "快来抢沙发") {
toastLog("已处于“评论列表”");
sleep(2000);
clickId('com.sina.weibo:id/midButton')
sleep(2000)
clickTar(text('评论').findOne())
sleep(1000)
if(id('element_editbox').exists()){
let textStr = 'testComment' + random(2000, 3000);
setText(textStr)
clickId('com.sina.weibo:id/tv_send')
sleep(3000)
// 删除
clickTar(text(textStr).findOne().parent())
sleep(400)
clickTar(className('android.widget.TextView').text('删除').findOne())
sleep(400)
clickTar(className('android.widget.TextView').text('确定').findOne())
back();
return true;
}
} else {
var CW = id("titleText").findOnce().text();
toastLog("处于错误的界面:" + CW + ",即将重新进入活动…");
sleep(2000);
}
} else {
toastLog("未找到微博顶栏标题,即将重新进入活动…");
sleep(2000);
}
return false;
}
function Zhuanfa() {
while (text("加载中").findOnce() != null) {
toastLog("正在等待“转发列表”加载……");
sleep(2000);
}
if (id("com.sina.weibo:id/titleText").findOnce() != null) {
if (id("com.sina.weibo:id/titleText").findOnce().text() == "热门微博") {
toastLog("已处于“转发列表”");
sleep(2000);
if (id("com.sina.weibo:id/leftButton").findOnce() != null) {
id("com.sina.weibo:id/leftButton").findOnce().click();
toastLog("已尝试点击“左转”按钮");
sleep(2000);
if (id("com.sina.weibo:id/forward_edit").findOnce() != null) {
id("com.sina.weibo:id/forward_edit").findOnce().click();
toastLog("已尝试点击“转发编辑”按钮");
sleep(2000);
if (id("com.sina.weibo:id/titleText").findOnce() != null) {
if (id("com.sina.weibo:id/titleText").findOnce().text() == "转发微博") {
setText(fmt("转发微博(Waiting For Delete & %s)", random(1000, 2000)));
sleep(1000);
var Fs = id("com.sina.weibo:id/titleSave").findOne().bounds();
click(Fs.centerX(), Fs.centerY());
toastLog("已尝试点击“发送”按钮");
sleep(2000);
return true;
}
}
}
}
} else {
var CW = id("com.sina.weibo:id/titleText").findOnce().text();
toastLog("处于错误的界面:" + CW + ",即将重新进入活动…");
sleep(2000);
}
} else {
toastLog("未找到微博顶栏标题,即将重新进入活动…");
sleep(2000);
}
return false;
}
function Guanzhu() {
clickTar(text("推荐").findOnce())
toastLog("已尝试点击“关注”任务按钮");
sleep(2000);
while (text("加载中").findOnce() != null) {
toastLog("正在等待“关注列表”加载……");
sleep(2000);
}
if (id("com.sina.weibo:id/titleText").findOnce() != null) {
if (id("com.sina.weibo:id/titleText").findOnce().text() == "关注") {
toastLog("已处于“关注列表”");
sleep(3000);
let btn = textStartsWith('粉丝数').findOnce().parent().parent().findOne(className('android.widget.Button').text('关注'))
if (btn != null) {
clickTar(btn.parent());
toastLog("已尝试点击“关注”按钮");
sleep(3000);
if (text("已关注").findOnce() != null) {
var QXGZ = text("已关注").findOnce().bounds();
click(QXGZ.centerX(), QXGZ.centerY());
toastLog("已尝试点击“已关注”按钮");
sleep(3000);
if (className("android.widget.TextView").text("已关注").findOnce() != null) {
var Aqg = className("android.widget.TextView").text("已关注").findOnce().bounds();
click(Aqg.centerX(), Aqg.centerY());
toastLog("已尝试点击“已关注菜单”按钮");
sleep(2000);
if (className("android.widget.TextView").text("取消关注").findOnce() != null) {
var QG = className("android.widget.TextView").text("取消关注").findOnce().bounds();
click(QG.centerX(), QG.centerY());
toastLog("已尝试点击“取消关注”按钮");
sleep(2000);
if (className("android.widget.TextView").text("确定").findOnce() != null) {
className("android.widget.TextView").text("确定").findOnce().click();
toastLog("已尝试点击“确定取消关注”按钮");
sleep(500)
clickId('img_back')
return true;
}
}
}
}
}
} else {
var CW = id("titleText").findOnce().text();
toastLog("处于错误的界面:" + CW + ",即将重新进入活动…");
sleep(2000);
}
} else {
toastLog("未找到微博顶栏标题,即将重新进入活动…");
sleep(2000);
}
return false;
}
/** common */
function getProcess(){
if(id('bottom_process_tv').exists()){
return id('bottom_process_tv').findOne().text()
}
return '没有'
}
function fmt(str){
var args = arguments, flag = true, i = 1;
str = str.replace(/%s/g, function () {
var arg = args[i++];
if (typeof arg === 'undefined') {
flag = false;
return '';
}
return arg;
});
return flag ? str : '';
}
function clickId(tid){
if(id(tid).exists()){
let target = id(tid).findOne();
return clickTar(target);
}
return false;
}
function clickTar(target){
if(target == null){
return false;
}
if(target.clickable()){
target.click();
}else{
let bounds = target.bounds()
click(bounds.centerX(), bounds.centerY())
}
return true;
}
function randSwipeArg(minHight, maxHeight){
var swipeCost = random(500, 800),
randStartY = random(200, 400),
randEndY = random(minHight || 1200, maxHeight || 1800),
randStartX = random(20, 40),
randEndX = random(20, 40)
;
randStartX = (randStartX % 2 == 0) ? -randStartX : randStartX
randEndX = (randEndX % 2 == 0) ? -randEndX : randEndX
var startX = device.width / 2 + randStartX,
startY = device.height - randStartY,
endX = device.width / 2 + randEndX,
endY = device.height - randEndY
;
return [startX, startY, endX, endY, swipeCost];
}