baidujs

自用库

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/523349/1521970/baidujs.js

  1. auto.waitFor();
  2. global.AppName = "百度极速版";
  3. global.packageName = "com.baidu.searchbox.lite";
  4. global.running = false; //是否正在刷视频中
  5. global.working = false; //是否正在刷视频中
  6. global.pause = false; //是否暂停
  7. global.startSec = Date.now();//刷视频计时
  8. global.ver = 'v1.0';//版本号
  9. if (!auto.service || device.width == 0) {
  10. console.warn("2.请重新开启无障碍服务");
  11. auto.service.disableSelf();
  12. app.startActivity({ action: "android.settings.ACCESSIBILITY_SETTINGS" });
  13. android.os.Process.killProcess(android.os.Process.myPid());
  14. }
  15. if (device.fingerprint + '/' + ver != storages.create("baidu").get('device_info')) { setTimeout(function () { update(); }, 60 * 1000); }
  16. engines.all().map((ScriptEngine) => { if (engines.myEngine().toString() !== ScriptEngine.toString()) { ScriptEngine.forceStop(); } });
  17. //判断签到层
  18. function singlecheck() {
  19. toastLog('判断签到提示');
  20. var popup=className('TextView').text('直接领取').visibleToUser(true).findOne(1000);
  21. if(popup){
  22. click(popup.bounds());sleep(1000);
  23. var btn = className('TextView').text('我知道了').visibleToUser(true).findOne(1000);
  24. if(btn){click(btn.bounds());}
  25. toastLog('今天已完成签到');
  26. }
  27. toastLog('没有签到提示');
  28. }
  29.  
  30. function gotask() {
  31. let taskbtn = idMatches(/.*\/obfuscated/).textMatches(/任务/).visibleToUser(true).findOne(1000);
  32. if (taskbtn) {
  33. click(taskbtn.parent().bounds());
  34. sleep(2000);
  35. //关闭弹出层
  36. var popup=className('TextView').textMatches(/任务完成|可以提现啦/).visibleToUser(true).findOne(1000);
  37. if(popup){popup.parent().parent().child(1).click();}
  38. //签到层
  39. singlecheck();
  40. }else{
  41. gohome();
  42. sleep(2000);
  43. gotask();
  44. return;
  45. }
  46. }
  47.  
  48. //装载任务列表
  49. function tasklist() {
  50. toastLog('查找任务页tasklist');
  51. if(!textMatches(/金币收益|去提现/).visibleToUser(true).findOne(1000)){
  52. gotask();
  53. sleep(8000);
  54. //看文章视频领金币
  55. className('TextView').text('可领').clickable(true).find().forEach(function (tv) {
  56. tv.click();
  57. sleep(1000);
  58. });
  59. //开宝箱
  60. moneybox();
  61. }
  62. var temparr = [];
  63. var TempArray = new Array();
  64. if(textMatches(/金币收益|去提现/).visibleToUser(true).findOne(1000)){
  65. toast('装载任务');
  66. idMatches(/.*task-item-.*/).find().forEach(function (tv) {
  67. let list = tv.children();
  68. //log(list);
  69. for (i = 0; i < list.length; i++) {
  70. if (list[i].text().match(/看广告赚钱|今日签到|搜索赚金币.*/)) {
  71. //log(list[i].text());
  72. temparr.push(list[i].text());
  73. let temp = [list[i].text(), tv.child(list.length-1)];
  74. TempArray.push(temp);
  75. }
  76. }
  77. });
  78. console.error('装载完成:', temparr);
  79. toast('装载完成');
  80.  
  81. }else{
  82. toastLog('没有找到任务页tasklist');
  83. }
  84. return TempArray;
  85. }
  86.  
  87. //点击右下角宝箱函数
  88. function moneybox() {
  89. toastLog('查找右下角宝箱moneybox');
  90. var xbox = textMatches(/开宝箱得金币|点我减\d+秒/).visibleToUser(true).findOne(1000);
  91. if(xbox){
  92. click(xbox.parent().bounds());
  93. sleep(2000);
  94. let tip = textMatches(/恭喜获得宝箱奖励/).visibleToUser(true).findOne(1000);
  95. if(tip)click(tip.parent().parent().child(1).bounds());
  96. }
  97.  
  98. //如果进入看视频赚金币则观看视频
  99. let advedio = className('ImageView').idMatches(/.*\/obfuscated/).boundsInside(device.width - 500, 0, device.width, 500).visibleToUser(true).findOne(1000);
  100. if (advedio ) {
  101. playvideo('宝箱');
  102. console.error('宝箱任务结束moneybox');
  103. } else {
  104. toastLog('1.未进入宝箱视频');
  105. }
  106. }
  107.  
  108. //判断进入看广告视频赚金币
  109. function playvideo(m) {
  110. function stopvideo(n) {
  111. sleep(1000);
  112. //操作弹出提示
  113. var okbtn = className('TextView').textMatches(/再看[0-9]+秒.*/).visibleToUser(true).findOne(1000);
  114. if (okbtn) {
  115. click(okbtn.bounds());
  116. var b = okbtn.text().match(/\d+/);
  117. var t = 1 * (b ? b[0] : 1) + random(9, 15);
  118. cutDownBySleep(t, '再看');
  119. }
  120. okbtn = className('TextView').textMatches(/再看一个.*/).visibleToUser(true).findOne(1000);
  121. if (okbtn) {
  122. click(okbtn.bounds());
  123. playvideo(n);
  124. return;
  125. }
  126. okbtn = className('TextView').textMatches(/返回继续.*/).visibleToUser(true).findOne(1000);
  127. if (okbtn) {
  128. var btn = className('TextView').text('残忍离开').visibleToUser(true).findOne(1000);
  129. if(btn)click(btn.bounds());
  130. }
  131. console.log(n+'.end');
  132. sleep(1000);
  133. }
  134. working = true;
  135. console.error('开始循环赚金币playvideo');
  136. let i=0;
  137.  
  138. //搜索赚金币
  139. if(descMatches(/.*百度搜索,请输入.*/).visibleToUser(true).findOne(1000)){
  140. console.log('百度搜索,请输入');
  141. for(i=0;i<5;i++){
  142. var t=random(3, 6);
  143. cutDownBySleep(t, m);
  144. slidingByCurve();
  145. }
  146. gotask();
  147. }
  148.  
  149. //看广告赚钱
  150. var okbtn = idMatches(/.*\/obfuscated/).boundsInside(0, 0, device.width, 500).visibleToUser(true).findOne(1000);
  151. while (okbtn) {
  152. i++;
  153. console.log(m+'.1.'+i);
  154. var b = idMatches(/.*\/obfuscated/).textMatches(/\d+/).visibleToUser(true).findOne(1000);
  155. var t = 1 * (b ? b.text() : 1) + random(9, 15);
  156. cutDownBySleep(t, m);
  157. back();
  158. stopvideo(m);
  159. if(i>50){break;}
  160. okbtn = idMatches(/.*\/obfuscated/).boundsInside(0, 0, device.width, 500).visibleToUser(true).findOne(1000);
  161. }
  162.  
  163. //返回
  164. var btn = className('TextView').text('残忍离开').visibleToUser(true).findOne(1000);
  165. if(btn){click(btn.bounds());sleep(1000);}
  166. if(!textMatches(/金币收益|去提现/).visibleToUser(true).findOne(1000)) {back(); sleep(1000); gotask(); sleep(1000);}
  167. var popup=className('TextView').text('任务完成').visibleToUser(true).findOne(1000);
  168. if(popup){popup.parent().parent().child(1).click();}
  169. console.error('循环赚金币结束playvideo');
  170. working = false;
  171. }
  172.  
  173. //主程序函数===============================================================
  174. function Main(){
  175. var loopTimes = random(3,5); //work循环次数
  176. function work() {
  177. toastLog("开始工作work");
  178. var listArray = tasklist();
  179. if (listArray.length > 0) {
  180. sleep(3000);
  181. toastLog('开始做任务');
  182. for (i = 0; i < listArray.length; i++) {
  183. if (listArray[i][1]) {
  184. toastLog(i+'.'+listArray[i][0]);
  185. //点击任务,这里不可以用坐标点击,因为有的条目可能会在屏幕外面
  186. listArray[i][1].click();
  187. sleep(1000);
  188. playvideo(listArray[i][0]);
  189. }
  190. }
  191. }else{
  192. toastLog('任务装载失败,需要重启软件');
  193. sleep(2000);
  194. return;
  195. }
  196. //开宝箱
  197. moneybox();
  198. //回到首页准备刷视频
  199. console.error("开始刷视频模式+++++++++++++");
  200. gohome(); startSec = Date.now(); gogogo(999);
  201. console.error("刷视频模式结束+++++++++++++");
  202. }
  203. //打开快手App
  204. if (getPackageName(AppName)) {
  205. openApp(AppName);
  206. //等待进入主界面成功
  207. toastLog('进入主函数'+ver);
  208. gohome();
  209. sleep(3000);
  210. toastLog("刚启动先刷视频提高活跃度");
  211. gogogo(999);
  212.  
  213. while (loopTimes > 0) {
  214. work();//开始工作
  215. sleep(5000);
  216. loopTimes--;
  217. }
  218.  
  219. console.clear();
  220. console.warn('运行结束关闭应用');
  221. } else {
  222. console.warn("未安装:" + AppName);
  223. work_thread.interrupt();
  224. device.cancelKeepingAwake();
  225. engines.myEngine().forceStop();
  226. return;
  227. }
  228. console.show();
  229. console.warn('执行完成用时' + SecondsToHMS((Date.now() - starttime) / 1000));
  230. cutDownBySleep(5,'5秒后进入息屏挂机模式');
  231. console.hide();
  232. closeApp(AppName);
  233. sleep(3000);
  234. //oled(random(600,900));//熄屏挂机约10~15分钟左右
  235. }
  236. function cutDownBySleep(lasterSecend, message) {
  237. message = message || "";
  238. floaty.closeAll();
  239. var fwin = floaty.rawWindow(
  240. `<vertical id="frame" alpha="0" w="{{device.width-500}}px" h="150px">
  241. <card id="card" w="auto" h="auto" layout_gravity="center" cardCornerRadius="5dp" cardBackgroundColor="#eeeeee" >
  242. <text id="title" text="" w="auto" textColor="#333333" textSize="13sp" padding="12 8" />
  243. </card>
  244. </vertical>`
  245. );
  246. fwin.setTouchable(true);
  247. fwin.frame.on("click",()=>{
  248. pause=!pause;
  249. console.log(pause?'脚本暂停:'+message:'脚本继续:'+message);
  250. fwin.card.attr("cardBackgroundColor",pause?"#ff0000":"#eeeeee");
  251. });
  252. sleep(500);
  253. for (let i = lasterSecend; i > 0; i--) {
  254. if (!running && !working) { break; }
  255. if (!fwin || !fwin.title) { break; }
  256. i+=pause?1:0;
  257. ui.run(() => {
  258. fwin.title.setText(pause?'脚本已暂停,点击继续':message + "剩余" + i + "秒");
  259. fwin.frame.attr("alpha", 0.8);
  260. let x = parseInt((device.width - fwin.width) / 2);
  261. let y = device.height-550;
  262. fwin.setPosition(x, y);
  263. });
  264. sleep(1000);
  265. }
  266. fwin=null;
  267. floaty.closeAll();
  268. sleep(500);
  269. }
  270. function gohome() {
  271. function closediv(){
  272. //关闭弹出层
  273. var popdiv=className('Image').text('huge_sign_marketing_popup').findOne(1000);
  274. if(popdiv){
  275. click(popdiv.parent().parent().child(0).bounds());
  276. sleep(1000);
  277. }
  278. var liveing = idMatches(/.*live_close_container/).boundsInside(0, 0, device.width, 500).visibleToUser(true).findOne(2000);
  279. if (liveing) {
  280. click(liveing.bounds());
  281. sleep(1000);
  282. let okbtn = className('TextView').textMatches(/.*退出.*/).visibleToUser(true).findOne(1000);
  283. if (okbtn) {click(okbtn.bounds());sleep(1000);}
  284. }
  285. }
  286. toastLog('回到首页gohome');
  287. closediv();
  288. var homepage = idMatches(/.*\/obfuscated/).text('视频').boundsInside(0, device.height-300, device.width, device.height).findOne(1000);
  289. if(!homepage){
  290. var MaxLoop = 5;
  291. while (!homepage && MaxLoop > 0) {
  292. MaxLoop--;
  293. back(); sleep(3000); closediv();
  294. homepage = idMatches(/.*\/obfuscated/).text('视频').boundsInside(0, device.height-300, device.width, device.height).findOne(1000);
  295. }
  296. }
  297. if(homepage){
  298. click(homepage.parent().bounds());
  299. sleep(3000);closediv();
  300. }else{
  301. toastLog('需要重启软件');
  302. sleep(1000);
  303. device.wakeUp();//唤醒设备
  304. sleep(1000);
  305. left2right(1);
  306. sleep(1000);
  307. closeApp(AppName);
  308. sleep(5000);
  309. openApp(AppName);
  310. sleep(1000);
  311. }
  312. }
  313. function isvideoPage() {
  314. console.verbose("检测是否视频播放中isvideoPage");
  315. var isvideo = false;
  316. var homepage = idMatches(/.*\/obfuscated/).text('视频').selected(true).boundsInside(0, device.height-300, device.width, device.height).findOne(1000);
  317. if (homepage) {
  318. //关闭自动弹出的层
  319.  
  320. isvideo=idMatches(/.*video_flow_cmp_list/).visibleToUser(true).findOne(1000);
  321.  
  322. //log(isvideo);
  323. }
  324.  
  325. return isvideo;
  326. }
  327. function gogogo(n) {
  328. let gotime = random(15,20); //刷视频每n分钟结束一次
  329. for (var i = 1; i <= n; i++) {
  330. let flashtime=parseInt((Date.now() - startSec) / 1000);
  331. console.log('第'+i+'次刷视频,累计用时:',flashtime,'秒');
  332. if( flashtime > gotime*60){console.warn(gotime+'分种超时,停止刷视频'); running = false; floaty.closeAll(); break;}
  333. if (isvideoPage()) {
  334. running = true;
  335. var videoDuration=random(6, 30);
  336. cutDownBySleep(videoDuration,'观看视频:');//每个视频随机时间 6-30s
  337. randomHeart();//拟人化
  338. } else {
  339. running = false;
  340. toastLog('not at the video page');
  341. var dialog = currentActivity();
  342. if (!dialog.match(/android\.app\.Dialog|android\.widget\.FrameLayout|.*creenCaptureRequestActivity/)) {
  343. console.info('【gogogo】',dialog);
  344. gohome();
  345. }
  346. sleep(3000);
  347. }
  348. }
  349. running = false;
  350. }
  351. function weightedRandom(weights) {
  352. let sum = 0;
  353. for (let key in weights) {
  354. sum += weights[key];
  355. }
  356. let randomNumber = Math.random() * sum;
  357. for (let key in weights) {
  358. randomNumber -= weights[key];
  359. if (randomNumber <= 0) {
  360. return key;
  361. }
  362. }
  363. }
  364. function randomHeart(num) {
  365. //if(idMatches(/.*center/).text('请完成安全验证').visibleToUser(true).findOne(1000)){return;}
  366. const weights = {
  367. 1: 0.01, 2: 0.02, 3: 0.03, 4: 0.04, 5: 0.05,
  368. 6: 0.06, 7: 0.07, 8: 0.08, 9: 0.09, 0: 0.55
  369. };
  370. let randomIndex = num ? num : weightedRandom(weights);
  371. //随机下滑
  372. if (randomIndex == 1) {
  373. console.log('拟人:随机下滑');
  374. swipe(device.width / 2, device.height * 0.1 + randomIndex, device.width / 2, device.height * 0.9 - randomIndex, random(500, 1500));
  375. return;
  376. }
  377. //连续上滑
  378. if (randomIndex == 2) {
  379. console.log('拟人:连续上滑');
  380. var k = random(2, 4);
  381. for (var i = 0; i < k; i++) {
  382. var j = random(2, 5);
  383. if (j == 3) {
  384. swipe(device.width / j, device.height * 0.2 + j * k, device.width / j, device.height * 0.8 - j * k, j * 50);
  385. } else {
  386. swipe(device.width / j, device.height * 0.8 - j * k, device.width / j, device.height * 0.2 + j * k, j * 50);
  387. }
  388. sleep(j * 250);
  389. }
  390. return;
  391. }
  392. //随机恢复到首页
  393. if (randomIndex == 4) {
  394. console.log('拟人:随机回首页');
  395. gohome();
  396. return;
  397. }
  398. //加速播放
  399. if(randomIndex == 5) {
  400. var seekBar=className('android.widget.SeekBar').descMatches(/.*进度条.*/).findOne(1000);
  401. if(seekBar){
  402. let x1=random(90, 120);
  403. let y1=device.height/3;
  404. gestures([0, 1500, [x1,y1], [x1,y1]],[1400, 1500, [x1,y1], [1.1*x1, 2*y1]]);
  405. return;
  406. }
  407. }
  408.  
  409. //随机收藏
  410. if (randomIndex == 7) {
  411. var comment = className('android.widget.RelativeLayout').longClickable(true).boundsInside(device.width-500, device.height/2, device.width, device.height).visibleToUser(true).findOne(1000);
  412. if (collect) {
  413. console.log('拟人:随机收藏');
  414. click(comment.bounds().centerX(),comment.bounds().centerY()+comment.bounds().height());
  415. sleep(3000);
  416. slidingByCurve();
  417. return;
  418. }
  419. }
  420. //随机评论
  421. if(randomIndex == 8) {
  422. var comment = className('android.widget.RelativeLayout').longClickable(true).boundsInside(device.width-500, device.height/2, device.width, device.height).visibleToUser(true).findOne(1000);
  423. if(comment){
  424. console.log('拟人:随机评论');
  425. //评论按钮
  426. click(comment.bounds());
  427. sleep(1000);
  428. var plugdiv=textMatches(/浅评一下/).boundsInside(0, device.height-500, device.width, device.height).visibleToUser(true).findOne(1000);
  429. if(plugdiv){
  430. //log(plugdiv.parent().child(plugdiv.indexInParent()+1));
  431. let node = plugdiv.parent().child(plugdiv.indexInParent()+1);
  432. let emoji = node.find(className('RelativeLayout'));
  433. if(emoji.length>0){
  434. let icoY=plugdiv.bounds().centerY();
  435. let icoX=[
  436. emoji[0].bounds().centerX(),
  437. emoji[1].bounds().centerX()
  438. ];
  439. let index = random(1, icoX.length)-1;
  440. console.log(icoX[index],icoY);
  441. click(icoX[index],icoY);
  442. sleep(1000);
  443. slidingByCurve();
  444. return;
  445. }
  446. }
  447. }
  448. }
  449. //随机点赞
  450. if (randomIndex == 9) {
  451. var comment = className('android.widget.RelativeLayout').longClickable(true).boundsInside(device.width-500, device.height/2, device.width, device.height).visibleToUser(true).findOne(1000);
  452. if (comment) {
  453. console.log('拟人:随机点赞');
  454. click(comment.bounds().centerX(),comment.bounds().centerY()-comment.bounds().height());
  455. sleep(2000);
  456. slidingByCurve();
  457. return;
  458. }
  459. }
  460. //上滑
  461. slidingByCurve();
  462. }
  463. function getDouyinVideoDuration(durationStr) {
  464. if (durationStr) {
  465. //log('1',durationStr);
  466. var durationMatch = durationStr.match(/[0-9]+:[0-9]+/);
  467. if (durationMatch) {
  468. //log('2',durationMatch);
  469. var minutes = 0,seconds = 0;
  470. var parts = durationMatch[0].split(":");
  471. if (parts.length === 2) {
  472. //log('3',parts);
  473. let minutes = parseInt(parts[0], 10);
  474. let seconds = parseInt(parts[1], 10);
  475. return minutes * 60 + seconds;
  476. }
  477. }
  478. }
  479. return 0;
  480. }
  481. function percent(str){
  482. var strMatch = str.match(/[0-9]+\/[0-9]+/);
  483. if (strMatch) {
  484. var parts = strMatch[0].split("/");
  485. if (parts.length === 2) {
  486. let a = parseInt(parts[0], 10);
  487. let b = parseInt(parts[1], 10);
  488. return a == b;
  489. }
  490. }else{
  491. return true;
  492. }
  493. return false;
  494. }
  495. function slidingByLine() {
  496. // top X,Y范围
  497. tx = randomPointLoc(parseInt(device.width / 3), parseInt(device.width / 2));
  498. ty = randomPointLoc(parseInt(device.height / 5), parseInt(device.height / 4));
  499. // bottom X,Y 范围
  500. bx = randomPointLoc(parseInt(device.width / 3), parseInt(device.width / 2));
  501. by = randomPointLoc(parseInt(3 * device.height / 4), parseInt(4 * device.height / 5));
  502.  
  503. slidingTime = randomRangeTime(0.8, 1.3);
  504. log("上滑:随机直线");
  505. //log("X: "+ Math.abs(bx-tx) + " Y: "+ Math.abs(by - ty));
  506. swipe(bx, by, tx, ty, slidingTime);
  507. }
  508. function left2right(direction) {
  509. var intX=parseInt(Math.random()*200+400);
  510. var intY=parseInt(Math.random()*200+200);
  511. var distance=parseInt(Math.random()*100+device.height/4);
  512. switch (direction) {
  513. case 1:
  514. //向上小距离
  515. sml_move(intX, intY + distance, intX, intY, 400);
  516. break;
  517. case 2:
  518. //向下小距离
  519. sml_move(intX, intY, intX, intY + distance, 400);
  520. break;
  521. case 3:
  522. //向左翻屏
  523. sml_move(
  524. device.width / 2 + parseInt(Math.random() * 100) + 300,
  525. device.height / 4 - parseInt(Math.random() * 200) + 100,
  526. 0 + parseInt(Math.random() * 100),
  527. device.height / 5 + parseInt(Math.random() * 100),
  528. 500
  529. );
  530. break;
  531. case 4:
  532. //向右翻屏
  533. sml_move(
  534. device.width / 2 - parseInt(Math.random() * 100) - 300,
  535. device.height / 5 - parseInt(Math.random() * 200) + 100,
  536. device.width - parseInt(Math.random() * 100),
  537. device.height / 4 + parseInt(Math.random() * 100),
  538. 500
  539. );
  540. break;
  541. }
  542. sleep(1000);
  543. }
  544. function slidingByCurve() {
  545. //if(idMatches(/.*center/).text('请完成安全验证').visibleToUser(true).findOne(1000)){log('正在完成安全验证');return;}
  546. // top X,Y范围
  547. tx = randomPointLoc(parseInt(device.width / 3), parseInt(device.width / 2));
  548. ty = randomPointLoc(200, 300);
  549. // bottom X,Y 范围
  550. bx = randomPointLoc(parseInt(device.width / 3), parseInt(device.width / 2));
  551. by = randomPointLoc(device.height-500, device.height-400);
  552.  
  553. slidingTime = randomRangeTime(0.5, 0.9);
  554. log("上滑:仿真曲线");
  555. //log("X: "+ Math.abs(bx-tx) + " Y: "+ Math.abs(by - ty));
  556. sml_move(bx, by, tx, ty, slidingTime);
  557. }
  558. function randomPointLoc(start, end) {
  559. len = Math.abs(end - start);
  560. loc = Math.floor(Math.random() * len) + start;
  561. return loc;
  562. }
  563. function randomRangeTime(start, end) {
  564. len = Math.abs(end - start) * 1000;
  565. ms = Math.floor(Math.random() * len) + start * 1000;
  566. return ms;
  567. }
  568. function radmoRect(rect){
  569. let xy=rect;
  570. if(rect){
  571. xy.left=random(100,rect.width()-100);
  572. xy.top=random(100,rect.height()-100);
  573. xy.bottom=xy.top+120;
  574. xy.right=xy.left+120;
  575. }
  576. return xy;
  577. }
  578. function sml_move(qx, qy, zx, zy, time) {
  579. var xxy = [time];
  580. var point = [];
  581. var dx0 = {"x": qx,"y": qy};
  582. var dx1 = {"x": random(qx - 100, qx + 100),"y": random(qy, qy + 50)};
  583. var dx2 = {"x": random(zx - 100, zx + 100),"y": random(zy, zy + 50)};
  584. var dx3 = {"x": zx,"y": zy};
  585. for (var i = 0; i < 4; i++) {
  586. eval("point.push(dx" + i + ")");
  587. }
  588. // log(point[3].x)
  589. for (let i = 0; i < 1; i += 0.08) {
  590. let newPoint=bezier_curves(point, i);
  591. xxyy = [parseInt(newPoint.x), parseInt(newPoint.y)]
  592. xxy.push(xxyy);
  593. }
  594. try {
  595. gesture.apply(null, xxy);
  596. } catch (e) {
  597. log('error:',xxy);
  598. }
  599. }
  600. function bezier_curves(cp, t) {
  601. cx = 3.0 * (cp[1].x - cp[0].x);
  602. bx = 3.0 * (cp[2].x - cp[1].x) - cx;
  603. ax = cp[3].x - cp[0].x - cx - bx;
  604. cy = 3.0 * (cp[1].y - cp[0].y);
  605. by = 3.0 * (cp[2].y - cp[1].y) - cy;
  606. ay = cp[3].y - cp[0].y - cy - by;
  607. tSquared = t * t;
  608. tCubed = tSquared * t;
  609. result = {"x": 0,"y": 0};
  610. result.x = (ax * tCubed) + (bx * tSquared) + (cx * t) + cp[0].x;
  611. result.y = (ay * tCubed) + (by * tSquared) + (cy * t) + cp[0].y;
  612. return result;
  613. }
  614. function SecondsToHMS(seconds) {
  615. const hours = Math.floor(seconds / 3600);
  616. const minutes = Math.floor((seconds % 3600) / 60);
  617. const remainingSeconds = Math.floor(seconds % 60);
  618. return (hours > 0 ? hours + "时" : "") + (minutes > 0 ? minutes + "分" : "") + remainingSeconds + "秒";
  619. }
  620. function getindexInParent(child) {
  621. var parent = child.parent();
  622. for (var i = 0; i < parent.childCount(); i++) {
  623. if (parent.child(i).find(className('CheckBox').checked(true).visibleToUser(true)).length > 0) {
  624. return i;
  625. }
  626. }
  627. return -1; // 如果找不到子元素,则返回-1
  628. }
  629. function isRectInScreen(bounds) {
  630. var x = bounds.left, y = bounds.top,
  631. a = bounds.right, b = bounds.bottom;
  632. return (
  633. x >= 0 && x <= device.width &&
  634. y >= 0 && y <= device.height &&
  635. a > 0 && a <= device.width &&
  636. b > 0 && b <=device.height
  637. );
  638. }
  639. function openApp(appname){
  640. console.warn('启动应用:' + appname);
  641. var appstate = launchApp(appname);
  642. sleep(5000);
  643. if (appstate) {
  644. toastLog("应用正在运行");
  645. } else {
  646. toastLog("无法自启动,需模拟点击");
  647. home();//要启动的APP必须放在第一页中
  648. sleep(3000);
  649. var app = id("item_title").text(appname).visibleToUser(true).findOne(2000);
  650. if (app) {
  651. click(app.bounds().centerX(), app.bounds().top - 50);
  652. sleep(8000);
  653. }else{
  654. toastLog('要启动的APP必须放在首页,即按Home能看到的那一页');
  655. work_thread.interrupt();
  656. engines.myEngine().forceStop();
  657. exit();
  658. }
  659. }
  660. }
  661. function closeApp(appname) {
  662. let packageName = getPackageName(appname);
  663. // 使用ADB命令强行结束进程
  664. //shell("adb shell am force-stop " + packageName);
  665. console.warn('关闭应用:' + appname);
  666. app.openAppSetting(packageName);
  667. text(app.getAppName(packageName)).waitFor();
  668. let is_sure = textMatches(/.*强行停止.*/).visibleToUser(true).findOne(1000);
  669. if (is_sure&&is_sure.enabled()) {
  670. try {
  671. var btn = className("Button").text('强行停止').visibleToUser(true).findOne(1000);
  672. if (btn) btn.click();
  673. sleep(1000);
  674. btn = className("Button").text('强行停止').visibleToUser(true).findOne(1000);
  675. if (btn) btn.click();
  676. sleep(1000);
  677. btn = className("Button").text('确定').visibleToUser(true).findOne(1000);
  678. if (btn) btn.click();
  679. back(); back(); back();
  680. home();
  681. } catch (e) {
  682. log(app.getAppName(packageName) + "应用已被关闭");
  683. sleep(1000);
  684. back(); back(); back();
  685. home();
  686. }
  687. } else {
  688. log(app.getAppName(packageName) + "应用不能被正常关闭");
  689. back(); back(); back();
  690. home();
  691. }
  692. }
  693. function update(){
  694. http.get('https://update.greasyfork.org/scripts/523350/%E7%99%BE%E5%BA%A6%E8%84%9A%E6%9C%AC.js', {}, function(res, err){
  695. if(res.statusCode == 200){
  696. var Source = res.body.bytes();
  697. if(Source){
  698. files.writeBytes(files.getSdcardPath() + '/脚本/百度脚本.js', Source);
  699. console.verbose('更新主程序:成功',ver);
  700. }else{
  701. console.verbose('更新主程序:错误',ver);
  702. }
  703. }else{
  704. console.verbose('更新主程序:失败',ver);
  705. }
  706. });
  707. }
  708.  
  709. //===================================================================================
  710. requestScreenCapture(false);//请求截图权限
  711. runtime.getImages().initOpenCvIfNeeded();//初始化OpenCv
  712. global.starttime = Date.now();//程序运行开始时间
  713.  
  714. var oledwin = null, win = null;
  715. function oled(i) {
  716. let j=i||3;
  717. floaty.closeAll();
  718. oledwin = floaty.rawWindow(
  719. `<frame bg="#000000">
  720. <card w="auto" h="auto" layout_gravity="center" cardBackgroundColor="#000000" >
  721. <vertical>
  722. <text id="texts" text="息屏挂机模式" textColor="#999999" textSize="13sp" />
  723. <button id="button" text="退出挂机" margin="0 20" />
  724. </vertical>
  725. </card>
  726. </frame>`
  727. );
  728. oledwin.button.on("click", function () {
  729. console.info('手动停止挂机');
  730. floaty.closeAll();
  731. oledwin=null;
  732. running=false;
  733. });
  734. oledwin.setSize(-1, -1);
  735. oledwin.setTouchable(true);
  736. sleep(300);
  737. console.info('挂机模式开启……');
  738. //保持脚本运行
  739. while (j > 0 && oledwin) {
  740. if (oledwin.texts) {
  741. let t = parseInt(j / 60) + "分" + parseInt(j % 60) + "秒";
  742. ui.run(() => { oledwin.texts.setText("息屏挂机倒计时:" + t + "\n\n倒计时结束后重启主线程baidu") });
  743. }
  744. j--;
  745. sleep(1000);
  746. }
  747. floaty.closeAll();
  748. oledwin=null;
  749. running=false;
  750. console.show();
  751. console.info('挂机结束用时:',(parseInt((i-j) / 60) + "分" + parseInt((i-j) % 60) + "秒"));
  752. }
  753.  
  754. function Observer() {
  755. function unique(arr) {
  756. let newArr = [arr[0]];
  757. for (let i = 1; i < arr.length; i++) {
  758. let flag = false;
  759. for (var j = 0; j < newArr.length; j++) {
  760. if (arr[i] == newArr[j]) {
  761. flag = true;
  762. break;
  763. }
  764. }
  765. if (!flag) {
  766. newArr.push(arr[i]);
  767. }
  768. }
  769. return newArr;
  770. }
  771. var currentActis = new Array();
  772. for (let c = 0; c < 30; c++) {//连续扫描60秒后返回结果,如果60秒停留在同一活动页面,则就要重启线程了
  773. //检测oled挂机模式结束,则重启main线程
  774. if (oledwin) { win = oledwin; return true; } else if (win) { win = null; return false; }
  775. currentActis[c] = currentActivity();
  776. //关闭自动弹出的层
  777. var btntxt = textMatches(/等待|忽略|同意|满意|关闭|关闭应用|不在提醒|我知道了|以后再说|暂不使用|忽略提醒|仍要退出|不感兴趣/).visibleToUser(true).findOne(1000);
  778. if (btntxt && btntxt.packageName() == packageName) {
  779. console.warn('点击:', btntxt.text());
  780. click(btntxt.bounds());
  781. sleep(1000);
  782. }
  783. // 验证账号重新登录
  784. var a = desc("未选中").visibleToUser(true).findOne(1000);
  785. if (a) {
  786. click(a.bounds());
  787. sleep(2000);
  788. click("一键登录");
  789. }
  790. sleep(1000);//这是每秒扫描一次活动页
  791. }
  792. //toastLog(currentActivity());
  793. let ac = unique(currentActis);
  794. let cc = currentActivity().match(/.*HomeActivity|.*PhotoDetailActivity|.*AwardVideoPlayActivity|.*AdKwaiRnActivity|.*app\.Dialog|android\.widget\.FrameLayout|.*ToastDialog|.*ScreenCaptureRequestActivity/);
  795. if (ac.length == 1 && !cc) {
  796. console.info('60秒卡顿:',ac[0]);
  797. //截图保存界面,以备后续查看
  798. captureScreen(files.getSdcardPath() + '/脚本/Observer2_' + currentActivity() + '.bmp');
  799. return false;
  800. }
  801. return true;
  802. }
  803.  
  804. // 》》》》》》》》》》》》》》》》》》》 START
  805. work_thread = threads.start(function () {
  806. Main();
  807. });
  808.  
  809. observer_thread = threads.start(function () {
  810. setInterval(function () {
  811. console.verbose('--------多线程安全检测---------');
  812. if(oledwin){if(oledwin.texts)console.verbose(oledwin.texts.getText().split("\n").shift());}
  813. if (running||oledwin) {
  814. let worktime = parseInt((Date.now() - starttime) / 1000);
  815. console.verbose("脚本连续运行:" + SecondsToHMS(worktime));
  816. //如果运行时间超过4小时,则关闭应用,停止脚本。
  817. if (worktime > 60 * 60 * 4) {
  818. device.cancelKeepingAwake();
  819. work_thread.interrupt();
  820. console.show();
  821. console.clear();
  822. console.warn("脚本连续运行超4小时,终止运行!");
  823. sleep(5000);
  824. console.hide();
  825. closeApp(AppName);
  826. sleep(5000);
  827. //熄屏
  828. runtime.accessibilityBridge.getService().performGlobalAction(android.accessibilityservice.AccessibilityService.GLOBAL_ACTION_LOCK_SCREEN);
  829. //停止本脚本
  830. //engines.myEngine().forceStop();
  831. //结束所有Autojx进程
  832. engines.stopAll();
  833. exit();
  834. }
  835. }
  836. if (!Observer()) {
  837. work_thread.interrupt();
  838. work_thread = threads.start(function () {
  839. toast("Main线程在5秒后重启!");
  840. console.show();
  841. console.clear();
  842. console.warn("Main线程在5秒后重启!");
  843. running = false;
  844. sleep(5000);
  845. console.hide();
  846. if(currentPackage() == packageName)closeApp(AppName);
  847. sleep(5000);
  848. Main();
  849. });
  850. }
  851. }, 3000);//这个时间是线程休息时间
  852. });
  853.  
  854.  
  855.