commit | author | age
|
bc5e1e
|
1 |
//操作 |
X |
2 |
|
|
3 |
let dynamicData = require("slib/dynamicData"), datas = require("slib/datas"), |
|
4 |
swiper = require("slib/swiper"), request = require("slib/request"); |
|
5 |
|
|
6 |
function actions() { |
|
7 |
|
|
8 |
} |
|
9 |
|
|
10 |
|
|
11 |
/** |
|
12 |
* description 根据关键词搜索视频 |
|
13 |
* @param keyword {string} : 搜索词 |
|
14 |
* @param platform {number} : 平台 |
|
15 |
* @return {boolean} : 返回是否成功 |
|
16 |
*/ |
|
17 |
actions.prototype.searchVideoByKeyword = function (keyword, platform) { |
|
18 |
let result = false; |
|
19 |
let startNum = 3; //重试次数 |
|
20 |
//搜索内容 |
|
21 |
logd('准备搜索'); |
b2d3f7
|
22 |
dynamicData.deviceLog(true, {log_detail: '准备搜索'}); |
bc5e1e
|
23 |
let schemesItem = datas.schemes.filter(item => item.platform === platform); |
b2d3f7
|
24 |
let map = {"uri": schemesItem[0].scheme["search"] + keyword}; |
bc5e1e
|
25 |
let num = 0; |
X |
26 |
search: |
b2d3f7
|
27 |
while (num < startNum) { |
P |
28 |
try { |
|
29 |
logd(JSON.stringify(map)); |
|
30 |
if (utils.openActivity(map)) { |
|
31 |
sleep(8 * 1000); |
|
32 |
logd('搜索完成, 准备进入结果页'); |
|
33 |
let log = { |
|
34 |
log_detail: '搜索完成, 准备进入结果页', |
|
35 |
operate_type: 4, |
|
36 |
keyword: keyword |
bc5e1e
|
37 |
} |
b2d3f7
|
38 |
dynamicData.deviceLog(true, log); |
P |
39 |
// dynamicData.insertTrace(log); |
|
40 |
|
|
41 |
let notVideo = text("搜索结果为空").getOneNodeInfo(3 * 1000); |
|
42 |
if (notVideo) { |
|
43 |
logd('搜索受限, 准备关闭脚本'); |
|
44 |
actions.prototype.exceptionLog('搜索受限, 准备关闭脚本'); |
|
45 |
request.sendDingDing('搜索受限,任务停止', '', false); |
|
46 |
exit(); |
|
47 |
break; |
|
48 |
} |
|
49 |
//进入视频页 |
|
50 |
if (platform === 1) { //抖音 |
|
51 |
let tab_node = clz("android.widget.Button").text("视频").getOneNodeInfo(10 * 1000); //视频分类 |
bc5e1e
|
52 |
if (tab_node) { |
X |
53 |
tab_node.click(); |
|
54 |
logd('已进入视频分类'); |
b2d3f7
|
55 |
dynamicData.deviceLog(true, {log_detail: '已进入视频分类'}); |
bc5e1e
|
56 |
sleep(8 * 1000); |
b2d3f7
|
57 |
let video_node = id("com.ss.android.ugc.aweme:id/cover").getOneNodeInfo(10 * 1000); //第一个作品 |
bc5e1e
|
58 |
if (video_node) { |
X |
59 |
video_node.click(); |
b2d3f7
|
60 |
logd('已进入视频, 准备浏览作品'); |
P |
61 |
dynamicData.deviceLog(true, {log_detail: '已进入视频, 准备浏览作品'}); |
|
62 |
sleep(3 * 1000); |
bc5e1e
|
63 |
result = true; |
X |
64 |
break; |
|
65 |
} |
|
66 |
} |
b2d3f7
|
67 |
} else if (platform === 2) { //小红书 |
P |
68 |
let selector = text("筛选").getOneNodeInfo(10 * 1000); |
|
69 |
if (selector) { |
|
70 |
selector.click(); |
|
71 |
sleep(5 * 1000); |
|
72 |
let tab_node = text("视频").getOneNodeInfo(10 * 1000); //视频分类 |
|
73 |
if (tab_node) { |
|
74 |
tab_node.click(); |
|
75 |
sleep(5 * 1000); |
|
76 |
let finishSelector = text("完成").clickable(true).getOneNodeInfo(10 * 1000); |
|
77 |
if (finishSelector) { |
|
78 |
finishSelector.click(); |
|
79 |
} else { |
|
80 |
selector.click(); |
|
81 |
} |
bc5e1e
|
82 |
logd('已进入视频分类'); |
b2d3f7
|
83 |
dynamicData.deviceLog(true, {log_detail: '已进入视频分类'}); |
P |
84 |
sleep(8 * 1000); |
|
85 |
let video_node = clz("android.widget.ImageView").depth(13).getOneNodeInfo(10 * 1000); //第一个作品 |
|
86 |
if (video_node) { |
|
87 |
video_node.click(); |
|
88 |
logd('已进入视频页, 准备浏览作品'); |
|
89 |
dynamicData.deviceLog(true, {log_detail: '已进入视频页, 准备浏览作品'}); |
|
90 |
result = true; |
|
91 |
break; |
|
92 |
} |
|
93 |
} |
|
94 |
} |
|
95 |
} else if (platform === 3) { //快手 |
|
96 |
let tabs = id("com.smile.gifmaker:id/tabs").getOneNodeInfo(10 * 1000).child(0).allChildren(); //分类 |
|
97 |
if (tabs) { |
|
98 |
for (let i = 1; i < tabs.length; i++) { |
|
99 |
tabs[i].click(); |
|
100 |
sleep(8 * 1000); |
|
101 |
let live_node = id("com.smile.gifmaker:id/live_status_text").getOneNodeInfo(5 * 1000); //直播分类 |
|
102 |
let video_node = id("com.smile.gifmaker:id/player_cover").getOneNodeInfo(5 * 1000); //视频分类 |
|
103 |
if (!live_node && video_node) { |
|
104 |
logd('已进入视频分类'); |
|
105 |
dynamicData.deviceLog(true, {log_detail: '已进入视频分类'}); |
|
106 |
video_node.click(); |
|
107 |
dynamicData.deviceLog(true, {log_detail: '已进入视频, 准备浏览作品'}); |
|
108 |
sleep(3 * 1000) |
|
109 |
result = true; |
|
110 |
break search; |
|
111 |
} |
bc5e1e
|
112 |
} |
X |
113 |
} |
|
114 |
} |
b2d3f7
|
115 |
} else { |
P |
116 |
logd('搜索失败, 重新搜索'); |
|
117 |
dynamicData.deviceLog(false, {log_detail: '搜索失败, 重新搜索'}); |
bc5e1e
|
118 |
} |
b2d3f7
|
119 |
} catch (e) { |
P |
120 |
logd('搜索失败:' + e); |
|
121 |
actions.prototype.exceptionLog('搜索失败:' + e); |
bc5e1e
|
122 |
} |
b2d3f7
|
123 |
num++; |
bc5e1e
|
124 |
} |
X |
125 |
return result; |
|
126 |
} |
|
127 |
|
b2d3f7
|
128 |
|
P |
129 |
/** |
|
130 |
* description 根据关键词搜索视频 |
|
131 |
* @param keyword {string} : 搜索词 |
|
132 |
* @param platform {number} : 平台 (百度,QQ浏览器) |
|
133 |
* @return {boolean} : 返回是否成功 |
|
134 |
*/ |
|
135 |
actions.prototype.searchByKeyword = function (keyword, platform) { |
|
136 |
let result = false; |
|
137 |
let startNum = 3; //重试次数 |
|
138 |
//搜索内容 |
|
139 |
logd('准备搜索'); |
|
140 |
dynamicData.deviceLog(true, {log_detail: '准备搜索'}); |
|
141 |
let schemesItem = datas.schemes.filter(item => item.platform === platform); |
|
142 |
let map = {"uri": schemesItem[0].scheme["search"] + keyword}; |
|
143 |
let num = 0; |
|
144 |
search: |
|
145 |
while (num < startNum) { |
|
146 |
try { |
|
147 |
let searchLayout = id("com.baidu.searchbox:id/obfuscated").getOneNodeInfo(5000); |
|
148 |
if (searchLayout) { |
|
149 |
let editableTextSelector = clz("android.widget.EditText"); |
|
150 |
if (editableTextSelector) { |
|
151 |
click(editableTextSelector); |
|
152 |
logd('搜索框已点击'); |
|
153 |
editableTextSelector.clearText(); |
|
154 |
inputText(editableTextSelector, keyword); |
|
155 |
logd('输入搜索内容:' + keyword); |
|
156 |
let searchBtn = text("搜索").getOneNodeInfo(5000); |
|
157 |
if (searchBtn.click()) { |
|
158 |
logd('搜索已点击'); |
|
159 |
result = true; |
|
160 |
} |
|
161 |
} else { |
|
162 |
let searchBox = searchLayout.getOneNodeInfo(clz("android.widget.TextView"), 5000); |
|
163 |
if (searchBox.click()) { |
|
164 |
logd('搜索框已点击'); |
|
165 |
let searchLayout2 = id("com.baidu.searchbox:id/obfuscated").getOneNodeInfo(5000); |
|
166 |
if (searchLayout2) { |
|
167 |
let editTextSelector2 = searchLayout2.getOneNodeInfo(clz("android.widget.EditText"), 5000); |
|
168 |
editTextSelector2.clearText(); |
|
169 |
inputText(editTextSelector2, keyword); |
|
170 |
logd('输入搜索内容:' + keyword); |
|
171 |
let searchBtn = text("搜索").getOneNodeInfo(5000); |
|
172 |
if (searchBtn.click()) { |
|
173 |
logd('搜索已点击'); |
|
174 |
result = true; |
|
175 |
} |
|
176 |
} |
|
177 |
} |
|
178 |
} |
|
179 |
|
|
180 |
} |
|
181 |
logd(JSON.stringify(map)); |
|
182 |
} catch (e) { |
|
183 |
logd('搜索失败:' + e); |
|
184 |
actions.prototype.exceptionLog('搜索失败:' + e); |
|
185 |
} |
|
186 |
num++; |
|
187 |
} |
|
188 |
return result; |
|
189 |
} |
bc5e1e
|
190 |
|
X |
191 |
/** |
|
192 |
* description 根据用户id搜索视频 |
|
193 |
* @param userId {string} : 用户id |
|
194 |
* @param platform {number} : 平台 |
|
195 |
* @return {boolean} : 返回用户信息 |
|
196 |
*/ |
|
197 |
actions.prototype.searchVideoByUserId = function (userId, platform) { |
|
198 |
let result = false; |
|
199 |
let startNum = 3; //重试次数 |
|
200 |
//搜索用户 |
|
201 |
logd('准备搜索用户'); |
b2d3f7
|
202 |
dynamicData.deviceLog(true, {log_detail: '准备搜索用户'}); |
bc5e1e
|
203 |
let schemesItem = datas.schemes.filter(item => item.platform === platform); |
X |
204 |
let map = {"uri": schemesItem[0].scheme["search"] + userId}; |
|
205 |
let num = 0; |
|
206 |
while (num < startNum) { |
|
207 |
try { |
|
208 |
if (utils.openActivity(map)) { |
b2d3f7
|
209 |
sleep(8 * 1000); |
bc5e1e
|
210 |
logd('搜索完成,准备进入用户主页'); |
X |
211 |
let log = { |
|
212 |
log_detail: '搜索完成,准备进入用户主页', |
|
213 |
operate_type: 4, |
|
214 |
keyword: userId |
|
215 |
} |
|
216 |
dynamicData.deviceLog(true, log); |
|
217 |
dynamicData.insertTrace(log); |
|
218 |
|
|
219 |
let notVideo = text("搜索结果为空").getOneNodeInfo(3 * 1000); |
|
220 |
if (notVideo) { |
|
221 |
logd('搜索受限, 准备关闭脚本'); |
|
222 |
actions.prototype.exceptionLog('搜索受限, 准备关闭脚本'); |
|
223 |
request.sendDingDing('搜索受限,任务停止', '', false); |
|
224 |
exit(); |
|
225 |
break; |
|
226 |
} |
|
227 |
//进入用户分类 |
|
228 |
let tab_node, user_node, video_node, video_tab; //用户分类,第一个用户,第一个视频,作品分类 |
|
229 |
if (platform === 1) tab_node = clz("android.widget.Button").text("用户").getOneNodeInfo(8 * 1000); |
|
230 |
if (platform === 2) tab_node = text("用户").getOneNodeInfo(8 * 1000); |
|
231 |
if (platform === 3) { |
|
232 |
let tabs = id("com.smile.gifmaker:id/tabs").getOneNodeInfo(8 * 1000).child(0).allChildren(); //分类 |
|
233 |
if (tabs) { |
|
234 |
for (let i = 1; i < tabs.length; i++) { |
|
235 |
tabs[i].click(); |
|
236 |
sleep(8 * 1000); |
|
237 |
let name_node = id("com.smile.gifmaker:id/name").getOneNodeInfo(5 * 1000); //用户分类 |
|
238 |
let video_node = id("com.smile.gifmaker:id/player_cover").getOneNodeInfo(5 * 1000); //视频分类 |
|
239 |
if (name_node && !video_node) { |
|
240 |
tab_node = id("com.smile.gifmaker:id/tabs").getOneNodeInfo(8 * 1000).child(0).child(i); |
|
241 |
break; |
|
242 |
} |
|
243 |
} |
|
244 |
} |
|
245 |
} |
|
246 |
if (tab_node) { |
|
247 |
tab_node.click(); |
|
248 |
logd('已进入用户分类'); |
b2d3f7
|
249 |
dynamicData.deviceLog(true, {log_detail: '已进入用户分类'}); |
bc5e1e
|
250 |
sleep(5 * 1000); |
X |
251 |
//进入用户主页 |
|
252 |
if (platform === 1) user_node = clz("com.lynx.tasm.behavior.ui.LynxFlattenUI").getOneNodeInfo(8 * 1000); |
|
253 |
if (platform === 2) user_node = clz("android.widget.RelativeLayout").getOneNodeInfo(8 * 1000); |
|
254 |
if (platform === 3) user_node = id("com.smile.gifmaker:id/user_root_layout").getOneNodeInfo(8 * 1000); |
|
255 |
if (user_node) { |
|
256 |
user_node.click(); |
|
257 |
logd('已进入用户主页'); |
b2d3f7
|
258 |
dynamicData.deviceLog(true, {log_detail: '已进入用户主页'}); |
bc5e1e
|
259 |
sleep(5 * 1000); |
X |
260 |
if (platform === 1) video_tab = descMatch(".*作品.*").clz("android.widget.TextView").selected(false).getOneNodeInfo(8 * 1000); |
|
261 |
if (platform === 2) video_tab = descMatch(".*笔记.*").clz("android.view.ViewGroup").selected(false).getOneNodeInfo(8 * 1000); |
|
262 |
if (platform === 3) video_tab = textMatch(".*作品.*").id("com.smile.gifmaker:id/tab_text").selected(false).getOneNodeInfo(8 * 1000); |
|
263 |
if (video_tab) { |
|
264 |
video_tab.click(); |
|
265 |
logd('已进入作品分类'); |
b2d3f7
|
266 |
dynamicData.deviceLog(true, {log_detail: '已进入作品分类'}); |
bc5e1e
|
267 |
sleep(2 * 1000); |
X |
268 |
} |
|
269 |
//进入作品 |
|
270 |
if (platform === 1) video_node = id("com.ss.android.ugc.aweme:id/cover").getOneNodeInfo(8 * 1000); |
|
271 |
if (platform === 2) video_node = drawingOrder(3).depth(23).getOneNodeInfo(8 * 1000); |
|
272 |
if (platform === 3) video_node = id("com.smile.gifmaker:id/player_cover").getOneNodeInfo(8 * 1000); |
|
273 |
if (video_node) { |
|
274 |
video_node.click(); |
|
275 |
logd('已进入视频页, 准备浏览作品'); |
b2d3f7
|
276 |
dynamicData.deviceLog(true, {log_detail: '已进入视频页, 准备浏览作品'}); |
bc5e1e
|
277 |
result = true; |
X |
278 |
break; |
|
279 |
} |
|
280 |
} |
|
281 |
} |
|
282 |
} else { |
|
283 |
logd('搜索失败, 重新搜索'); |
b2d3f7
|
284 |
dynamicData.deviceLog(false, {log_detail: '搜索失败, 重新搜索'}); |
bc5e1e
|
285 |
} |
X |
286 |
} catch (e) { |
|
287 |
logd('搜索失败:' + e); |
|
288 |
actions.prototype.exceptionLog('搜索失败:' + e); |
|
289 |
} |
|
290 |
num++; |
|
291 |
} |
|
292 |
return result; |
|
293 |
} |
|
294 |
|
|
295 |
|
|
296 |
/** |
|
297 |
* description 打开视频地址 |
|
298 |
* @param url {string} : 地址 |
|
299 |
* @param platform {number} : 平台 |
|
300 |
* @return {boolean} : 返回是否成功 |
|
301 |
*/ |
|
302 |
actions.prototype.searchVideoByUrl = function (url, platform) { |
|
303 |
let result = false; |
|
304 |
let startNum = 3; //重试次数 |
|
305 |
//搜索视频 |
|
306 |
dynamicData.deviceLog(true, {log_detail: '准备打开视频'}); |
|
307 |
let schemesItem = datas.schemes.filter(item => item.platform === platform); |
b2d3f7
|
308 |
let map = {"uri": schemesItem[0].scheme["search"] + url}; |
bc5e1e
|
309 |
let num = 0; |
X |
310 |
while (num < startNum) { |
|
311 |
try { |
|
312 |
if (utils.openActivity(map)) { |
|
313 |
sleep(8000); |
|
314 |
logd('已进入视频'); |
|
315 |
let log = { |
|
316 |
log_detail: '已进入视频', |
|
317 |
operate_type: 4, |
|
318 |
} |
|
319 |
dynamicData.deviceLog(true, log); |
|
320 |
dynamicData.insertTrace(log); |
|
321 |
result = true; |
|
322 |
break; |
|
323 |
} else { |
|
324 |
logd('打开视频失败'); |
b2d3f7
|
325 |
dynamicData.deviceLog(false, {log_detail: '打开视频失败'}); |
bc5e1e
|
326 |
} |
X |
327 |
} catch (e) { |
|
328 |
logd('搜索失败:' + e); |
|
329 |
let error = { |
b2d3f7
|
330 |
log_detail: '搜索失败:' + e, |
P |
331 |
operate_type: 16 |
bc5e1e
|
332 |
} |
X |
333 |
dynamicData.deviceLog(true, error); |
|
334 |
dynamicData.insertTrace(error); |
|
335 |
} |
|
336 |
num++; |
|
337 |
} |
|
338 |
return result; |
|
339 |
} |
|
340 |
|
|
341 |
|
|
342 |
/** |
|
343 |
* description 评论回复 |
|
344 |
* @param dom {object} : 评论节点 |
|
345 |
* @param log {object} : 日志参数组 |
|
346 |
* @return {boolean} : 返回是否成功 |
|
347 |
*/ |
|
348 |
actions.prototype.commentReply = function (dom, log) { |
|
349 |
let result = false; |
|
350 |
if (dom) { |
|
351 |
dom.click(); |
|
352 |
let title = textMatch(".*自己评论.*").getOneNodeInfo(10000); |
|
353 |
if (title) { |
|
354 |
logd('当前评论不允许回复, 继续浏览评论'); |
|
355 |
log.log_detail = '当前评论不允许回复, 继续浏览评论'; |
|
356 |
dynamicData.deviceLog(true, log); |
|
357 |
} else { |
|
358 |
logd('准备输入回复内容'); |
|
359 |
log.log_detail = '准备输入回复内容'; |
|
360 |
dynamicData.deviceLog(true, log); |
|
361 |
let words = "hello"; |
|
362 |
let input_selectors = clz("android.widget.EditText").getOneNodeInfo(10000); |
|
363 |
if (input_selectors) { |
|
364 |
if (input_selectors.inputText(words)) { |
|
365 |
logd('回复内容 "' + words + '" 输入成功, 准备发送'); |
|
366 |
log.log_detail = '回复内容 "' + words + '" 输入成功, 准备发送'; |
|
367 |
dynamicData.deviceLog(true, log); |
|
368 |
let send = text("发送").getOneNodeInfo(10000); |
|
369 |
if (send) { |
|
370 |
send.click(); |
|
371 |
logd('回复完成, 继续浏览评论'); |
|
372 |
log.log_detail = '回复完成, 继续浏览评论'; |
|
373 |
log.operate_type = 11; |
|
374 |
dynamicData.deviceLog(true, log); |
|
375 |
dynamicData.insertTrace(log); |
|
376 |
delete log.operate_type; |
|
377 |
result = true; |
|
378 |
} |
|
379 |
} |
|
380 |
} |
|
381 |
} |
|
382 |
} |
|
383 |
return result; |
|
384 |
} |
|
385 |
|
|
386 |
|
|
387 |
/** |
|
388 |
* description 私信 |
|
389 |
* @param dom {object} : 头像节点 |
|
390 |
* @param platform {number} : 平台 |
|
391 |
* @param log {object} : 日志参数组 |
|
392 |
* @return {boolean} : 返回是否成功 |
|
393 |
*/ |
|
394 |
actions.prototype.message = function (dom, platform, log) { |
|
395 |
let result = false; |
|
396 |
logd('准备进入用户主页'); |
|
397 |
log.log_detail = '准备进入用户主页'; |
|
398 |
dynamicData.deviceLog(true, log); |
|
399 |
if (dom) { |
|
400 |
dom.click(); |
|
401 |
logd('开始浏览用户主页'); |
|
402 |
log.log_detail = '开始浏览用户主页'; |
|
403 |
log.operate_type = 12; |
|
404 |
dynamicData.deviceLog(true, log); |
|
405 |
dynamicData.insertTrace(log) |
|
406 |
delete log.operate_type; |
|
407 |
if (platform === 1) { //抖音先关注再私信 |
|
408 |
let follow_btn = text("关注").clickable(true).getOneNodeInfo(10000); |
|
409 |
if (follow_btn) { |
|
410 |
follow_btn.click(); |
|
411 |
logd('已关注用户, 准备进入私信'); |
|
412 |
log.log_detail = '已关注用户, 准备进入私信'; |
|
413 |
log.operate_type = 13; |
|
414 |
dynamicData.deviceLog(true, log); |
|
415 |
dynamicData.insertTrace(log); |
|
416 |
delete log.operate_type; |
|
417 |
//判断私密账户 |
|
418 |
let private = textMatch(".*私密账号.*").getOneNodeInfo(10000); |
|
419 |
let ok = text("知道了").getOneNodeInfo(10000); |
|
420 |
if (private) { |
|
421 |
ok.click(); |
|
422 |
logd('该用户是私密账户, 取消私信, 准备返回评论区'); |
|
423 |
log.log_detail = '该用户是私密账户, 取消私信, 准备返回评论区'; |
|
424 |
dynamicData.deviceLog(true, log); |
|
425 |
actions.prototype.go_back(1); |
|
426 |
return false; |
|
427 |
} |
|
428 |
} |
|
429 |
} |
|
430 |
let message_btn; //私信按钮 |
|
431 |
if (platform === 1) message_btn = text("私信").getOneNodeInfo(8000); |
|
432 |
if (platform === 2) message_btn = desc("发消息").getOneNodeInfo(8000); |
|
433 |
if (platform === 3) message_btn = id("com.smile.gifmaker:id/send_message_small_icon").getOneNodeInfo(8000); |
|
434 |
let title = text("账号已经注销").getOneNodeInfo(10000); |
|
435 |
//判断是否注销 |
|
436 |
if (title) { |
|
437 |
logd('该用户已注销, 取消私信, 准备返回评论区'); |
|
438 |
log.log_detail = '该用户已注销, 取消私信, 准备返回评论区'; |
|
439 |
dynamicData.deviceLog(true, log); |
|
440 |
actions.prototype.go_back(1); |
|
441 |
return false; |
|
442 |
} else if (message_btn) { |
|
443 |
message_btn.click(); |
|
444 |
logd('已进入私信页, 准备发消息'); |
|
445 |
log.log_detail = '已进入私信页, 准备发消息'; |
|
446 |
dynamicData.deviceLog(true, log); |
|
447 |
let input_selectors = clz("android.widget.EditText"); |
|
448 |
let word = "hello"; |
|
449 |
//寻找输入框 输入话术 |
|
450 |
if (inputText(input_selectors, word)) { |
|
451 |
let send_btn; //发送按钮 |
|
452 |
if (platform === 1) send_btn = desc("发送").getOneNodeInfo(8000); |
|
453 |
if (platform === 2) send_btn = text("发送").getOneNodeInfo(index(0), 8000); |
|
454 |
if (platform === 3) send_btn = id("com.smile.gifmaker:id/send_btn").getOneNodeInfo(8000); |
|
455 |
if (send_btn.click()) { |
|
456 |
logd('私信完成,准备返回评论区'); |
|
457 |
log.log_detail = '私信完成,准备返回评论区'; |
|
458 |
log.operate_type = 14; |
b2d3f7
|
459 |
log.keyword = text; |
bc5e1e
|
460 |
dynamicData.deviceLog(true, log); |
X |
461 |
dynamicData.insertTrace(log); |
|
462 |
delete log.operate_type; |
|
463 |
actions.prototype.go_back(2); |
|
464 |
result = true; |
|
465 |
} |
|
466 |
} |
|
467 |
} |
|
468 |
} |
|
469 |
return result; |
|
470 |
} |
|
471 |
|
|
472 |
|
|
473 |
/** |
|
474 |
* description 点赞 |
|
475 |
* @param dom {object} : 爱心节点 |
|
476 |
* @param log {object} : 日志参数组 |
|
477 |
* @return {boolean} : 返回是否成功 |
|
478 |
*/ |
|
479 |
actions.prototype.like = function (dom, log) { |
|
480 |
let result = false; |
|
481 |
if (dom) { |
|
482 |
dom.click(); |
|
483 |
logd('已点赞, 继续浏览'); |
|
484 |
log.log_detail = '已点赞, 继续浏览'; |
|
485 |
log.operate_type = 10; |
|
486 |
dynamicData.deviceLog(true, log); |
|
487 |
dynamicData.insertTrace(log); |
|
488 |
delete log.operate_type; |
|
489 |
result = true; |
|
490 |
} |
|
491 |
return result; |
|
492 |
} |
|
493 |
|
|
494 |
|
|
495 |
/** |
|
496 |
* description 收藏 |
|
497 |
* @param dom {object} : 收藏节点 |
|
498 |
* @param log {object} : 日志参数组 |
|
499 |
* @return {boolean} : 返回是否成功 |
|
500 |
*/ |
|
501 |
actions.prototype.collection = function (dom, log) { |
|
502 |
let result = false; |
|
503 |
if (dom) { |
|
504 |
dom.click(); |
|
505 |
logd('已收藏, 继续浏览'); |
|
506 |
log.log_detail = '已收藏, 继续浏览'; |
|
507 |
log.operate_type = 7; |
|
508 |
dynamicData.deviceLog(true, log); |
|
509 |
dynamicData.insertTrace(log); |
|
510 |
delete log.operate_type; |
|
511 |
result = true; |
|
512 |
} |
|
513 |
return result; |
|
514 |
} |
|
515 |
|
|
516 |
|
|
517 |
/** |
|
518 |
* description 关注 |
|
519 |
* @param dom {object} : 关注节点 |
|
520 |
* @param log {object} : 日志参数组 |
|
521 |
* @return {boolean} : 返回是否成功 |
|
522 |
*/ |
|
523 |
actions.prototype.follow = function (dom, log) { |
|
524 |
let result = false; |
|
525 |
if (dom) { |
|
526 |
dom.click(); |
|
527 |
logd('已关注, 继续浏览'); |
|
528 |
log.log_detail = '已关注, 继续浏览'; |
|
529 |
log.operate_type = 13; |
|
530 |
dynamicData.deviceLog(true, log); |
|
531 |
dynamicData.insertTrace(log); |
|
532 |
delete log.operate_type; |
|
533 |
result = true; |
|
534 |
} |
|
535 |
return result; |
|
536 |
} |
|
537 |
|
|
538 |
|
|
539 |
/** |
|
540 |
* description 评论 |
|
541 |
* @param log {object} : 日志参数组 |
|
542 |
* @return {boolean} : 返回是否成功 |
|
543 |
*/ |
|
544 |
actions.prototype.comment = function (log) { |
|
545 |
let result = false; |
|
546 |
logd('准备输入评论内容'); |
|
547 |
log.log_detail = '准备输入评论内容'; |
|
548 |
dynamicData.deviceLog(true, log); |
|
549 |
let words = 'hello'; |
|
550 |
let input_selectors; |
|
551 |
input_selectors = clz("android.widget.EditText").getOneNodeInfo(10000); |
|
552 |
let input_tips = textMatch(".*说点什么.*").getOneNodeInfo(10000); |
|
553 |
if (input_selectors || input_tips) { |
|
554 |
if (input_tips) { |
|
555 |
input_tips.click(); |
|
556 |
sleep(4000); |
|
557 |
input_selectors = clz("android.widget.EditText").getOneNodeInfo(10000); |
|
558 |
} |
|
559 |
if (input_selectors.inputText(words)) { |
|
560 |
logd('评论内容 "' + words + '" 输入成功, 准备发送'); |
|
561 |
log.log_detail = '评论内容 "' + words + '" 输入成功, 准备发送'; |
|
562 |
dynamicData.deviceLog(true, log); |
|
563 |
let send = text("发送").getOneNodeInfo(10000); |
|
564 |
if (send) { |
|
565 |
send.click(); |
|
566 |
logd('评论完成, 继续浏览'); |
|
567 |
log.log_detail = '评论完成, 继续浏览'; |
|
568 |
log.operate_type = 9; |
|
569 |
dynamicData.deviceLog(true, log); |
|
570 |
dynamicData.insertTrace(log); |
|
571 |
actions.prototype.go_back(1); |
|
572 |
delete log.operate_type; |
|
573 |
result = true; |
|
574 |
} |
|
575 |
} |
|
576 |
} |
|
577 |
return result; |
|
578 |
} |
|
579 |
|
|
580 |
|
|
581 |
/** |
|
582 |
* description 获取用户账号信息 |
|
583 |
* @param dom {object} : 头像节点 |
|
584 |
* @param platform {number} : 平台 |
|
585 |
* @return {object} : 返回用户账号信息 |
|
586 |
*/ |
|
587 |
actions.prototype.getUserInfo = function (dom, platform) { |
|
588 |
let startNum = 3; //重试次数 |
b2d3f7
|
589 |
let user = {id: '', nickname: ''}; //账号信息 |
bc5e1e
|
590 |
let num = 0; |
X |
591 |
if (dom) { |
|
592 |
let clickResult = dom.click(); |
|
593 |
if (!clickResult) dom.click(); |
|
594 |
logd('准备进入用户主页'); |
b2d3f7
|
595 |
dynamicData.deviceLog(true, {log_detail: '准备进入用户主页'}); |
bc5e1e
|
596 |
} |
X |
597 |
sleep(2 * 1000); |
|
598 |
while (num < startNum) { |
|
599 |
try { |
|
600 |
if (platform === 1) { //抖音 |
|
601 |
let idSelector = textMatch(".*抖音号.*").getOneNodeInfo(8 * 1000); |
|
602 |
let nameSelector = descMatch(".*复制名字.*").getOneNodeInfo(8 * 1000); |
|
603 |
if (idSelector) user.id = idSelector.text.slice(4); |
|
604 |
if (nameSelector) user.nickname = nameSelector.text; |
|
605 |
} else if (platform === 2) { //小红书 |
|
606 |
let idSelectors = textMatch(".*小红书号.*").getOneNodeInfo(8 * 1000); |
|
607 |
if (idSelectors) { |
|
608 |
if (idSelectors.text.includes(":")) { |
|
609 |
user.id = idSelectors.text.slice(5); |
|
610 |
} else { |
|
611 |
user.id = idSelectors.text.slice(4); |
|
612 |
} |
|
613 |
} |
|
614 |
let nameSelectors = depth(16).drawingOrder(9).clz("android.widget.TextView").getOneNodeInfo(8 * 1000); |
|
615 |
if (nameSelectors) user.nickname = nameSelectors.text; |
|
616 |
} else if (platform === 3) { //快手 |
|
617 |
let idSelectors = id("com.smile.gifmaker:id/profile_user_kwai_id").getOneNodeInfo(10 * 1000); |
|
618 |
if (idSelectors) { |
|
619 |
user.id = idSelectors.text.slice(4); |
|
620 |
user.nickname = id("com.smile.gifmaker:id/user_name_tv").getOneNodeInfo(10 * 1000).text; |
|
621 |
} |
|
622 |
} |
|
623 |
if (user.id !== '') { |
|
624 |
logd('已获取用户账号信息'); |
|
625 |
let log = { |
b2d3f7
|
626 |
log_detail: '已获取用户账号信息', |
P |
627 |
operate_type: 12 |
bc5e1e
|
628 |
} |
X |
629 |
dynamicData.deviceLog(true, log); |
|
630 |
dynamicData.insertTrace(log); |
|
631 |
break; |
|
632 |
} |
|
633 |
|
|
634 |
} catch (e) { |
|
635 |
logd('获取用户账号失败:' + e); |
b2d3f7
|
636 |
dynamicData.deviceLog(true, {log_detail: '获取用户账号失败:' + e}); |
bc5e1e
|
637 |
} |
X |
638 |
num++; |
|
639 |
} |
|
640 |
return user; |
|
641 |
} |
|
642 |
|
|
643 |
|
|
644 |
/** |
|
645 |
* description 获取视频地址 |
|
646 |
* @param platform {number} : 平台 |
|
647 |
* @return {object} : 返回地址信息 |
|
648 |
*/ |
|
649 |
actions.prototype.getVideoLink = function (platform) { |
|
650 |
try { |
|
651 |
let shareDesc = descMatch(".*分享.*").getOneNodeInfo(8000); |
|
652 |
let shareId = id("com.smile.gifmaker:id/forward_icon").getOneNodeInfo(8000); |
|
653 |
if (shareDesc || shareId) { |
|
654 |
if (platform === 3) { |
|
655 |
shareId.click(); |
|
656 |
} else { |
|
657 |
shareDesc.click(); |
|
658 |
} |
|
659 |
sleep(3000); |
b2d3f7
|
660 |
let share = [textMatch(".*复制链接.*").getOneNodeInfo(8000), textMatch(".*链接分享.*").getOneNodeInfo(10000), |
bc5e1e
|
661 |
textMatch(".*分享至.*").pkg("com.ss.android.ugc.aweme").getOneNodeInfo(8000)]; |
b2d3f7
|
662 |
for (let i = 0; i < share.length; i++) { |
bc5e1e
|
663 |
if (share[i]) { |
X |
664 |
share[i].parent().click(); |
|
665 |
sleep(2000); |
|
666 |
let content = utils.getClipboardText(); |
|
667 |
if (content) { |
|
668 |
let index = content.lastIndexOf("http"); |
|
669 |
let link = content.slice(index); |
|
670 |
return link; |
|
671 |
} else { |
|
672 |
return null; |
|
673 |
} |
|
674 |
} |
|
675 |
} |
|
676 |
} |
|
677 |
} catch (e) { |
|
678 |
logd('获取视频地址失败:' + e); |
b2d3f7
|
679 |
dynamicData.deviceLog(false, {log_detail: '获取视频地址失败:' + e}); |
bc5e1e
|
680 |
return null; |
X |
681 |
} |
|
682 |
} |
|
683 |
|
|
684 |
|
|
685 |
/** |
|
686 |
* description 获取作品信息 |
|
687 |
* @param platform {number} : 平台 |
|
688 |
* @return {object} : 返回节点信息 |
|
689 |
*/ |
|
690 |
actions.prototype.getVideoInfo = function (platform) { |
|
691 |
let startNum = 3, info = {}; //重试次数, 节点信息 |
|
692 |
let num = 0; |
|
693 |
while (num < startNum) { |
b2d3f7
|
694 |
try { |
bc5e1e
|
695 |
switch (platform) { |
X |
696 |
case 1: //抖音 |
b2d3f7
|
697 |
info.nameSelector = id("com.ss.android.ugc.aweme:id/title").getOneNodeInfo(10 * 1000); //用户名称 |
P |
698 |
info.postSelector = id("com.ss.android.ugc.aweme:id/desc").getOneNodeInfo(10 * 1000); //作品名称 |
|
699 |
info.avatarSelector = id("com.ss.android.ugc.aweme:id/user_avatar").getOneNodeInfo(10 * 1000); //头像 |
|
700 |
info.commentSelector = id("com.ss.android.ugc.aweme:id/comment_container").getOneNodeInfo(10 * 1000); // 评论按钮 |
|
701 |
info.commentCountSelector = id("com.ss.android.ugc.aweme:id/comment_container").getOneNodeInfo(10 * 1000).nextSiblings()[0].child(0); //评论数 |
|
702 |
break; |
|
703 |
case 2: //小红书 |
|
704 |
info.nameSelector = id("com.xingin.xhs:id/matrixNickNameView").getOneNodeInfo(10 * 1000); |
|
705 |
info.postSelector = id("com.xingin.xhs:id/noteContentText").getOneNodeInfo(10 * 1000); |
|
706 |
info.avatarSelector = id("com.xingin.xhs:id/matrixAvatarView").getOneNodeInfo(10 * 1000); |
|
707 |
info.commentSelector = id("com.xingin.xhs:id/commentLayout").getOneNodeInfo(10 * 1000); |
|
708 |
info.commentCountSelector = id("com.xingin.xhs:id/commentLayout").getOneNodeInfo(10 * 1000).child(1); |
|
709 |
break; |
|
710 |
case 3: //快手 |
|
711 |
info.nameSelector = id("com.smile.gifmaker:id/user_name_text_view").getOneNodeInfo(10 * 1000); |
|
712 |
info.postSelector = id("com.smile.gifmaker:id/element_caption_label").getOneNodeInfo(10 * 1000); |
|
713 |
info.avatarSelector = id("com.smile.gifmaker:id/follow_avatar_view").getOneNodeInfo(10 * 1000); |
|
714 |
info.commentSelector = id("com.smile.gifmaker:id/comment_icon").getOneNodeInfo(10 * 1000); |
|
715 |
info.commentCountSelector = id("com.smile.gifmaker:id/comment_count_view").getOneNodeInfo(10 * 1000); |
bc5e1e
|
716 |
} |
X |
717 |
if (info.nameSelector && info.postSelector && info.avatarSelector && info.commentSelector && info.commentCountSelector) { |
|
718 |
break; |
|
719 |
} else { |
|
720 |
info = null; |
|
721 |
} |
|
722 |
} catch (e) { |
|
723 |
info = null; |
|
724 |
} |
|
725 |
num++; |
|
726 |
} |
|
727 |
return info; |
|
728 |
} |
|
729 |
|
|
730 |
|
|
731 |
/** |
|
732 |
* description 随机翻页 |
|
733 |
*/ |
|
734 |
actions.prototype.randomSwiper = function () { |
|
735 |
let max_swiperTimes = random(1, 3); //翻页次数 |
|
736 |
let swiperTimes = 0; |
|
737 |
while (swiperTimes < max_swiperTimes) { |
|
738 |
swiper.pageSwiper(); //翻页 |
|
739 |
logd('随机翻页第' + (swiperTimes + 1) + '次'); |
b2d3f7
|
740 |
let log = {log_detail: '随机翻页第' + (swiperTimes + 1) + '次', operate_type: 15}; |
bc5e1e
|
741 |
dynamicData.deviceLog(false, log); |
X |
742 |
dynamicData.insertTrace(log); |
|
743 |
swiperTimes++; |
b2d3f7
|
744 |
sleep(random(4000, 6000)); |
bc5e1e
|
745 |
} |
X |
746 |
} |
|
747 |
|
|
748 |
/** |
|
749 |
* description 视频翻页 |
|
750 |
* @param log {object} : 日志参数组 |
|
751 |
*/ |
|
752 |
actions.prototype.videoSwiper = function (log) { |
|
753 |
let logInfo = log ? log : {}; |
|
754 |
logInfo.log_detail = '视频翻页'; |
|
755 |
logInfo.operate_type = 15; |
|
756 |
swiper.pageSwiper(); |
|
757 |
logd('视频翻页'); |
|
758 |
dynamicData.deviceLog(false, logInfo); |
b2d3f7
|
759 |
// dynamicData.insertTrace(logInfo); |
bc5e1e
|
760 |
} |
X |
761 |
|
|
762 |
|
|
763 |
/** |
|
764 |
* description 脚本异常日志 |
|
765 |
* @param log_detail {string} : 日志明细 |
|
766 |
*/ |
|
767 |
actions.prototype.exceptionLog = function (log_detail) { |
|
768 |
let error = { |
b2d3f7
|
769 |
log_detail: log_detail, |
P |
770 |
operate_type: 16 |
bc5e1e
|
771 |
} |
X |
772 |
logd(error); |
|
773 |
dynamicData.deviceLog(false, error); |
|
774 |
dynamicData.insertTrace(error); |
|
775 |
} |
|
776 |
|
|
777 |
|
|
778 |
/** |
|
779 |
* description 自定义返回函数 |
|
780 |
* @param page {number} : 返回页数 |
|
781 |
*/ |
|
782 |
actions.prototype.go_back = function (page) { |
|
783 |
let count = 0; |
|
784 |
while (count < page) { |
|
785 |
back(); |
|
786 |
count++; |
|
787 |
sleep(3500); |
|
788 |
} |
|
789 |
} |
|
790 |
|
|
791 |
|
|
792 |
/** |
|
793 |
* 分发数据给对应设备 |
|
794 |
* @param deviceNos {string} : 设备信息 |
|
795 |
* @param data {string} : 数据 |
|
796 |
* @param separator {string} : 数据分隔符 |
|
797 |
* @return {string} : 返回当前设备分配的数据 |
|
798 |
*/ |
|
799 |
actions.prototype.distributeDataToDevices = function (deviceNos, data, separator) { |
|
800 |
let deviceNo = ecloud.getDeviceNo(); //设备编号 |
|
801 |
let devicesArray = deviceNos.split(","); |
|
802 |
let dataArray = data.split(separator); |
|
803 |
for (let i = 0; i < devicesArray.length; i++) { |
|
804 |
if (devicesArray[i] === deviceNo && dataArray[i]) { |
|
805 |
return dataArray[i]; |
|
806 |
} |
|
807 |
} |
|
808 |
} |
|
809 |
|
|
810 |
|
|
811 |
/** |
|
812 |
* 数据按指定字符分割成数组 |
|
813 |
* @param data {string} : 数据 |
|
814 |
* @param separator {string} : 分割符 |
|
815 |
* @return {array} : 返回数据 |
|
816 |
*/ |
|
817 |
actions.prototype.splitData = function (data, separator) { |
|
818 |
let dataArray = data.split(separator); |
b2d3f7
|
819 |
let filterArray = dataArray.filter(function (value) { |
bc5e1e
|
820 |
return value !== undefined && value !== null && value !== ''; |
X |
821 |
}); |
|
822 |
return filterArray; |
|
823 |
} |
|
824 |
|
|
825 |
|
|
826 |
module.exports = new actions(); |