🏠 Home 

baidujs

自用库

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