-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.js
156 lines (137 loc) · 4.43 KB
/
main.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
const gestureParam = require("./gestureParam.js");
const package = "com.xiaomi.vipaccount";
const deviceHeight = 2400;
const deviceWidth = 1080;
auto.waitFor();
function unlockScreen() {
while (!device.isScreenOn()) {
device.wakeUp();
sleep(1000);
}
toastLog("开始滑动解锁");
let times = 3;
while (times--) {
swipe(
deviceWidth / 2,
(deviceHeight / 4) * 3,
deviceWidth / 2,
deviceHeight / 4,
1000
);
sleep(2000); // 等待动画
}
toastLog("开始手势解锁");
// gestureParam 解锁的坐标和时间
gestures(gestureParam);
}
function isLocked() {
return context
.getSystemService(context.KEYGUARD_SERVICE)
.inKeyguardRestrictedInputMode();
}
function checkIn() {
// 切换到我的
while (!id("nav_item_3").exists()) sleep(1);
id("nav_item_3").findOne().click();
while (!text("每日签到").exists()) sleep(1);
click("每日签到");
while (!(text("已签到").exists() || text("立即签到").exists())) sleep(1);
if (text("已签到").exists()) {
toastLog("已签到,不再签到");
} else {
// 不延迟签到可能报错
sleep(2000);
// 会卡在人机验证,需要手动操作
// click("立即签到");
while (!text("已签到").exists()) sleep(1000);
// 手动检查结果的时间
sleep(3 * 1000);
toastLog("签到成功");
}
}
function viewPost() {
let firstPostText;
toastLog("开始查找第 1 个非视频帖子");
while (true) {
let firstPostChild;
let counter;
for (counter = 0; counter < 3; counter++) {
try {
firstPostChild = id(`${package}:id/content_view`)
.depth(15)
.find()
.filter(function(ui) {
return ui.bounds().width() > 0; // 存在相同 id 的情况,所以要排除
})[0]
.child(1) // 屏幕第 1 个帖子 (LinearLayout)
.children();
break;
} catch (error) {
if (id(`${package}:id/single_banner`).exists()) {
id(`${package}:id/close`).findOne().click();
toastLog("已关闭弹窗");
}
toastLog(error);
sleep(2000);
if (text("重新加载").exists()) {
click("重新加载");
toastLog("点击 重新加载");
sleep(5000);
}
}
}
if (counter == 3) {
toastLog("超过最大重试次数,没有找到帖子,结束运行");
return false;
}
// 找到第 1 个非视频帖子,视频帖子不计算积分
if (
firstPostChild.length >= 3 &&
firstPostChild[1].className() == "android.widget.TextView" &&
firstPostChild[2].className() == "android.view.ViewGroup"
) {
firstPostText = firstPostChild[1];
break;
}
toastLog("向下滑动查找非视频帖子");
const x = deviceWidth / 2,
y = (deviceHeight / 4) * 3;
swipe(x, y, x, y - 500, 500);
}
// 点击文字部分进入帖子
toastLog("点击进入帖子");
toastLog(firstPostText.text());
click(firstPostText.bounds().centerX(), firstPostText.bounds().centerY());
// 浏览和点赞
toastLog("开始浏览帖子");
sleep(15000);
// className("android.widget.Button").textStartsWith("点赞").findOne().click();
// sleep(1000);
back();
sleep(1000);
back();
toastLog("浏览和点赞结束");
return true;
}
function main() {
if (isLocked()) {
toastLog("屏幕已锁");
unlockScreen();
} else {
toastLog("屏幕未锁");
}
do {
shell(`am force-stop ${package}`, true);
sleep(1000);
launch(package);
toastLog("等待广告");
sleep(6000);
toastLog("开始操作");
} while (viewPost() === false);
checkIn();
let result = shell(`am force-stop ${package}`, true);
toastLog(result);
// lockScreen();
}
main();
//unlockScreen();