forked from maxwellyue/autojs_script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.js
223 lines (197 loc) · 5.25 KB
/
template.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
const utils = require('./common.js');
var template = {};
/**
* 初始化参数
*/
var initParam = {
appName:"",//应用名称
lastNewsText:"",//上一次新闻标题
totalNewsReaded : 0,//已经阅读的新闻条数
totalNewsOneTime : 50,//一次性阅读多少条新闻
loopTimeToFindNews : 20,//找了多少次新闻找不到会退出
indexBtnText: "首页", //其他页面挑到首页的按钮文字,重要!
indexFlagText : "刷新",//首页特有的标志文字,重要!
timeAwardText : "领取",//时段奖励关键字
}
template.init = function(param){
Object.assign(initParam, param);
}
/**
* 运行
* 需要的方法
* 1、签到:signIn
* 2、寻找一条新闻条目:findNewsItem
*/
template.run = function(fun){
/**
* 启动
*/
utils.wakeUp();
utils.launch(initParam.appName);
/**
* 自动更新
*/
template.autoUpdate(fun);
/**
* 回归首页的位置
*/
template.jumpToIndex(fun.getIndexBtnItem);
/**
* 签到
*/
if(fun.signIn != null){
fun.signIn();
}
/**
* 新闻阅读流程
*/
while(true){
//领取时段奖励
template.getTimeAward(fun.doingAfterTimeAward);
//找到一条新闻
template.getOneNews(fun.findNewsItem);
//阅读新闻60s
template.readNews(60,fun.isShouldBack);
//返回新闻列表
utils.backToIndex(initParam.indexFlagText);
}
}
template.autoUpdate = function(fun){
var updateFlag = false;
var updateBtn;
if(text("安全升级").findOnce()){
updateFlag = true;
updateBtn = text("安全升级").findOnce();
}
if(text("立即升级").findOnce()){
updateFlag = true;
updateBtn = text("立即升级").findOnce();
}
if(text("立即更新").findOnce()){
updateFlag = true;
updateBtn = text("立即更新").findOnce();
}
if(text("升级").findOnce()){
updateFlag = true;
updateBtn = text("升级").findOnce();
}
if(updateFlag){
updateBtn.click();
}else{
return;
}
//循环找安装,有可能安装还不能用
var installFlag = false;
while(!installFlag){
sleep(1000);
var uiele = text("安装").findOnce();
toast("开始找安装");
if(uiele){
uiele.click();
sleep(1000);
uiele = text("安装").findOnce();
if(!uiele){
installFlag = true;
}
}
}
//安装完成
var installFinishFlag = false;
while(!installFinishFlag){
sleep(1000);
var uiele = text("完成").findOnce();
if(uiele){
uiele.click();
installFinishFlag = true;
}
}
//重新运行
template.run(fun);
}
/**
* 跳转到首页
* 1、返回和首页标识一起判断
*/
template.jumpToIndex = function(getIndexBtnItem){
var indexFlag = text(initParam.indexFlagText).findOnce();
while(!indexFlag){
//点击首页标识性文字
var flag = false;
if(getIndexBtnItem == null){
flag = utils.UITextBoundsClick(initParam.indexBtnText);
}else{
flag = getIndexBtnItem().click();
}
//执行返回
if(!flag){
back();
}
sleep(1000);
//重新取flag
indexFlag = text(initParam.indexFlagText).findOnce();
}
}
/**
* 获取时段奖励
*/
template.getTimeAward = function(doingAfterTimeAward){
utils.UITextBoundsClick(initParam.timeAwardText);
//判断是否有提示
if(doingAfterTimeAward != null){
doingAfterTimeAward();
}
}
/**
* 获取一条新闻
*/
template.getOneNews = function(findNewsItem){
//阅读超过50条,刷新页面
if(initParam.totalNewsReaded > initParam.totalNewsOneTime){
initParam.totalNews = 0;
click(1,1919);
sleep(2000);
}
//上滑找新闻
var isFindNews = false;//是否找到新闻
var newsText = "";//新闻标题
var newsItem;//新闻条目
initParam.loopTimeToFindNews = 0;//循环次数
while((!isFindNews || initParam.lastNewsText === newsText) && initParam.loopTimeToFindNews < 20){
//找新闻次数+1
initParam.loopTimeToFindNews++;
//进行下翻
swipe(device.width / 2, device.height / 4 * 2, device.width / 2, device.height / 4, 1000);
sleep(1000);
//新闻条目
newsItem = findNewsItem();
if(newsItem){
newsText = newsItem.child(0).text();
isFindNews = true;
}
}
//找到新闻,点击阅读
if(isFindNews){
initParam.lastNewsText = newsText;
initParam.totalNewsReaded++;
newsItem.click();
}else{
toast("20次滑动没有找到新闻,请检查新闻ID");
exit();
}
}
//阅读新闻
template.readNews = function(seconds,isShouldBack){
//滑动阅读新闻
for(var i = 0 ;i < seconds/10 ;i++){
utils.swapeToRead();
//判断是否直接返回
var shouldBack = false;
if(isShouldBack != null){
shouldBack = isShouldBack();
}
if(shouldBack){
return;
}
}
}
module.exports = template;