Greasy Fork is available in English.

gifshowjs

自用库

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