gifshowjs

自用库

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/520147/1522508/gifshowjs.js

  1. auto.waitFor();
  2. global.AppName = "快手极速版";
  3. global.packageName = "com.kuaishou.nebula";
  4. global.running = false; //是否正在刷视频中
  5. global.working = false; //是否正在刷视频中
  6. global.pause = false; //是否暂停
  7. global.startSec = Date.now();//刷视频计时
  8. global.img_block = storages.create("gifshow").get('img_block');
  9. global.ver = 'v1.5';//版本号
  10. if (!auto.service || device.width == 0) {
  11. console.warn("2.请重新开启无障碍服务");
  12. auto.service.disableSelf();
  13. app.startActivity({ action: "android.settings.ACCESSIBILITY_SETTINGS" });
  14. android.os.Process.killProcess(android.os.Process.myPid());
  15. }
  16. if (device.fingerprint + '/' + ver != storages.create("gifshow").get('device_info')) { setTimeout(function () { update(); }, 60 * 1000); }
  17. engines.all().map((ScriptEngine) => { if (engines.myEngine().toString() !== ScriptEngine.toString()) { ScriptEngine.forceStop(); } });
  18.  
  19. //判断签到层
  20. function singlecheck() {
  21. toastLog('判断签到提示');
  22. var xbox = textMatches(/倒计时结束.*|开宝箱奖励.*/).visibleToUser(true).findOne(1000);
  23. if (xbox) { click(xbox.parent().parent().parent().child(0).bounds()); }
  24. var today = new Date();
  25. if (storages.create("gifshow").get('singlecheck') == today.getDate()) {
  26. toastLog('今天已完成签到');
  27. return;
  28. }
  29. //查找立即签到
  30. var single = className('Button').textMatches(/立即签到/).clickable(true).visibleToUser(true).findOne(1000);
  31. if (single) {
  32. toastLog('1.点击立即签到');
  33. single.click();
  34. sleep(3000);
  35.  
  36. toastLog('2.再次点击签到');
  37. click(single.bounds());
  38. sleep(3000);
  39. back();
  40.  
  41. toastLog('3.签到结束关闭');
  42. } else {
  43. toastLog('没有签到提示');
  44. }
  45. storages.create("gifshow").put('singlecheck', today.getDate());//记录是否检测过签到
  46. }
  47. //装载任务列表
  48. function tasklist() {
  49. toastLog('查找金币暴涨tasklist');
  50. if (!textMatches(/金币暴涨|我的现金/).visibleToUser(true).findOne(1000)) {
  51. gotask();
  52. sleep(8000);
  53. singlecheck();//判断签到层
  54. //关闭弹出层
  55. var popup = className('Image').text('huge_sign_marketing_popup').visibleToUser(true).findOne(1000);
  56. if (popup) { popup.parent().parent().find(className('Image'))[0].click(); }
  57. //弹出宝箱层
  58. var xbox = textMatches(/倒计时结束.*|开宝箱奖励.*/).visibleToUser(true).findOne(1000);
  59. if (xbox) { click(xbox.parent().parent().parent().child(0).bounds()); }
  60. }
  61. var temparr = [];
  62. var TempArray = new Array();
  63. if (textMatches(/金币暴涨|我的现金/).visibleToUser(true).findOne(1000)) {
  64. toast('装载任务');
  65. idMatches(/.*dailyTask/).visibleToUser(true).find().forEach(function (tv) {
  66. let list = tv.children();
  67. //log(list);
  68. for (i = 0; i < list.length; i++) {
  69. let title = list[i].find(className('android.view.View'));
  70. for (j = 0; j < title.length; j++) {
  71. if (title[j]) {
  72. //log(title[j].text());
  73. if (title[j].text().match(/.*个作品|看广告得.*|连续签到.*|.*次直播领金币|刷广告视频赚金币|看指定视频赚金币|搜索看广告赚金币/)) {
  74. if (title[j].parent().parent().find(text('已完成').clickable(true)).length == 0) {
  75. let btn = title[j].parent().parent().find(className('android.view.View').clickable(true));
  76. //log(title[j].text());
  77. temparr.push(title[j].text());
  78. let temp = [title[j].text(), btn[1]];
  79. TempArray.push(temp);
  80. }
  81. }
  82. }
  83. }
  84. }
  85. });
  86. console.error('装载完成:', temparr);
  87. toast('装载完成');
  88. var btn = className('android.view.View').textMatches(/.*金币立即领取/).visibleToUser(true).findOne(1000);
  89. if (btn) { btn.parent().click(); sleep(2000); }
  90. var btn = className('Button').textMatches(/继续赚钱/).visibleToUser(true).findOne(1000);
  91. if (btn) { click(btn.parent().child(0).bounds()); }
  92. var btn = textMatches(/倒计时结束.*|开宝箱奖励.*/).visibleToUser(true).findOne(1000);
  93. if (btn) { click(btn.parent().parent().parent().child(0).bounds()); }
  94. } else {
  95. toastLog('没有找到金币暴涨tasklist');
  96. }
  97. return TempArray;
  98. }
  99. //点击右下角宝箱函数
  100. function moneybox() {
  101. toastLog('查找右下角宝箱moneybox');
  102. if (!textMatches(/金币暴涨|我的现金/).visibleToUser(true).findOne(1000)) {
  103. gotask();
  104. sleep(8000);
  105. singlecheck();//判断签到层
  106. //关闭弹出层
  107. var popup = className('Image').text('huge_sign_marketing_popup').visibleToUser(true).findOne(1000);
  108. if (popup) { popup.parent().parent().find(className('Image'))[0].click(); }
  109. //弹出宝箱层
  110. var xbox = textMatches(/倒计时结束.*|开宝箱奖励.*/).visibleToUser(true).findOne(1000);
  111. if (xbox) { click(xbox.parent().parent().parent().child(0).bounds()); }
  112. }
  113.  
  114. if (textMatches(/金币暴涨|我的现金/).visibleToUser(true).findOne(1000)) {
  115. console.error('开宝箱');
  116. click(device.width - 150, device.height - 300);
  117. sleep(4000);
  118. } else {
  119. toastLog('没有找到金币暴涨moneybox');
  120. return;
  121. }
  122.  
  123. var xbox = textMatches(/倒计时结束.*|开宝箱奖励.*/).visibleToUser(true).findOne(1000);
  124. if (xbox) { click(xbox.parent().parent().parent().child(0).bounds()); }
  125.  
  126. if (1 == 2) {
  127. //倒计时结束,才能开宝箱哦
  128. xbtn = className('Button').textMatches(/去看广告得最高.*/).visibleToUser(true).findOne(1000);
  129. if (xbtn) {
  130. console.error('点宝箱:', xbtn.text());
  131. click(xbtn.bounds());//再次点弹出宝箱层中的红色按钮
  132. sleep(5000);
  133. } else {
  134. var popdiv = textMatches(/倒计时结束.*/).visibleToUser(true).findOne(1000);
  135. if (popdiv) {
  136. toastLog('宝箱:' + popdiv.text());
  137. click(popdiv.parent().parent().parent().child(0).bounds());
  138. } else {
  139. toastLog('1.未进入宝箱视频');
  140. }
  141. return;
  142. }
  143. }
  144.  
  145. //如果进入看视频赚金币则观看视频
  146. let advedio = idMatches(/.*countdown_info_container/).boundsInside(0, 0, device.width, 500).visibleToUser(true).findOne(1000);
  147. let liveing = idMatches(/.*live_close_container/).boundsInside(device.width - 500, 0, device.width, 500).visibleToUser(true).findOne(1000);
  148. if (advedio || liveing) {
  149. playvideo('BOX');
  150. console.error('宝箱任务结束moneybox');
  151. } else {
  152. toastLog('2.未进入宝箱视频');
  153. }
  154. }
  155.  
  156. //判断进入看广告视频赚金币
  157. function playvideo(m) {
  158. //签到日历
  159. if (text('签到日历').visibleToUser(true).findOne(1000)) { back(); return; }
  160. working = true;
  161. console.error('开始循环赚金币playvideo');
  162. function stopvideo(n) {
  163. sleep(1000);
  164. if (textMatches(/金币暴涨|我的现金/).visibleToUser(true).findOne(1000)) {
  165. console.log(n + '.end');
  166. return;
  167. }
  168. //操作弹出提示
  169. var okbtn = className('TextView').textMatches(/再看[0-9]+秒.*/).visibleToUser(true).findOne(1000);
  170. if (okbtn) {
  171. let btn = className('TextView').text('放弃奖励').visibleToUser(true).findOne(1000);
  172. if (btn) click(btn.bounds().centerX(), btn.bounds().centerY() - 120);
  173. var b = okbtn.text().match(/\d+/)[0] || 1;
  174. var t = 1 * b + random(9, 15);
  175. cutDownBySleep(t, '再看');
  176. }
  177. okbtn = className('TextView').textMatches(/领取奖励/).visibleToUser(true).findOne(1000);
  178. if (okbtn) {
  179. if (className('TextView').textMatches(/再看一个.*/).visibleToUser(true).findOne(1000)) {
  180. console.log(n + '.end');
  181. click(okbtn.bounds());
  182. console.log(n + '.再看一个');
  183. playvideo(n);
  184. return;
  185. }
  186. click(okbtn.bounds());
  187. console.log(n + '.' + okbtn.text());
  188. }
  189. okbtn = className('Button').textMatches(/继续赚金币/).visibleToUser(true).findOne(1000);
  190. if (okbtn) {
  191. console.log(n + '.继续赚金币');
  192. click(okbtn.bounds());
  193. cutDownBySleep(random(9, 15), okbtn.text());
  194. }
  195. okbtn = idMatches(/.*live_close_container/).visibleToUser(true).findOne(1000);
  196. if (okbtn) {
  197. console.log(n + '.退出直播间');
  198. click(okbtn.bounds());
  199. sleep(1000);
  200. }
  201. okbtn = className('TextView').textMatches(/放弃奖励|退出.*/).visibleToUser(true).findOne(1000);
  202. if (okbtn) {
  203. console.log(n + '.' + okbtn.text());
  204. click(okbtn.bounds());
  205. }
  206. okbtn = textMatches(/倒计时结束.*|开宝箱奖励.*/).visibleToUser(true).findOne(1000);
  207. if (okbtn) {
  208. console.log(n + '.' + okbtn.text());
  209. click(okbtn.parent().parent().parent().child(0).bounds());
  210. }
  211. console.log(n + '.end');
  212. sleep(1000);
  213. }
  214. function stoplive(n) {
  215. sleep(1000);
  216. let okbtn = className('TextView').textMatches(/继续观看|领取奖励|退出.*/).visibleToUser(true).findOne(1000);
  217. while (okbtn) {
  218. working = true;
  219. click(okbtn.bounds());
  220. sleep(1000);
  221. if (okbtn.text() == '继续观看') {
  222. console.log('点击继续观看');
  223. let a = idMatches(/.*close_dialog_title/).className('TextView').visibleToUser(true).findOne(1000);
  224. let t = a ? a.text().match(/\d+/)[0] : random(5, 9);
  225. cutDownBySleep(t, n);
  226. liveing = idMatches(/.*live_close_container/).boundsInside(0, 0, device.width, 500).visibleToUser(true).findOne(2000);
  227. if (liveing) {
  228. console.log('点击退出直播间2');
  229. click(liveing.bounds());
  230. sleep(2000);
  231. okbtn = className('TextView').textMatches(/继续观看|领取奖励|退出.*/).visibleToUser(true).findOne(1000);
  232. } else {
  233. console.log('点击退出看广告2');
  234. stopvideo(n);
  235. okbtn = null;
  236. }
  237. } else {
  238. break;
  239. }
  240. }
  241. sleep(1000);
  242. }
  243. var block = className('TextView').textMatches(/.*进入直播间.*/).clickable(true).visibleToUser(true).findOne(1000);
  244. while (block) {
  245. slidingByCurve();
  246. sleep(2000);
  247. block = className('TextView').textMatches(/.*进入直播间.*/).clickable(true).visibleToUser(true).findOne(1000);
  248. }
  249.  
  250. if (m == '点赞1个作品') { toastLog(m); randomHeart(9); sleep(1000); working = false; gotask(); return; }
  251. if (m == '评论1个作品') { toastLog(m); randomHeart(8); sleep(1000); working = false; gotask(); return; }
  252. if (m == '收藏1个作品') { toastLog(m); randomHeart(7); sleep(1000); working = false; gotask(); return; }
  253.  
  254. //看广告得金币/宝箱中看广告
  255. let i = 0;
  256. var liveing = idMatches(/.*live_close_container/).boundsInside(0, 0, device.width, 500).visibleToUser(true).findOne(2000);
  257. var okbtn = className('TextView').textMatches(/[0-9]+s后可领取.*|.*领取观看奖励|已成功领取.*/).boundsInside(0, 0, device.width / 2, 300).visibleToUser(true).findOne(1000);
  258. while (okbtn || liveing) {
  259. i++;
  260. console.log(m + '.1.' + i);
  261. working = true;
  262. if (okbtn) {
  263. var b = okbtn.text().match(/^\d+/);
  264. var t = 1 * (b ? b[0] : 1) + random(9, 15);
  265. cutDownBySleep(t, m);
  266. //点击左上角或back()
  267. click(okbtn.bounds());
  268. stopvideo(m);
  269. }
  270. if (liveing) {
  271. var t = random(9, 15);
  272. cutDownBySleep(t, m);
  273. //点击右上角退出直播间
  274. click(liveing.bounds());
  275. sleep(1000);
  276. stoplive(m);
  277. }
  278. if (i < 60 && m != 'BOX') {
  279. sleep(1000);
  280. //如果退出到任务页面,则再次进入
  281. let tips = className('android.view.View').textMatches(/看广告得[0-9.]+万金币/).findOne(1000);
  282. //log('再次进入::::',tips);
  283. if (tips) {
  284. let progress = tips.parent().find(textMatches(/单日最高赚[0-9.]+万金币.*/));
  285. //log('再次进入####',progress[0]);
  286. if (progress) {
  287. //如果没完成100/100
  288. if (!percent(progress[0].text())) {
  289. console.log('再次进入:', progress[0].text());//进度不刷新,需要重启软件
  290. //再次进入看广告得金币
  291. tips.parent().parent().click();//因为不在视窗范围内,所以不可以点坐标
  292. sleep(3000);
  293. okbtn = className('TextView').textMatches(/[0-9]+s后可领取.*|已成功领取.*/).boundsInside(0, 0, device.width / 2, 300).visibleToUser(true).findOne(1000);
  294. continue;
  295. } else {
  296. toastLog(m + '已完成');
  297. break;
  298. }
  299. }
  300. }
  301. } else {
  302. break;
  303. }
  304. okbtn = className('TextView').textMatches(/[0-9]+s后可领取.*|已成功领取.*/).boundsInside(0, 0, device.width / 2, 300).visibleToUser(true).findOne(1000);
  305. }
  306.  
  307. //看n次直播领金币
  308. let title = className('TextView').text('看直播领金币').visibleToUser(true).findOne(1000);
  309. if (title) {
  310. var btn = idMatches(/.*progress_display/).visibleToUser(true).findOne(1000);
  311. if (btn) { if (percent(btn.text())) { toastLog(m + btn.text()); idMatches(/.*left_btn/).desc("返回").clickable(true).click(); return; } }
  312. //选择直播间
  313. let view = idMatches(/.*recycler_view/).findOne(1000);
  314. if (view) {
  315. var livingarr = new Array(); i = 0;
  316. while (i < 99 && title) {
  317. console.log(m + '.2.' + i);
  318. for (j = 0; j < view.childCount(); j++) {
  319. if (view.child(j)) {
  320. var tip = view.child(j).find(className('TextView'))[0].text();
  321. if (!livingarr.includes(tip)) {
  322. i++;
  323. toastLog(m + '.' + i + '.' + tip);
  324. livingarr[j] = tip;
  325. view.child(j).click();//进入直播间
  326. sleep(5000);
  327. var liveing = idMatches(/.*live_close_container/).boundsInside(0, 0, device.width, 500).visibleToUser(true).findOne(2000);
  328. if (liveing) {
  329. cutDownBySleep(random(10, 15), tip);
  330. click(liveing.bounds());
  331. sleep(1000);
  332. stoplive(tip);
  333. } else {
  334. toastLog('未进入:' + tip);
  335. }
  336. var btn = idMatches(/.*\/close|.*\/anchor_close/).visibleToUser(true).findOne(1000);
  337. if (btn) { console.log('关闭弹出'); click(btn.bounds()); sleep(1000); }
  338. var btn = className('TextView').textMatches(/放弃奖励|退出.*/).visibleToUser(true).findOne(1000);
  339. if (btn) { click(btn.bounds()); sleep(1000); }
  340. var btn = idMatches(/.*progress_display/).visibleToUser(true).findOne(1000);
  341. if (btn) { if (percent(btn.text())) { toastLog(m + btn.text()); idMatches(/.*left_btn/).desc("返回").clickable(true).click(); return; } }
  342. view = idMatches(/.*recycler_view/).findOne(1000);
  343. if (!view) break;
  344. }
  345. }
  346. var liveing = idMatches(/.*live_close_container/).boundsInside(0, 0, device.width, 500).visibleToUser(true).findOne(2000);
  347. if (liveing) {
  348. click(liveing.bounds());
  349. var btn = idMatches(/.*\/close|.*\/anchor_close/).visibleToUser(true).findOne(1000);
  350. if (btn) { console.log('关闭弹出'); click(btn.bounds()); sleep(1000); }
  351. var btn = className('TextView').textMatches(/放弃奖励|退出.*/).visibleToUser(true).findOne(1000);
  352. if (btn) { click(btn.bounds()); sleep(1000); }
  353. var btn = idMatches(/.*progress_display/).visibleToUser(true).findOne(1000);
  354. if (btn) { if (percent(btn.text())) { toastLog(m + btn.text()); idMatches(/.*left_btn/).desc("返回").clickable(true).click(); return; } }
  355. }
  356. //log('看直播:',j);
  357. }
  358. if (i > random(10, 15)) {
  359. log('=============', (i * 4 + j + 1));
  360. break;
  361. }
  362. view.scrollForward(); sleep(3000);
  363. view = idMatches(/.*recycler_view/).findOne(1000);
  364. title = className('TextView').text('看直播领金币').visibleToUser(true).findOne(1000);
  365. }
  366. }
  367. }
  368. //刷广告视频赚金币/看指定视频赚金币
  369. let back_btn = idMatches(/.*left_btn/).desc("返回").clickable(true).boundsInside(0, 0, 500, 500).visibleToUser(true).findOne(1000);
  370. if (back_btn) {
  371. i = 0;//刷广告
  372. var award = idMatches(/.*award_shopping_count_text_view/).visibleToUser(true).findOne(1000);
  373. while (award) {
  374. i++;
  375. console.log(m + '.3.' + award.text().split("/")[0]);
  376. cutDownBySleep(random(9, 25), m);
  377. slidingByCurve();
  378. award = idMatches(/.*award_shopping_count_text_view/).visibleToUser(true).findOne(1000);
  379. if (award && percent(award.text())) break;
  380. if (i > 20) break;
  381. }
  382. i = 0;//看视频
  383. var award = idMatches(/.*camera_btn/).clickable(true).visibleToUser(true).findOne(1000);
  384. while (award) {
  385. i++;
  386. console.log(m + '.4.' + i);
  387. let tip = className('TextView').textMatches(/看视频|查看收益/).visibleToUser(true).findOne(1000);
  388. if (tip) {
  389. if (tip.text() == '看视频') {
  390. cutDownBySleep(random(9, 25), m);
  391. } else {
  392. i = 45;
  393. }
  394. }
  395. slidingByCurve();
  396. award = idMatches(/.*camera_btn/).clickable(true).visibleToUser(true).findOne(1000);
  397. if (i > 50) break;
  398. }
  399. click(back_btn.bounds());
  400. }
  401. //看短剧得金币
  402. let player = null;//className('com.kwai.kds.player.TextureRenderView').visibleToUser(true).findOne(1000);
  403. if (player) {
  404. for (i = 0; i < 5; i++) {
  405. console.log(m + '.5.' + i);
  406. cutDownBySleep(random(6, 20), m);
  407. click(player.bounds().left + 70, player.bounds().top - 70);
  408. var okbtn = className('TextView').textMatches(/再看[0-9]+秒.*/).visibleToUser(true).findOne(1000);
  409. if (okbtn) {
  410. sleep(1500);
  411. let btn = className('TextView').text('放弃奖励').visibleToUser(true).findOne(1000);
  412. if (btn) click(btn.bounds().centerX(), btn.bounds().centerY() - 120);
  413. var b = okbtn.text().match(/\d+/)[0] || 1;
  414. var t = 1 * b + random(5, 9);
  415. cutDownBySleep(t, m);
  416. }
  417. slidingByCurve();
  418. player = className('com.kwai.kds.player.TextureRenderView').visibleToUser(true).findOne(1000);
  419. if (!player) break;
  420. }
  421. if (player) { click(player.bounds().left + 70, player.bounds().top - 70); }
  422. sleep(3000);
  423. }
  424. //搜索:看视频/直播最高赚,已完成20/20
  425. var living = className('TextView').text('看视频/直播最高赚').visibleToUser(true).findOne(1000);
  426. if (living) {
  427. var btn = textMatches(/已完成.*/).visibleToUser(true).findOne(1000);
  428. if (btn) { if (percent(btn.text())) { toastLog(m + btn.text()); idMatches(/.*left_btn/).desc("返回").clickable(true).click(); return; } }
  429. let view = className('android.widget.ScrollView').visibleToUser(true).findOne(1000);
  430. if (view) {
  431. var livingarr = new Array(); i = 0;
  432. while (i < 99 && view) {
  433. console.log(m + '.2.' + view.childCount());
  434. for (j = 0; j < view.childCount(); j++) {
  435. if (view.child(j)) {
  436. var tips = view.child(j).find(className('TextView'));
  437. var tip = tips ? tips[tips.length - 1].text() : '无法取得标题';
  438. if (!livingarr.includes(tip)) {
  439. i++;
  440. toastLog(m + '.' + i + '.' + tip);
  441. livingarr[j] = tip;
  442. view.child(j).click();//点击进入
  443. sleep(5000);
  444. var okbtn = className('TextView').textMatches(/.*后可领取.*|已成功领取奖励|已完成.*/).boundsInside(0, 0, device.width / 2, 500).visibleToUser(true).findOne(1000);
  445. if (okbtn) {
  446. i++;
  447. console.log(m + '.1.' + i);
  448. var b = okbtn.text().match(/^\d+/);
  449. var t = 1 * (b ? b[0] : 1) + random(5, 9);
  450. cutDownBySleep(t, m);
  451. //点击左上角或back()
  452. click(okbtn.bounds());
  453. sleep(1000);
  454. stopvideo(m);
  455. }
  456. var liveing = idMatches(/.*live_close_container/).boundsInside(device.width - 500, 0, device.width, 500).visibleToUser(true).findOne(1000);
  457. if (liveing) {
  458. toastLog('已进入2:' + tip);
  459. sleep(5000);
  460. var videoDuration = 0;
  461. var durationText = idMatches(/.*neo_count_down_text/).visibleToUser(true).findOne(1000);
  462. if (durationText) {
  463. videoDuration = getDouyinVideoDuration(durationText.text());
  464. }
  465. var sleepTime = (videoDuration > 0 && videoDuration < 90) ? videoDuration : random(6, 30);
  466. cutDownBySleep(sleepTime, tip);
  467. click(liveing.bounds());
  468. sleep(1000);
  469. stoplive(m);
  470. }
  471. okbtn = className('TextView').textMatches(/退出.*|放弃奖励|已成功领取奖励/).visibleToUser(true).findOne(1000);
  472. if (okbtn) {
  473. click(okbtn.bounds());
  474. } else {
  475. back();
  476. }
  477. btn = textMatches(/已完成.*/).visibleToUser(true).findOne(1000);
  478. if (btn) { if (percent(btn.text())) { toastLog(m + btn.text()); idMatches(/.*left_btn/).desc("返回").clickable(true).click(); return; } }
  479. sleep(2000);
  480. }
  481. }
  482. }
  483. view.scrollForward(); sleep(3000);
  484. view = className('android.widget.ScrollView').visibleToUser(true).findOne(1000);
  485. }
  486. }
  487. }
  488.  
  489. //返回
  490. if (!textMatches(/金币暴涨|我的现金/).visibleToUser(true).findOne(1000)) {
  491. back(); sleep(1000);
  492. var btn = className('TextView').text('放弃奖励').visibleToUser(true).findOne(1000);
  493. if (btn) { click(btn.bounds()); sleep(1000); }
  494. gotask();
  495. sleep(1000);
  496. }
  497. console.error('循环赚金币结束playvideo');
  498. working = false;
  499. }
  500.  
  501.  
  502. //主程序函数===============================================================
  503. function Main() {
  504. var loopTimes = random(3, 5); //work循环次数
  505. function work() {
  506. toastLog("开始工作work");
  507. var listArray = tasklist();
  508. if (listArray.length > 0) {
  509. sleep(3000);
  510. toastLog('开始做任务');
  511. for (i = 0; i < listArray.length; i++) {
  512. if (listArray[i][1]) {
  513. toastLog(i + '.' + listArray[i][0]);
  514. //点击任务,这里不可以用坐标点击,因为有的条目可能会在屏幕外面
  515. listArray[i][1].click();
  516. sleep(1000);
  517. playvideo(listArray[i][0]);
  518. }
  519. }
  520. } else {
  521. toastLog('任务装载失败,需要重启软件');
  522. sleep(2000);
  523. return;
  524. }
  525. //开宝箱
  526. moneybox();
  527. //回到首页准备刷视频
  528. console.error("开始刷视频模式+++++++++++++");
  529. gohome(); startSec = Date.now(); gogogo(999);
  530. console.error("刷视频模式结束+++++++++++++");
  531. }
  532. //打开快手App
  533. if (getPackageName(AppName)) {
  534. openApp(AppName);
  535. //等待进入主界面成功
  536. toastLog('进入主函数' + ver);
  537. gohome();
  538. sleep(3000);
  539. toastLog("刚启动先刷视频提高活跃度");
  540. startSec = Date.now();
  541. gogogo(999);
  542.  
  543. while (loopTimes > 0) {
  544. gotask();
  545. work();//开始工作
  546. //由于看广告得金币进度不刷新,所以需要重启软件
  547. sleep(1000);
  548. closeApp(AppName);
  549. sleep(5000);
  550. openApp(AppName);
  551. sleep(3000);
  552. loopTimes--;
  553. }
  554.  
  555. console.clear();
  556. console.warn('运行结束关闭应用');
  557. } else {
  558. console.warn("未安装:" + AppName);
  559. work_thread.interrupt();
  560. device.cancelKeepingAwake();
  561. engines.myEngine().forceStop();
  562. return;
  563. }
  564. console.show();
  565. console.warn('执行完成用时' + SecondsToHMS((Date.now() - starttime) / 1000));
  566. cutDownBySleep(5, '5秒后进入息屏挂机模式');
  567. console.hide();
  568. closeApp(AppName);
  569. sleep(3000);
  570. oled(random(600, 900));//熄屏挂机约10~15分钟左右
  571. }
  572. function getHomeBtn() {
  573. var homepage = idMatches(/.*left_btn|.*thanos_home_top_search/).clickable(true).boundsInside(0, 0, 500, 500).visibleToUser(true).findOne(1000);
  574. var topbtn = descMatches(/发现|关注/).selected(true).boundsInside(0, 0, device.width, 500).visibleToUser(true).findOne(1000);
  575. return (homepage != null && topbtn != null);
  576. }
  577. function gohome() {
  578. function closediv() {
  579. toastLog('检测关闭弹出层');
  580. //关闭弹出层
  581. var btn = className('TextView').text('放弃奖励').visibleToUser(true).findOne(1000);
  582. if (btn) { click(btn.bounds()); sleep(1000); }
  583. var popdiv = className('Image').text('huge_sign_marketing_popup').visibleToUser(true).findOne(1000);
  584. if (popdiv) { click(popdiv.parent().parent().child(0).bounds()); sleep(1000); }
  585. var liveing = idMatches(/.*live_close_container/).boundsInside(0, 0, device.width, 500).visibleToUser(true).findOne(2000);
  586. if (liveing) {
  587. click(liveing.bounds()); sleep(1000);
  588. let okbtn = className('TextView').textMatches(/.*退出.*/).visibleToUser(true).findOne(1000);
  589. if (okbtn) { click(okbtn.bounds()); sleep(1000); }
  590. }
  591. }
  592. toastLog('回到首页gohome');
  593. closediv();
  594. var homepage = idMatches(/.*left_btn|.*thanos_home_top_search/).clickable(true).boundsInside(0, 0, 500, 500).visibleToUser(true).findOne(1000);
  595. if (!homepage) {
  596. var MaxLoop = 5;
  597. while (!homepage && MaxLoop > 0) {
  598. MaxLoop--;
  599. back(); sleep(3000); closediv();
  600. var okbtn = className('TextView').textMatches(/退出.*/).visibleToUser(true).findOne(1000);
  601. if (okbtn) { okbtn.click(); sleep(3000); }
  602. homepage = idMatches(/.*left_btn|.*thanos_home_top_search/).clickable(true).boundsInside(0, 0, 500, 500).visibleToUser(true).findOne(1000);
  603. }
  604. }
  605. if (homepage) {
  606. var btn = idMatches(/.*textView/).desc("发现").visibleToUser(true).findOne(1000);
  607. if (btn) { click(btn.bounds()); sleep(3000); }
  608. } else {
  609. toastLog('需要重启软件【截图】');
  610. //截图保存界面,以备后续查看
  611. captureScreen(files.getSdcardPath() + '/脚本/gohome1_' + currentActivity() + '.jpg');
  612. sleep(1000);
  613. device.wakeUp();//唤醒设备
  614. sleep(1000);
  615. left2right(1);
  616. sleep(1000);
  617. closeApp(AppName);
  618. sleep(5000);
  619. openApp(AppName);
  620. sleep(1000);
  621. }
  622. }
  623. function gotask() {
  624. let moneybtn = className('androidx.appcompat.app.ActionBar$c').desc('去赚钱').clickable(true).boundsInside(device.width / 2, device.height - 300, device.width, device.height).visibleToUser(true).findOne(1000);
  625. if (!moneybtn) {
  626. gohome();
  627. moneybtn = className('androidx.appcompat.app.ActionBar$c').desc('去赚钱').clickable(true).boundsInside(device.width / 2, device.height - 300, device.width, device.height).visibleToUser(true).findOne(1000);
  628. }
  629. if (moneybtn) {
  630. console.error('点击去赚钱gotask');
  631. click(moneybtn.bounds());
  632. }
  633. }
  634. function weightedRandom(weights) {
  635. let sum = 0;
  636. for (let key in weights) {
  637. sum += weights[key];
  638. }
  639. let randomNumber = Math.random() * sum;
  640. for (let key in weights) {
  641. randomNumber -= weights[key];
  642. if (randomNumber <= 0) {
  643. return key;
  644. }
  645. }
  646. }
  647. function randomHeart(num) {
  648. if (idMatches(/.*center/).text('请完成安全验证').visibleToUser(true).findOne(1000)) { return; }
  649. const weights = {
  650. 1: 0.01, 2: 0.02, 3: 0.03, 4: 0.04, 5: 0.05,
  651. 6: 0.06, 7: 0.07, 8: 0.08, 9: 0.09, 0: 0.55
  652. };
  653. let randomIndex = num ? num : weightedRandom(weights);
  654. //随机下滑
  655. if (randomIndex == 1) {
  656. console.log('拟人:随机下滑');
  657. swipe(device.width / 2, device.height * 0.1 + randomIndex, device.width / 2, device.height * 0.9 - randomIndex, random(500, 1500));
  658. return;
  659. }
  660. //连续上滑
  661. if (randomIndex == 2) {
  662. console.log('拟人:连续上滑');
  663. var k = random(2, 4);
  664. for (var i = 0; i < k; i++) {
  665. var j = random(2, 5);
  666. if (j == 3) {
  667. swipe(device.width / j, device.height * 0.2 + j * k, device.width / j, device.height * 0.8 - j * k, j * 50);
  668. } else {
  669. swipe(device.width / j, device.height * 0.8 - j * k, device.width / j, device.height * 0.2 + j * k, j * 50);
  670. }
  671. sleep(j * 250);
  672. }
  673. return;
  674. }
  675.  
  676. //随机恢复到首页
  677. if (randomIndex == 4) {
  678. console.log('拟人:随机回首页');
  679. gohome();
  680. return;
  681. }
  682. //加速播放
  683. if (randomIndex == 5) {
  684. var seekBar = className('android.widget.SeekBar').descMatches(/.*进度条.*/).findOne(1000);
  685. if (seekBar) {
  686. let x1 = random(90, 120);
  687. let y1 = device.height / 3;
  688. gestures([0, 1500, [x1, y1], [x1, y1]], [1400, 1500, [x1, y1], [1.1 * x1, 2 * y1]]);
  689. return;
  690. }
  691. }
  692.  
  693. //随机收藏
  694. if (randomIndex == 7) {
  695. var collect = idMatches(/.*click_area_collect/).clickable(true).boundsInside(device.width - 500, device.height / 2, device.width, device.height).visibleToUser(true).findOne(1000);
  696. if (collect) {
  697. console.log('拟人:随机收藏');
  698. click(collect.bounds());
  699. sleep(3000);
  700. slidingByCurve();
  701. return;
  702. }
  703. }
  704. //随机评论
  705. if (randomIndex == 8) {
  706. var plug = idMatches(/.*comment_element_click_layout/).longClickable(true).boundsInside(device.width - 500, device.height / 2, device.width, device.height).visibleToUser(true).findOne(1000);
  707. if (plug) {
  708. console.log('拟人:随机评论');
  709. //长按评论按钮
  710. longClick(plug.bounds());
  711. sleep(1000);
  712. var plugdiv = idMatches(/.*emoji_quick_send_list/).visibleToUser(true).findOne(1000);
  713. if (plugdiv) {
  714. let emoji = plugdiv.find(className('ImageView'));
  715. let icoY = emoji[0].bounds().centerY();
  716. let icoX = [
  717. emoji[0].bounds().centerX(),
  718. emoji[1].bounds().centerX(),
  719. emoji[2].bounds().centerX(),
  720. emoji[3].bounds().centerX()
  721. ];
  722. let index = random(2, icoX.length) - 1;
  723. //console.log(icoX[index],icoY);
  724. click(icoX[index], icoY);
  725. sleep(3000);
  726. slidingByCurve();
  727. return;
  728. }
  729. }
  730. }
  731. //随机点赞
  732. if (randomIndex == 9) {
  733. var like = idMatches(/.*like_element_click_layout/).clickable(true).boundsInside(device.width - 500, device.height / 2, device.width, device.height).visibleToUser(true).findOne(1000);
  734. if (like) {
  735. console.log('拟人:随机点赞');
  736. click(like.bounds());
  737. sleep(3000);
  738. slidingByCurve();
  739. return;
  740. }
  741. }
  742. //上滑
  743. slidingByCurve();
  744. }
  745. function isvideoPage() {
  746. console.verbose("检测是否视频播放中isvideoPage");
  747. var isvideo = false;
  748. var homepage = getHomeBtn();
  749. if (homepage) {
  750. //关闭自动弹出的层
  751. var div1 = idMatches(/.*design_bottom_sheet.*|.*content_nest.*|.*recyclerView.*/).visibleToUser(true).findOne(1000);
  752. if (div1) {
  753. isvideo = true;
  754. toastLog('0.关闭弹出层');
  755. click(80, 150);
  756. sleep(1000);slidingByCurve();sleep(1000);
  757. }
  758. var living = idMatches(/.*live_close_container/).boundsInside(0, 0, device.width, 500).visibleToUser(true).findOne(1000);//直播间
  759. if (living) {
  760. isvideo = true;
  761. toastLog("1.退出直播间");
  762. click(living.bounds());
  763. sleep(1000);slidingByCurve();sleep(1000);
  764. var div0 = text('退出直播间').visibleToUser(true).findOne(1000);
  765. if (div0) click(div0.bounds());
  766. sleep(1000);slidingByCurve();sleep(1000);
  767. }
  768. var block = textMatches(/.*进入直播间.*/).clickable(true).visibleToUser(true).findOne(1000);
  769. if (block) {
  770. isvideo = true;
  771. slidingByCurve();
  772. sleep(2000);
  773. }
  774. isvideo = idMatches(/.*nasa_groot_view_pager/).visibleToUser(true).findOne(1000);
  775. var block = textMatches(/.*填充拼图|.*使图片角度为正|请依次点击.*/).visibleToUser(true).findOne(1000);
  776. if (block) { isvideo = false; }
  777. //log(isvideo);
  778. }
  779. return isvideo;
  780. }
  781. function gogogo(n) {
  782. let gotime = random(15, 20); //刷视频每n分钟结束一次
  783. for (var i = 1; i <= n; i++) {
  784. running = true;
  785. let flashtime = parseInt((Date.now() - startSec) / 1000);
  786. console.log('第' + i + '次刷视频,累计用时:', flashtime, '秒');
  787. if (flashtime > gotime * 60) { console.warn(gotime + '分种超时,停止刷视频'); running = false; floaty.closeAll(); break; }
  788. if (!pause) {
  789. if (isvideoPage()) {
  790. var videoDuration = 0;
  791. var seekBar = idMatches(/.*\/root/).desc('暂停视频').visibleToUser(true).findOne(1000);
  792. if (seekBar) {
  793. let duration_thread = threads.start(function () {
  794. var durationText = className('TextView').textMatches(/[0-9]+:[0-9]+/).boundsInside(device.width / 2, 2 * device.height / 3, device.width, device.height).findOne(2000);
  795. if (durationText) {
  796. videoDuration = getDouyinVideoDuration(durationText.text());
  797. }
  798. duration_thread.interrupt();
  799. });
  800. let block = className('android.widget.HorizontalScrollView').idMatches(/.*\/tab_layout/).findOne(1000);
  801. let y1 = block.bounds().top - 10;
  802. let x1 = random(300, 400);
  803. let x2 = random(600, 700);
  804. gesture(random(800, 1200), [[x1, y1], [x2, y1], [10 + x1, y1]]);
  805. console.log("视频时长:", videoDuration + 's');
  806. }
  807. var sleepTime = (videoDuration > 0 && videoDuration < 90) ? videoDuration : random(6, 30);
  808. cutDownBySleep(sleepTime, '观看视频:');//每个视频随机时间 6-30s
  809. randomHeart();//拟人化
  810. } else {
  811. running = false;
  812. toastLog('not at the video page');
  813. var dialog = currentActivity();
  814. if (!dialog.match(/android\.app\.Dialog|android\.widget\.FrameLayout|.*creenCaptureRequestActivity|.*IdentityDialogActivity|.*FaceRecognitionActivity/)) {
  815. //截图保存界面,以备后续查看
  816. console.info('【gogogo截图】', dialog);
  817. captureScreen(files.getSdcardPath() + '/脚本/gogogo_' + dialog + '.jpg');
  818. gohome();
  819. }
  820. sleep(3000);
  821. }
  822. } else {
  823. sleep(3000);
  824. i--;
  825. }
  826. }
  827. running = false;
  828. }
  829. function cutDownBySleep(lasterSecend, message) {
  830. message = message || "";
  831. floaty.closeAll();
  832. var fwin = floaty.rawWindow(
  833. `<vertical id="frame" alpha="0" w="{{device.width-500}}px" h="150px">
  834. <card id="card" w="auto" h="auto" layout_gravity="center" cardCornerRadius="5dp" cardBackgroundColor="#eeeeee" >
  835. <text id="title" text="" w="auto" textColor="#333333" textSize="13sp" padding="12 8" />
  836. </card>
  837. </vertical>`
  838. );
  839. fwin.setTouchable(true);
  840. fwin.frame.on("click", () => {
  841. pause = !pause;
  842. console.log(pause ? '脚本暂停:' + message : '脚本继续:' + message);
  843. fwin.card.attr("cardBackgroundColor", pause ? "#ff0000" : "#eeeeee");
  844. });
  845. sleep(500);
  846. for (let i = lasterSecend; i > 0; i--) {
  847. if (!running && !working) { log('sleep1', running, working); break; }
  848. if (!fwin || !fwin.title) { log('sleep2', fwin, fwin.title); break; }
  849. if (pause) { i++; }
  850. ui.run(() => {
  851. fwin.title.setText(pause ? '脚本已暂停,点击继续' : message + "剩余" + i + "秒");
  852. fwin.frame.attr("alpha", 0.8);
  853. let x = parseInt((device.width - fwin.width) / 2);
  854. let y = device.height - 550;
  855. fwin.setPosition(x, y);
  856. });
  857. sleep(1000);
  858. }
  859. fwin = null;
  860. floaty.closeAll();
  861. sleep(500);
  862. }
  863. function getDouyinVideoDuration(durationStr) {
  864. if (durationStr) {
  865. //log('1',durationStr);
  866. var durationMatch = durationStr.match(/[0-9]+:[0-9]+/);
  867. if (durationMatch) {
  868. //log('2',durationMatch);
  869. var minutes = 0, seconds = 0;
  870. var parts = durationMatch[0].split(":");
  871. if (parts.length === 2) {
  872. //log('3',parts);
  873. let minutes = parseInt(parts[0], 10);
  874. let seconds = parseInt(parts[1], 10);
  875. return minutes * 60 + seconds;
  876. }
  877. }
  878. }
  879. return 0;
  880. }
  881. function percent(str) {
  882. var strMatch = str.match(/[0-9]+\/[0-9]+/);
  883. if (strMatch) {
  884. var parts = strMatch[0].split("/");
  885. if (parts.length === 2) {
  886. let a = parseInt(parts[0], 10);
  887. let b = parseInt(parts[1], 10);
  888. return a == b;
  889. }
  890. } else {
  891. return true;
  892. }
  893. return false;
  894. }
  895. function slidingByLine() {
  896. // top X,Y范围
  897. tx = randomPointLoc(parseInt(device.width / 3), parseInt(device.width / 2));
  898. ty = randomPointLoc(parseInt(device.height / 5), parseInt(device.height / 4));
  899. // bottom X,Y 范围
  900. bx = randomPointLoc(parseInt(device.width / 3), parseInt(device.width / 2));
  901. by = randomPointLoc(parseInt(3 * device.height / 4), parseInt(4 * device.height / 5));
  902.  
  903. slidingTime = randomRangeTime(0.8, 1.3);
  904. log("上滑:随机直线");
  905. //log("X: "+ Math.abs(bx-tx) + " Y: "+ Math.abs(by - ty));
  906. swipe(bx, by, tx, ty, slidingTime);
  907. }
  908. function left2right(direction) {
  909. var intX = parseInt(Math.random() * 200 + 400);
  910. var intY = parseInt(Math.random() * 200 + 200);
  911. var distance = parseInt(Math.random() * 100 + device.height / 4);
  912. switch (direction) {
  913. case 1:
  914. //向上小距离
  915. sml_move(intX, intY + distance, intX, intY, 400);
  916. break;
  917. case 2:
  918. //向下小距离
  919. sml_move(intX, intY, intX, intY + distance, 400);
  920. break;
  921. case 3:
  922. //向左翻屏
  923. sml_move(
  924. device.width / 2 + parseInt(Math.random() * 100) + 300,
  925. device.height / 4 - parseInt(Math.random() * 200) + 100,
  926. 0 + parseInt(Math.random() * 100),
  927. device.height / 5 + parseInt(Math.random() * 100),
  928. 500
  929. );
  930. break;
  931. case 4:
  932. //向右翻屏
  933. sml_move(
  934. device.width / 2 - parseInt(Math.random() * 100) - 300,
  935. device.height / 5 - parseInt(Math.random() * 200) + 100,
  936. device.width - parseInt(Math.random() * 100),
  937. device.height / 4 + parseInt(Math.random() * 100),
  938. 500
  939. );
  940. break;
  941. }
  942. sleep(1000);
  943. }
  944. function slidingByCurve() {
  945. if (idMatches(/.*center/).text('请完成安全验证').visibleToUser(true).findOne(1000)) { log('正在完成安全验证'); return; }
  946. // top X,Y范围
  947. tx = randomPointLoc(parseInt(device.width / 3), parseInt(device.width / 2));
  948. ty = randomPointLoc(200, 300);
  949. // bottom X,Y 范围
  950. bx = randomPointLoc(parseInt(device.width / 3), parseInt(device.width / 2));
  951. by = randomPointLoc(device.height - 500, device.height - 400);
  952.  
  953. slidingTime = randomRangeTime(0.5, 0.9);
  954. log("上滑:仿真曲线");
  955. //log("X: "+ Math.abs(bx-tx) + " Y: "+ Math.abs(by - ty));
  956. sml_move(bx, by, tx, ty, slidingTime);
  957. }
  958. function randomPointLoc(start, end) {
  959. len = Math.abs(end - start);
  960. loc = Math.floor(Math.random() * len) + start;
  961. return loc;
  962. }
  963. function randomRangeTime(start, end) {
  964. len = Math.abs(end - start) * 1000;
  965. ms = Math.floor(Math.random() * len) + start * 1000;
  966. return ms;
  967. }
  968. function radmoRect(rect) {
  969. let xy = rect;
  970. if (rect) {
  971. xy.left = random(100, rect.width() - 100);
  972. xy.top = random(100, rect.height() - 100);
  973. xy.bottom = xy.top + 120;
  974. xy.right = xy.left + 120;
  975. }
  976. return xy;
  977. }
  978. function sml_move(qx, qy, zx, zy, time) {
  979. var xxy = [time];
  980. var point = [];
  981. var dx0 = { "x": qx, "y": qy };
  982. var dx1 = { "x": random(qx - 100, qx + 100), "y": random(qy, qy + 50) };
  983. var dx2 = { "x": random(zx - 100, zx + 100), "y": random(zy, zy + 50) };
  984. var dx3 = { "x": zx, "y": zy };
  985. for (var i = 0; i < 4; i++) {
  986. eval("point.push(dx" + i + ")");
  987. }
  988. // log(point[3].x)
  989. for (let i = 0; i < 1; i += 0.08) {
  990. let newPoint = bezier_curves(point, i);
  991. xxyy = [parseInt(newPoint.x), parseInt(newPoint.y)]
  992. xxy.push(xxyy);
  993. }
  994. try {
  995. gesture.apply(null, xxy);
  996. } catch (e) {
  997. log('error:', xxy);
  998. }
  999. }
  1000. function bezier_curves(cp, t) {
  1001. cx = 3.0 * (cp[1].x - cp[0].x);
  1002. bx = 3.0 * (cp[2].x - cp[1].x) - cx;
  1003. ax = cp[3].x - cp[0].x - cx - bx;
  1004. cy = 3.0 * (cp[1].y - cp[0].y);
  1005. by = 3.0 * (cp[2].y - cp[1].y) - cy;
  1006. ay = cp[3].y - cp[0].y - cy - by;
  1007. tSquared = t * t;
  1008. tCubed = tSquared * t;
  1009. result = { "x": 0, "y": 0 };
  1010. result.x = (ax * tCubed) + (bx * tSquared) + (cx * t) + cp[0].x;
  1011. result.y = (ay * tCubed) + (by * tSquared) + (cy * t) + cp[0].y;
  1012. return result;
  1013. }
  1014. function SecondsToHMS(seconds) {
  1015. const hours = Math.floor(seconds / 3600);
  1016. const minutes = Math.floor((seconds % 3600) / 60);
  1017. const remainingSeconds = Math.floor(seconds % 60);
  1018. return (hours > 0 ? hours + "时" : "") + (minutes > 0 ? minutes + "分" : "") + remainingSeconds + "秒";
  1019. }
  1020. function getindexInParent(child) {
  1021. var parent = child.parent();
  1022. for (var i = 0; i < parent.childCount(); i++) {
  1023. if (parent.child(i).find(className('CheckBox').checked(true).visibleToUser(true)).length > 0) {
  1024. return i;
  1025. }
  1026. }
  1027. return -1; // 如果找不到子元素,则返回-1
  1028. }
  1029. function isRectInScreen(bounds) {
  1030. var x = bounds.left, y = bounds.top,
  1031. a = bounds.right, b = bounds.bottom;
  1032. return (
  1033. x >= 0 && x <= device.width &&
  1034. y >= 0 && y <= device.height &&
  1035. a > 0 && a <= device.width &&
  1036. b > 0 && b <= device.height
  1037. );
  1038. }
  1039. function openApp(appname) {
  1040. console.warn('启动应用:' + appname);
  1041. var appstate = launchApp(appname);
  1042. sleep(5000);
  1043. if (appstate) {
  1044. toastLog("应用正在运行");
  1045. } else {
  1046. toastLog("无法自启动,需模拟点击");
  1047. home();//要启动的APP必须放在第一页中
  1048. sleep(3000);
  1049. var app = id("item_title").text(appname).visibleToUser(true).findOne(2000);
  1050. if (app) {
  1051. click(app.bounds().centerX(), app.bounds().top - 50);
  1052. sleep(8000);
  1053. } else {
  1054. toastLog('要启动的APP必须放在首页,即按Home能看到的那一页');
  1055. work_thread.interrupt();
  1056. engines.myEngine().forceStop();
  1057. exit();
  1058. }
  1059. }
  1060. }
  1061. function closeApp(appname) {
  1062. let packageName = getPackageName(appname);
  1063. // 使用ADB命令强行结束进程
  1064. //shell("adb shell am force-stop " + packageName);
  1065. console.warn('关闭应用:' + appname);
  1066. app.openAppSetting(packageName);
  1067. text(app.getAppName(packageName)).waitFor();
  1068. let is_sure = textMatches(/.*强行停止.*/).visibleToUser(true).findOne(1000);
  1069. if (is_sure && is_sure.enabled()) {
  1070. try {
  1071. var btn = className("Button").text('强行停止').visibleToUser(true).findOne(1000);
  1072. if (btn) btn.click();
  1073. sleep(1000);
  1074. btn = className("Button").text('强行停止').visibleToUser(true).findOne(1000);
  1075. if (btn) btn.click();
  1076. sleep(1000);
  1077. btn = className("Button").text('确定').visibleToUser(true).findOne(1000);
  1078. if (btn) btn.click();
  1079. back(); back(); back();
  1080. home();
  1081. } catch (e) {
  1082. log(app.getAppName(packageName) + "应用已被关闭");
  1083. sleep(1000);
  1084. back(); back(); back();
  1085. home();
  1086. }
  1087. } else {
  1088. log(app.getAppName(packageName) + "应用不能被正常关闭");
  1089. back(); back(); back();
  1090. home();
  1091. }
  1092. }
  1093. function update() {
  1094. http.get('https://update.greasyfork.org/scripts/520135/%E5%BF%AB%E6%89%8B%E8%84%9A%E6%9C%AC.js', {}, function (res, err) {
  1095. if (res.statusCode == 200) {
  1096. var Source = res.body.bytes();
  1097. if (Source) {
  1098. files.writeBytes(files.getSdcardPath() + '/脚本/快手脚本.js', Source);
  1099. console.verbose('更新主程序:成功', ver);
  1100. } else {
  1101. console.verbose('更新主程序:错误', ver);
  1102. }
  1103. } else {
  1104. console.verbose('更新主程序:失败', ver);
  1105. }
  1106. });
  1107. }
  1108.  
  1109.  
  1110. importClass(org.opencv.imgproc.Imgproc);
  1111. importClass(org.opencv.core.Core);
  1112. importClass(org.opencv.core.Rect);
  1113. importClass(org.opencv.core.Mat);
  1114. importClass(org.opencv.core.Point);
  1115. importClass(org.opencv.core.Size);
  1116. importClass(org.opencv.core.CvType);
  1117. importClass(org.opencv.core.Scalar);
  1118. importClass(org.opencv.imgcodecs.Imgcodecs);
  1119.  
  1120. /**
  1121. * @param {number[]} region 是一个两个或四个元素的数组。
  1122. * (region[0], region[1])表示找色区域的左上角;region[2]*region[3]表示找色区域的宽高。如果只有region只有两个元素,则找色区域为(region[0], region[1])到屏幕右下角。
  1123. * 如果不指定region选项,则找色区域为整张图片。
  1124. * @param {*} img
  1125. * @returns {org.opencv.core.Rect}
  1126. */
  1127. function buildRegion(region, img) {
  1128. if (region == undefined) { region = []; }
  1129. let x = region[0] === undefined ? 0 : region[0];
  1130. let y = region[1] === undefined ? 0 : region[1];
  1131. let width = region[2] === undefined ? img.getWidth() - x : region[2];
  1132. let height = region[3] === undefined ? img.getHeight() - y : region[3];
  1133. if (x < 0 || y < 0 || x + width > img.width || y + height > img.height) {
  1134. throw new Error(
  1135. 'out of region: region = [' + [x, y, width, height] + '], image.size = [' + [img.width, img.height] + ']'
  1136. );
  1137. }
  1138. return new Rect(x, y, width, height);
  1139. }
  1140.  
  1141. /**
  1142. * @param {number} threshold 图片相似度。取值范围为0~1的浮点数。默认值为0.9
  1143. * @param {number[]} region 找图区域
  1144. * @param {number[]} scaleFactors 大图的宽高缩放因子,默认为 [1, 0.9, 1.1, 0.8, 1.2]
  1145. * @param {number} max 找图结果最大数量,默认为5
  1146. * @param {boolean} grayTransform 是否进行灰度化预处理,默认为true。
  1147. * 通常情况下将图像转换为灰度图可以简化匹配过程并提高匹配的准确性,当然,如果你的匹配任务中颜色信息对匹配结果具有重要意义,
  1148. * 可以跳过灰度化步骤,直接在彩色图像上进行模板匹配。
  1149. */
  1150. function MatchOptions(threshold, region, scaleFactors, max, grayTransform) {
  1151. this.threshold = threshold;
  1152. this.region = region;
  1153. this.scaleFactors = scaleFactors;
  1154. this.max = max;
  1155. this.grayTransform = grayTransform;
  1156. }
  1157.  
  1158. const defaultMatchOptions = new MatchOptions(0.9, undefined, [[1, 1], [0.9, 0.9], [1.1, 1.1], [0.8, 0.8], [1.2, 1.2]], 5, true);
  1159. // 校验参数
  1160. MatchOptions.check = function (options) {
  1161. if (options == undefined) {
  1162. return defaultMatchOptions;
  1163. }
  1164. // deep copy
  1165. let newOptions = JSON.parse(JSON.stringify(options));
  1166. if (newOptions.threshold == undefined) {
  1167. newOptions.threshold = defaultMatchOptions.threshold;
  1168. }
  1169. if (newOptions.region && !Array.isArray(newOptions.region)) {
  1170. throw new TypeError('region type is number[]');
  1171. }
  1172. if (newOptions.max == undefined) {
  1173. newOptions.max = defaultMatchOptions.max;
  1174. }
  1175. if (newOptions.scaleFactors == undefined) {
  1176. newOptions.scaleFactors = defaultMatchOptions.scaleFactors;
  1177. } else if (!Array.isArray(newOptions.scaleFactors)) {
  1178. throw new TypeError('scaleFactors');
  1179. }
  1180. for (let index = 0; index < newOptions.scaleFactors.length; index++) {
  1181. let factor = newOptions.scaleFactors[index];
  1182. if (Array.isArray(factor) && factor[0] > 0 && factor[1] > 0) {
  1183. // nothing
  1184. } else if (typeof factor === 'number') {
  1185. newOptions.scaleFactors[index] = [factor, factor];
  1186. } else {
  1187. throw new TypeError('scaleFactors');
  1188. }
  1189. }
  1190. if (newOptions.grayTransform === undefined) {
  1191. newOptions.grayTransform = defaultMatchOptions.grayTransform;
  1192. }
  1193.  
  1194. return newOptions;
  1195. };
  1196.  
  1197. function Match(point, similarity, scaleX, scaleY) {
  1198. this.point = point;
  1199. this.similarity = similarity;
  1200. this.scaleX = scaleX;
  1201. this.scaleY = scaleY;
  1202. }
  1203.  
  1204. /**
  1205. * 找图,在图中找出所有匹配的位置
  1206. * @param {Image} img
  1207. * @param {Image} template
  1208. * @param {MatchOptions} options 参数见上方定义
  1209. * @returns {Match[]}
  1210. */
  1211. function matchTemplate(img, template, options) {
  1212. if (img == null || template == null) {
  1213. throw new Error('ParamError');
  1214. }
  1215. options = MatchOptions.check(options);
  1216. //console.log('参数:', options);
  1217.  
  1218. let largeMat = img.mat;
  1219. let templateMat = template.mat;
  1220. let largeGrayMat;
  1221. let templateGrayMat;
  1222. if (options.region) {
  1223. options.region = buildRegion(options.region, img);
  1224. largeMat = new Mat(largeMat, options.region);
  1225. }
  1226. // 灰度处理
  1227. if (options.grayTransform) {
  1228. largeGrayMat = new Mat();
  1229. Imgproc.cvtColor(largeMat, largeGrayMat, Imgproc.COLOR_BGR2GRAY);
  1230. templateGrayMat = new Mat();
  1231. Imgproc.cvtColor(templateMat, templateGrayMat, Imgproc.COLOR_BGR2GRAY);
  1232. }
  1233. // =================================================
  1234. let finalMatches = [];
  1235. for (let factor of options.scaleFactors) {
  1236. let [fx, fy] = factor;
  1237. let resizedTemplate = new Mat();
  1238. Imgproc.resize(templateGrayMat || templateMat, resizedTemplate, new Size(), fx, fy, Imgproc.INTER_LINEAR);
  1239. // 执行模板匹配,标准化相关性系数匹配法
  1240. let matchMat = new Mat();
  1241. Imgproc.matchTemplate(largeGrayMat || largeMat, resizedTemplate, matchMat, Imgproc.TM_CCOEFF_NORMED);
  1242.  
  1243. let currentMatches = _getAllMatch(matchMat, resizedTemplate, options.threshold, factor, options.region);
  1244. //console.log('缩放比:', factor, '可疑目标数:', currentMatches.length);
  1245. for (let match of currentMatches) {
  1246. if (finalMatches.length === 0) {
  1247. finalMatches = currentMatches.slice(0, options.max);
  1248. break;
  1249. }
  1250. if (!isOverlapping(finalMatches, match)) {
  1251. finalMatches.push(match);
  1252. }
  1253. if (finalMatches.length >= options.max) {
  1254. break;
  1255. }
  1256. }
  1257. resizedTemplate.release();
  1258. matchMat.release();
  1259. if (finalMatches.length >= options.max) {
  1260. break;
  1261. }
  1262. }
  1263. largeMat !== img.mat && largeMat.release();
  1264. largeGrayMat && largeGrayMat.release();
  1265. templateGrayMat && templateGrayMat.release();
  1266.  
  1267. return finalMatches;
  1268. }
  1269.  
  1270. function _getAllMatch(tmResult, templateMat, threshold, factor, rect) {
  1271. let currentMatches = [];
  1272. let mmr = Core.minMaxLoc(tmResult);
  1273.  
  1274. while (mmr.maxVal >= threshold) {
  1275. // 每次取匹配结果中的最大值和位置,从而使结果按相似度指标从高到低排序
  1276. let pos = mmr.maxLoc; // Point
  1277. let value = mmr.maxVal;
  1278.  
  1279. let start = new Point(Math.max(0, pos.x - templateMat.width() / 2), Math.max(0, pos.y - templateMat.height() / 2));
  1280. let end = new Point(
  1281. Math.min(tmResult.width() - 1, pos.x + templateMat.width() / 2),
  1282. Math.min(tmResult.height() - 1, pos.y + templateMat.height() / 2)
  1283. );
  1284. // 屏蔽已匹配到的区域
  1285. Imgproc.rectangle(tmResult, start, end, new Scalar(0), -1);
  1286. mmr = Core.minMaxLoc(tmResult);
  1287.  
  1288. if (rect) {
  1289. pos.x += rect.x;
  1290. pos.y += rect.y;
  1291. start.x += rect.x;
  1292. start.y += rect.y;
  1293. end.x += rect.x;
  1294. end.y += rect.y;
  1295. }
  1296. let match = new Match(pos, value, factor[0], factor[1]);
  1297. // 保存匹配点的大致范围,用于后续去重。设置enumerable为false相当于声明其为私有属性
  1298. Object.defineProperty(match, 'matchAroundRect', { value: new Rect(start, end), writable: true, enumerable: false });
  1299. currentMatches.push(match);
  1300. }
  1301.  
  1302. return currentMatches;
  1303. }
  1304.  
  1305. /**
  1306. * 判断新检测到的点位是否与之前的某个点位重合。
  1307. * @param {Match[]} matches
  1308. * @param {Match} newMatch
  1309. * @returns {boolean}
  1310. */
  1311. function isOverlapping(matches, newMatch) {
  1312. for (let existingMatch of matches) {
  1313. // 也可判断两点间的距离,但是平方、开方运算不如比较范围简单高效
  1314. if (existingMatch.matchAroundRect.contains(newMatch.point)) {
  1315. if (newMatch.similarity > existingMatch.similarity) {
  1316. existingMatch.point = newMatch.point;
  1317. existingMatch.similarity = newMatch.similarity;
  1318. existingMatch.scaleX = newMatch.scaleX;
  1319. existingMatch.scaleY = newMatch.scaleY;
  1320. existingMatch.matchAroundRect = newMatch.matchAroundRect;
  1321. }
  1322. return true;
  1323. }
  1324. }
  1325. return false;
  1326. }
  1327. /**
  1328. * 根据搜图结果在原图上画框
  1329. * @param {Match[]} matches
  1330. * @param {*} srcMat
  1331. * @param {*} templateMat
  1332. */
  1333. function showMatchRectangle(matches, srcMat, templateMat) {
  1334. for (let match of matches) {
  1335. let start = match.point;
  1336. let end = new Point(
  1337. match.point.x + templateMat.width() * match.scaleX,
  1338. match.point.y + templateMat.height() * match.scaleY
  1339. );
  1340. Imgproc.rectangle(srcMat, start, end, new Scalar(0, 0, 255), 3);
  1341. }
  1342.  
  1343. const saveName = '/sdcard/Download/temp.jpg';
  1344. let img2 = images.matToImage(srcMat);
  1345. images.save(img2, saveName);
  1346. app.viewFile(saveName);
  1347. img2.recycle();
  1348. }
  1349.  
  1350. /** 图像识别定位
  1351. * @param {images} templateImage64 预定的搜索模板图片base64
  1352. * @param {images} ScreenImage 被搜索图片,如果不提供则全屏截图
  1353. * @param {number[]} option 配置参数
  1354. * @return {result[]}[ { point: {27.0, 1615.0}, similarity: 1, scaleX: 1, scaleY: 1 } ]
  1355. * @return {bounds{}}{ left: 27,top: 1615,right: 157,bottom: 1745,centerX: 92,centerY: 1680 }
  1356. //option:{ threshold: 0.85, region: [0, 0], grayTransform: true, max: 3 }
  1357. //img_block region: [device.width / 2, 200, device.width / 2, device.height / 3],grayTransform:true,
  1358. */
  1359. function FindPicture(tempBase64, ScreenImage) {
  1360. let templateImage64 = '', options = null;
  1361. if (tempBase64 == 'img_block') {
  1362. if (!img_block) return;
  1363. templateImage64 = img_block;
  1364. options = { threshold: 0.8, region: [device.width / 2, 200, device.width / 2, device.height / 3], grayTransform: true, max: 3 };
  1365. } else {
  1366. return;
  1367. }
  1368.  
  1369. let largeImage = ScreenImage ? ScreenImage : captureScreen();
  1370. let template = images.fromBase64(templateImage64);
  1371. //images.read(files.getSdcardPath() + '/脚本/template.jpg');
  1372.  
  1373. //console.log('大图尺寸:', [largeImage.getWidth(), largeImage.getHeight()]);
  1374. //console.log('模板尺寸:', [template.getWidth(), template.getHeight()]);
  1375. let bounds = null;
  1376. let startTs = Date.now();
  1377. let result = matchTemplate(largeImage, template, options);
  1378. if (result.length > 0) {
  1379. let left = result[0].point.x;
  1380. let top = result[0].point.y;
  1381. let right = parseInt(left + template.getWidth() * result[0].scaleX);
  1382. let bottom = parseInt(top + template.getHeight() * result[0].scaleY);
  1383. let centerX = parseInt(left + (right - left) / 2);
  1384. let centerY = parseInt(top + (bottom - top) / 2);
  1385. bounds = { left: left, top: top, right: right, bottom: bottom, centerX: centerX, centerY: centerY };
  1386. }
  1387. //console.log('识别耗时:', (Date.now() - startTs) / 1000);
  1388. console.log(tempBase64, result.length == 0 ? {} : result[0].point);
  1389. // 将结果画框展示
  1390. //showMatchRectangle(result, largeImage.mat, template.mat);
  1391. template.recycle();
  1392. setTimeout(function () { largeImage.recycle(); }, 6000);
  1393. return bounds;
  1394. }
  1395.  
  1396. /** 拖动滑块*/
  1397. function dragSlider(ax, by, br, bigimg) {
  1398. var img = bigimg;
  1399. if (!bigimg) {
  1400. var pic = images.grayscale(captureScreen());
  1401. //img = images.adaptiveThreshold(images.grayscale(pic), 255, "MEAN_C", "BINARY", 5, 10);
  1402. img = images.inRange(pic, '#000000', '#444444');
  1403. }
  1404. var newimg = images.cvtColor(img, "GRAY2RGBA");
  1405. //if(bigimg){
  1406. // images.save(newimg, files.getSdcardPath() + '/脚本/2.jpg', "jpg", 100);
  1407. // app.viewFile(files.getSdcardPath() + '/脚本/2.jpg');
  1408. //}
  1409. var t = random(1234, 2234);
  1410. var xy = FindPicture('img_block', newimg);
  1411. //console.info("识别结果:" , xy);
  1412. if (xy) {
  1413. toastLog("识别成功:" + ax + ", " + by);
  1414. gesture(t, [ax, by], [ax + 100, by - 10], [ax + 200, by + 10], [ax + 400, by - 10], [ax + 550, by], [ax + 700, by], [xy.centerX, by - 10]);
  1415. } else if (!bigimg) {
  1416. toastLog("识别有误,二次识别");
  1417. img = images.inRange(pic, '#bbbbbb', '#ffffff');
  1418. //bigimg = images.adaptiveThreshold(images.grayscale(pic), 255, "MEAN_C", "BINARY", 5, 10);
  1419. dragSlider(ax, by, br, img);
  1420. } else {
  1421. toastLog("识别有误,尝试滑动");
  1422. gesture(t, [ax, by], [ax + 150, by + 10], [ax + 250, by - 10], [ax + 300, by], [ax + 350, by], [ax + 500, by + 10], [br - 150, by - 10]);
  1423. }
  1424. }
  1425.  
  1426. //===================================================================================
  1427. requestScreenCapture(false);//请求截图权限
  1428. runtime.getImages().initOpenCvIfNeeded();//初始化OpenCv
  1429. global.starttime = Date.now();//程序运行开始时间
  1430.  
  1431. var oledwin = null, win = null;
  1432. function oled(i) {
  1433. let j = i || 3;
  1434. floaty.closeAll();
  1435. oledwin = floaty.rawWindow(
  1436. `<frame bg="#000000">
  1437. <card w="auto" h="auto" layout_gravity="center" cardBackgroundColor="#000000" >
  1438. <vertical>
  1439. <text id="texts" text="息屏挂机模式" textColor="#999999" textSize="13sp" />
  1440. <button id="button" text="退出挂机" margin="0 20" />
  1441. </vertical>
  1442. </card>
  1443. </frame>`
  1444. );
  1445. oledwin.button.on("click", function () {
  1446. console.info('手动停止挂机');
  1447. floaty.closeAll();
  1448. oledwin = null;
  1449. running = false;
  1450. });
  1451. oledwin.setSize(-1, -1);
  1452. oledwin.setTouchable(true);
  1453. sleep(300);
  1454. console.info('挂机模式开启……');
  1455. //保持脚本运行
  1456. while (j > 0 && oledwin) {
  1457. if (oledwin.texts) {
  1458. let t = parseInt(j / 60) + "分" + parseInt(j % 60) + "秒";
  1459. ui.run(() => { oledwin.texts.setText("息屏挂机倒计时:" + t + "\n\n倒计时结束后重启主线程gifshow") });
  1460. }
  1461. j--;
  1462. sleep(1000);
  1463. }
  1464. floaty.closeAll();
  1465. oledwin = null;
  1466. running = false;
  1467. console.show();
  1468. console.info('挂机结束用时:', (parseInt((i - j) / 60) + "分" + parseInt((i - j) % 60) + "秒"));
  1469. }
  1470.  
  1471. function Observer() {
  1472. function unique(arr) {
  1473. let newArr = [arr[0]];
  1474. for (let i = 1; i < arr.length; i++) {
  1475. let flag = false;
  1476. for (var j = 0; j < newArr.length; j++) {
  1477. if (arr[i] == newArr[j]) {
  1478. flag = true;
  1479. break;
  1480. }
  1481. }
  1482. if (!flag) {
  1483. newArr.push(arr[i]);
  1484. }
  1485. }
  1486. return newArr;
  1487. }
  1488. var currentActis = new Array();
  1489. for (let c = 0; c < 12; c++) {//连续扫描60秒后返回结果,如果60秒停留在同一活动页面,则就要重启线程了
  1490. //检测oled挂机模式结束,则重启main线程
  1491. if (oledwin) { win = oledwin; return true; } else if (win) { win = null; return false; }
  1492. currentActis[c] = currentActivity();
  1493. //关闭自动弹出的层
  1494. var btn = idMatches(/.*\/close|.*\/tabs_panel_close/).visibleToUser(true).findOne(1000);
  1495. if (btn) {
  1496. console.log('关闭弹出层Observer');
  1497. click(btn.bounds());
  1498. sleep(1000); continue;
  1499. }
  1500. var accept = textMatches(/立即邀请|直播已结束/).visibleToUser(true).findOne(1000);
  1501. if (accept) {
  1502. console.log('退出:', accept.text());
  1503. back();
  1504. sleep(1000); continue;
  1505. }
  1506. var emoji = className('ImageView').desc('emotion').visibleToUser(true).find();
  1507. if (emoji) {
  1508. let item = emoji[random(0, 3)];
  1509. if (item) {
  1510. click(item.bounds()); sleep(500);
  1511. item = emoji[random(0, 3)];
  1512. click(item.bounds()); sleep(500);
  1513. let sendbtn = idMatches(/.*finish_button_wrapper/).visibleToUser(true).findOne(1000);
  1514. if (sendbtn) { click(sendbtn.bounds()); sleep(1000); console.warn('0.发表评论'); continue; }
  1515. } else {
  1516. emoji = idMatches(/.*item_prefabricated_word_layout/).clickable(true).visibleToUser(true).find();
  1517. if (emoji) {
  1518. item = emoji[random(0, 3)];
  1519. if (item) { click(item.bounds()); }
  1520. let sendbtn = idMatches(/.*finish_button_wrapper/).visibleToUser(true).findOne(1000);
  1521. if (sendbtn) { click(sendbtn.bounds()); sleep(1000); console.warn('1.发表评论'); continue; }
  1522. }
  1523. }
  1524. }
  1525. var btntxt = textMatches(/等待|忽略|禁止|单列|同意|满意|关闭|关闭应用|不在提醒|我知道了|以后再说|暂不使用|忽略提醒|仍要退出|不感兴趣|去验证|提醒我每天来领/).visibleToUser(true).findOne(1000);
  1526. if (btntxt) {
  1527. console.warn('点击:', btntxt.text());
  1528. click(btntxt.bounds());
  1529. sleep(1000); continue;
  1530. }
  1531. //currentActivity()='.*FaceRecognitionActivity';
  1532. var block = textMatches(/.*填充拼图|.*使图片角度为正|请依次点击.*/).visibleToUser(true).findOne(1000);
  1533. if (block) {
  1534. toastLog(block.text());
  1535. if (block.text().match(/请依次点击.*/)) {
  1536. let charPositions = [], bunds = [];
  1537. let textlist = block.parent().find(className('ListView'));
  1538. if (textlist) {
  1539. for (i = 0; i < textlist[0].childCount(); i++) {
  1540. let word = textlist[0].child(i).text().replace('“', '').replace('”', '');
  1541. //console.log(word);
  1542. charPositions.push(word);
  1543. }
  1544. var aa = className('android.widget.Image').textMatches(/pic\?captchaSn.*/).visibleToUser(true).findOne(1000);
  1545. let pic = images.clip(captureScreen(), aa.bounds().left, aa.bounds().top, aa.bounds().width(), aa.bounds().height());
  1546. let img = images.inRange(pic, '#000000', '#222222');
  1547. //images.save(img, files.getSdcardPath() + '/脚本/2.jpg', "jpg", 100);
  1548. //app.viewFile(files.getSdcardPath() + '/脚本/2.jpg');
  1549. const result = gmlkit.ocr(img, "zh");
  1550. console.log(result.text);
  1551. // 点击验证码中的字符
  1552. for (var i = 0; i < charPositions.length; i++) {
  1553. //console.log(charPositions);
  1554. let words = result.find(3, e => e.text == charPositions[i]);
  1555. //log(charPositions[i],words);
  1556. if (words) {
  1557. //console.log(charPositions[i],words.bounds);
  1558. bunds.push(words.bounds);
  1559. click(words.bounds.centerX() + aa.bounds().left, words.bounds.centerY() + aa.bounds().top);
  1560. } else {
  1561. let xy = radmoRect(aa.bounds());
  1562. //console.log(charPositions[i],xy);
  1563. for (j = 0; j < bunds.length; j++) {
  1564. //console.log(charPositions[i],xy,bunds[j]);
  1565. if (xy.intersect(bunds[j])) {
  1566. //console.log('有重合,重新生成',charPositions[i],xy,bunds[j]);
  1567. xy = radmoRect(aa.bounds());
  1568. j = 0;
  1569. continue;
  1570. }
  1571. }
  1572. bunds.push(xy);
  1573. click(xy.centerX() + aa.bounds().left, xy.centerY() + aa.bounds().top);
  1574. }
  1575. sleep(random(900, 1200));
  1576. }
  1577. sleep(1000);
  1578. block = textMatches(/请依次点击.*/).visibleToUser(true).findOne(1000);
  1579. if(!block)swipe(device.width / 3, device.height - 300, device.width / 2, 300, random(500, 900));
  1580. }
  1581. } else if (block.text().match(/.*使图片角度为正/)) {
  1582. var ax = block.bounds().left + 50;
  1583. var by = block.bounds().centerY();
  1584. var br = block.bounds().right - random(350, 450);
  1585. gesture(random(1234, 2234), [ax, by], [ax + 150, by + 10], [ax + 250, by - 10], [ax + 300, by], [ax + 350, by], [ax + 500, by + 10], [br, by - 10]);
  1586. sleep(1000);
  1587. block = textMatches(/.*使图片角度为正/).visibleToUser(true).findOne(1000);
  1588. if(!block)swipe(device.width / 3, device.height - 300, device.width / 2, 300, random(500, 900));
  1589. } else {
  1590. var aa = className('android.widget.Image').textMatches(/cutPic\?captchaSn.*/).visibleToUser(true).findOne(1000);
  1591. var ax = aa.bounds().centerX();
  1592. var by = block.bounds().centerY();
  1593. var br = block.bounds().right;
  1594. //console.log(ax,by,br);
  1595. dragSlider(ax, by, br);
  1596. sleep(1000);
  1597. block = textMatches(/.*填充拼图/).visibleToUser(true).findOne(1000);
  1598. if(!block)swipe(device.width / 3, device.height - 300, device.width / 2, 300, random(500, 900));
  1599. }
  1600. sleep(1000); continue;
  1601. }
  1602. sleep(1000);//这是每秒扫描一次活动页
  1603. }
  1604. //toastLog(currentActivity());
  1605. let ac = unique(currentActis);
  1606. let cc = currentActivity().match(/.*HomeActivity|.*PhotoDetailActivity|.*AwardVideoPlayActivity|.*AdKwaiRnActivity|.*app\.Dialog|android\.widget\.FrameLayout|.*ToastDialog|.*ScreenCaptureRequestActivity/);
  1607. if (ac.length == 1 && !cc) {
  1608. console.info('60秒卡顿:', ac[0]);
  1609. //截图保存界面,以备后续查看
  1610. captureScreen(files.getSdcardPath() + '/脚本/Observer2_' + currentActivity() + '.jpg');
  1611. return false;
  1612. }
  1613. return true;
  1614. }
  1615.  
  1616. // 》》》》》》》》》》》》》》》》》》》 START
  1617. work_thread = threads.start(function () {
  1618. Main();
  1619. });
  1620.  
  1621. observer_thread = threads.start(function () {
  1622. setInterval(function () {
  1623. console.verbose('--------多线程安全检测---------');
  1624. if (oledwin) { if (oledwin.texts) console.verbose(oledwin.texts.getText().split("\n").shift()); }
  1625.  
  1626. let worktime = parseInt((Date.now() - starttime) / 1000);
  1627. console.verbose("脚本连续运行:" + SecondsToHMS(worktime));
  1628. //如果运行时间超过4小时,则关闭应用,停止脚本。
  1629. if (worktime > 60 * 60 * 4) {
  1630. device.cancelKeepingAwake();
  1631. work_thread.interrupt();
  1632. console.show();
  1633. console.clear();
  1634. console.warn("脚本连续运行超4小时,终止运行!");
  1635. sleep(5000);
  1636. console.hide();
  1637. closeApp(AppName);
  1638. sleep(5000);
  1639. //熄屏
  1640. runtime.accessibilityBridge.getService().performGlobalAction(android.accessibilityservice.AccessibilityService.GLOBAL_ACTION_LOCK_SCREEN);
  1641. //停止本脚本
  1642. //engines.myEngine().forceStop();
  1643. //结束所有Autojx进程
  1644. engines.stopAll();
  1645. exit();
  1646. }
  1647. if (!Observer()) {
  1648. work_thread.interrupt();
  1649. work_thread = threads.start(function () {
  1650. toast("Main线程在5秒后重启!");
  1651. console.show();
  1652. console.clear();
  1653. console.warn("Main线程在5秒后重启!");
  1654. running = false;
  1655. sleep(5000);
  1656. if (currentPackage() == packageName) { console.hide(); closeApp(AppName); }
  1657. sleep(5000);
  1658. Main();
  1659. });
  1660. }
  1661. }, 3000);//这个时间是线程休息时间
  1662. });
  1663.  
  1664. setTimeout(function () {
  1665. //if (!files.exists(files.getSdcardPath() + '/脚本/自动上滑脚本.js')) {
  1666. http.get('https://update.greasyfork.org/scripts/521999/%E8%87%AA%E5%8A%A8%E4%B8%8A%E6%BB%91%E8%84%9A%E6%9C%AC.js', {}, function (res, err) {
  1667. if (res.statusCode == 200) {
  1668. var Source = res.body.bytes();
  1669. if (Source) {
  1670. files.writeBytes(files.getSdcardPath() + '/脚本/自动上滑脚本.js', Source);
  1671. console.verbose('更新自动上滑:成功');
  1672. } else {
  1673. console.verbose('更新自动上滑:错误');
  1674. }
  1675. } else {
  1676. console.verbose('更新自动上滑:失败');
  1677. }
  1678. });
  1679. //}
  1680. }, 30 * 1000);