douyinUtils.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. const common = require("./common.js");
  2. const { swipeRandom, waitTime, openApp, random, xs_控件匹配是否存在, xs_控件是否存在, xs_控件点击, noResponse, findNodeXY } = require("./common.js");
  3. var douyinUtils = {};
  4. douyinUtils.appName = "抖音";
  5. douyinUtils.packageName = 'com.ss.android.ugc.aweme';
  6. /**关闭屏幕上“以后再说”对话框*/
  7. douyinUtils.closeFlashWindow = function () {
  8. try {
  9. if (xs_控件是否存在("text", "好的")) {
  10. log("检测到---抖音个人信息保护指引");
  11. xs_控件点击("text", "好的");//抖音个人信息保护指引
  12. }
  13. if (xs_控件是否存在("text", "我知道了")) {
  14. log("检测到---青少年模式");
  15. xs_控件点击("text", "我知道了");//青少年模式
  16. }
  17. if (xs_控件是否存在("text", "以后再说")) {
  18. log("检测到---抖音更新界面");
  19. xs_控件点击("text", "以后再说");//抖音更新界面
  20. }
  21. if (xs_控件匹配是否存在("text", "发现通讯录好友")) {
  22. log("检测到---抖音发现通讯录界面");
  23. if (xs_控件匹配是否存在("text", "取消")) {
  24. xs_控件点击("text", "取消");//抖音发现通讯录界面
  25. }
  26. if (xs_控件匹配是否存在("text", "暂时不要")) {
  27. xs_控件点击("text", "暂时不要");//抖音发现通讯录界面
  28. }
  29. }
  30. if (xs_控件是否存在("text", "知道了")) {
  31. log("检测到---青少年模式");
  32. xs_控件点击("text", "知道了");//青少年模式
  33. }
  34. //TODO
  35. if (xs_控件是否存在("text", "刷新")) {
  36. log("检测到---网络异常");
  37. xs_控件点击("text", "刷新");//网络异常
  38. }
  39. if (xs_控件是否存在("text", "挂断")) {
  40. log("有视频电话打进来");
  41. xs_控件点击("text", "挂断");//不接视频电话
  42. }
  43. if (xs_控件是否存在("text", "取消") && xs_控件是否存在("text", "等待对方接听")) {
  44. log("拨打出视频电话");
  45. xs_控件点击("text", "取消");//打视频电话
  46. }
  47. if (xs_控件是否存在("text", "好友推荐")) {
  48. log("检测到---好友推荐");
  49. back();
  50. }
  51. if (xs_控件是否存在("text", "网络错误")) {
  52. log("检测到---网络错误");
  53. xs_控件点击("text", "刷新");
  54. }
  55. if (xs_控件是否存在("text", "直播已结束")) {
  56. log("检测到---直播已结束");
  57. // eslint-disable-next-line no-undef
  58. swipe(822, 1293, 804, 205, random(500, 1000));
  59. sleep(2000);
  60. }
  61. if (xs_控件是否存在("text", "稍后")) {
  62. log("稍后", "t");
  63. click("稍后");
  64. }
  65. if (xs_控件是否存在("text", "下次再说")) {
  66. log("下次再说", "t");
  67. click("下次再说");
  68. }
  69. if (xs_控件是否存在("text", "稍后提醒我")) {
  70. log("稍后提醒我", "t");
  71. click("稍后提醒我");
  72. }
  73. if (findNodeXY(text("暂不绑定"), true)) {
  74. log("暂不绑定", "t");
  75. }
  76. if (click("立即开始")) {
  77. log("立即開始", "t");
  78. }
  79. if (findNodeXY(text("同意授权"), true)) {
  80. log("同意授权", "t");
  81. }
  82. if (findNodeXY(text("同意"), true)) {
  83. log("同意", "t");
  84. }
  85. //TODO
  86. if (findNodeXY(id("a9p"), true)) {
  87. log("拒绝", "来电");
  88. }
  89. if (findNodeXY(text("忽略"), true)) {
  90. log("检测到---链接", "t");
  91. }
  92. noResponse();
  93. }catch (e) {
  94. console.log(e);
  95. }
  96. }
  97. /**
  98. * 检查及处理一些意外情况,界面干扰情况,比如弹出的“以后再说”,“不感兴趣”,该方案是单独使用一个独立的线程来执行,不会主线程造成阻塞 ??理解肯定有错
  99. 这个干了两件事,第一个关闭哪些弹出框,第二 检测任务线程是否卡主,如果连续times 次,检测到卡主,就重启任务线程。.
  100. * @param {*} taskThread 线程 ,任务线程。
  101. * @param {*} times 次数,连续检测到任务线程,卡主的次数。每一次是10秒,
  102. */
  103. douyinUtils.checkOthers = function (taskThread, times) {
  104. var tmpIndex = 0;
  105. var oldActivty = 1;
  106. if (taskThread) {
  107. var tTh = taskThread.call(this);
  108. }
  109. threads.start(function () {
  110. var i = 0;
  111. // eslint-disable-next-line no-constant-condition
  112. while (true) {
  113. douyinUtils.closeFlashWindow();
  114. var curA = common.index;
  115. if (taskThread) {
  116. console.log("%d---%d", oldActivty, curA);
  117. if (oldActivty == curA) {
  118. console.log("" + (times - tmpIndex) * 10 + "秒后退出,重新开始");
  119. tmpIndex++;
  120. } else {
  121. tmpIndex = 0;
  122. oldActivty = curA;
  123. }
  124. if (tmpIndex > times) {
  125. var txt = "退出任务重新开始";
  126. console.log(txt);
  127. console.log(txt);
  128. console.log(txt);
  129. console.log(txt);
  130. tTh.interrupt();
  131. back();
  132. back();
  133. sleep(5000);
  134. tTh = taskThread.call(this);
  135. common.index = 0;
  136. tmpIndex = 0;
  137. }
  138. }
  139. if (i % 6 == 0) {
  140. log("activity-->" + curA);
  141. }
  142. sleep(10000);
  143. i++;
  144. }
  145. });
  146. }
  147. /**
  148. * 跳转到评论
  149. */
  150. douyinUtils.toComment = function () {
  151. waitTime(3,"点击评论")
  152. // eslint-disable-next-line no-constant-condition
  153. while(true){
  154. var plwg = descStartsWith("评论").findOnce();
  155. if (plwg != null) {
  156. console.log("点击评论");
  157. plwg.click();
  158. sleep(3000);
  159. }
  160. console.log("检测评论页");
  161. var t = textMatches(".*条评论.*|.*暂无评论.*").find();
  162. if(t){
  163. console.log("加载评论完成");
  164. break;
  165. }
  166. if(text("留下你的精彩评论吧").findOnce()){
  167. back();
  168. sleep(3000);
  169. }
  170. sleep(1000);
  171. }
  172. };
  173. /**
  174. * 点击斗音界面“我” 按钮
  175. */
  176. douyinUtils.toMy = function () {
  177. text("我").findOne().parent().parent().parent().click();
  178. }
  179. /**
  180. * 点击粉丝按钮
  181. */
  182. douyinUtils.toMyFs = function () {
  183. text("粉丝").findOne().parent().click();
  184. }
  185. /**
  186. * 上滑视屏,冷却时间一秒
  187. */
  188. douyinUtils.nextVideo = function () {
  189. log("上滑")
  190. // eslint-disable-next-line no-undef
  191. swipe(device.width * 0.6 + random(-20, 10), device.height * 0.55 + random(-20, 10),
  192. device.width * 0.62 + random(-20, 10), device.height * 0.35 + random(-20, 10), 1);
  193. sleep(1000);
  194. log("冷却")
  195. }
  196. /**
  197. * 下滑视屏,冷却时间一秒
  198. */
  199. douyinUtils.lastVideo = function () {
  200. log("下滑")
  201. // eslint-disable-next-line no-undef
  202. swipe(device.width * 0.6 + random(-20, 10), device.height * 0.35 + random(-20, 10),
  203. device.width * 0.62 + random(-20, 10), device.height * 0.55 + random(-20, 10), 1);
  204. log("冷却")
  205. sleep(1000)
  206. }
  207. /**
  208. * 评论翻页
  209. * @param {*} step 一次翻多少页,默认只翻一页
  210. */
  211. douyinUtils.commentNextPage = function (step) {
  212. var total = step || 1;
  213. var index = 0;
  214. while (index < total) {
  215. waitTime(1, "下一页")
  216. swipeRandom(device.width * 0.5, device.height * 0.85, device.width * 0.7, device.height * 0.4, 500);
  217. waitTime(1, "冷却");
  218. index++;
  219. }
  220. }
  221. /**
  222. * 跟据用户分享的直播间链接,进入直博间 或者某是,(后面发现非直播间也能进,就是用户分享的,名字没改)
  223. * @param {*} link 直播间链接
  224. */
  225. douyinUtils.toLiveRoom = function (link) {
  226. setClip(link);
  227. douyinUtils.closeDy();
  228. douyinUtils.openDy();
  229. waitTime(8, "等待抖音冷却,等待看一看出现,如果没出现可能链接有问题");
  230. textEndsWith("打开看看").findOne().click();
  231. waitTime(1, "进入指定视频");
  232. }
  233. douyinUtils.toRoom = function (link) {
  234. setClip(link);
  235. douyinUtils.closeDy();
  236. waitTime(3);
  237. douyinUtils.openDy();
  238. waitTime(8, "等待抖音冷却,等待看一看出现,如果没出现可能链接有问题");
  239. textEndsWith("看看").findOne().click();
  240. waitTime(1, "进入指定视频");
  241. }
  242. /**
  243. * 打开抖音
  244. */
  245. douyinUtils.openDy = function () {
  246. openApp(douyinUtils.appName);
  247. waitTime(10, "加载抖音中");
  248. }
  249. /**
  250. * 等待主页加载完成,等待抖音的主页出现。这些方法都不好使,
  251. */
  252. douyinUtils.waitMain = function () {
  253. global.waitForActivity("com.ss.android.ugc.aweme.main.MainActivity")
  254. }
  255. /**
  256. * 等待视频加载完成
  257. */
  258. douyinUtils.waitVideoDetail = function () {
  259. global.waitForActivity("com.ss.android.ugc.aweme.detail.ui.DetailActivity")
  260. }
  261. /**
  262. * 等待用户个人信息加载完成
  263. */
  264. douyinUtils.waitUserProfile = function () {
  265. global.waitForActivity("com.ss.android.ugc.aweme.profile.ui.UserProfileActivity")
  266. }
  267. /**
  268. * 等待用户自己的粉丝列表加载完成 ?? 是的,但是不太好使
  269. */
  270. douyinUtils.waitFollowRelation = function () {
  271. global.waitForActivity("com.ss.android.ugc.aweme.following.ui.FollowRelationTabActivity")
  272. }
  273. /**
  274. * 等待分享?? 对的,不太好使
  275. */
  276. douyinUtils.waitShare = function () {
  277. global.waitForActivity("com.ss.android.ugc.aweme.refactor.douyin.share.improve.CommonShareDialog")
  278. }
  279. /**
  280. * 等待直播 ?? 对的,不太好使
  281. */
  282. douyinUtils.waitLive = function () {
  283. global.waitForActivity("com.ss.android.ugc.aweme.live.LivePlayActivity")
  284. }
  285. /**
  286. * 返回个人信息
  287. */
  288. douyinUtils.backToUserProfile = function () {
  289. while (global.currentActivity() != "com.ss.android.ugc.aweme.profile.ui.UserProfileActivity") {
  290. back();
  291. console.log("返回个人信息");
  292. sleep(2000);
  293. }
  294. }
  295. /**
  296. * 返回用户首页
  297. */
  298. douyinUtils.backToHome = function () {
  299. while (global.currentActivity() != "com.ss.android.ugc.aweme.main.MainActivity" && global.currentActivity() != "android.app.Dialog") {
  300. back();
  301. console.log("返回用户首页");
  302. sleep(2000);
  303. }
  304. click("首页");
  305. sleep(2000);
  306. click("推荐");
  307. }
  308. /**
  309. * 返回用户作品
  310. */
  311. douyinUtils.backToDetail = function () {
  312. while (global.currentActivity() != "com.ss.android.ugc.aweme.detail.ui.DetailActivity" && descStartsWith("评论").findOnce() != null) {
  313. sleep(1000)
  314. log("返回用户作品")
  315. }
  316. }
  317. /**
  318. * 返回评论
  319. */
  320. douyinUtils.backToPl = function () {
  321. while (global.currentActivity() != "com.ss.android.ugc.aweme.detail.ui.DetailActivity") {
  322. back();
  323. sleep(1000)
  324. log( "返回评论")
  325. }
  326. }
  327. /**
  328. * 是否在评论页中?? ,是的,不好使。偶尔出错
  329. * @returns
  330. */
  331. douyinUtils.isInPly = function () {
  332. sleep(2000)
  333. var t = id("title").findOnce();
  334. if (t) {
  335. return true;
  336. }
  337. return false;
  338. }
  339. /**
  340. * 检查是否可以评论,是否有评论按钮,检测是否有 ‘写评论’,如果有,就是没有人评论过,点进去 要出问题。
  341. * @returns
  342. */
  343. douyinUtils.checkXPl = function () {
  344. click(device.width * 0.4, device.height * 0.5);
  345. var i = 2;
  346. while (i > 0) {
  347. var t = text("写评论").findOnce();
  348. if (t != null) {
  349. return true;
  350. }
  351. sleep(1000);
  352. i--;
  353. }
  354. return false;
  355. }
  356. /**
  357. * 关闭抖音??不太像啊 是关闭抖音,用了n种方法,都不是特别好使。
  358. */
  359. douyinUtils.closeDy = function () {
  360. // closeApp(douyinUtils.appName);
  361. // close1();
  362. // common.forceStopApp(douyinUtils.packageName);
  363. common.closeApp(douyinUtils.appName);
  364. waitTime(3);
  365. // close1();
  366. }
  367. /**
  368. * 点击坐标清理内存。 分辨率不同,可能不好使
  369. */
  370. // eslint-disable-next-line no-unused-vars
  371. function closex() {
  372. press(device.width * 0.75, device.height - device.getVirtualBarHeigh() * 0.5, 10);
  373. waitTime(2, "清理");
  374. click(device.width * 0.5, device.height - device.getVirtualBarHeigh() * 2);
  375. }
  376. /**
  377. * 清理后台??,强行结束 抖音,但是结束后,有可能,再也启动不起来了。
  378. */
  379. function close1() {
  380. // currentPackage();
  381. app.openAppSetting(douyinUtils.packageName);
  382. text(app.getAppName(douyinUtils.packageName)).waitFor();
  383. let is_sure = textMatches(/(.*强.*|.*停.*|.*结.*|.*行.*)/).findOne();
  384. if (is_sure.enabled()) {
  385. textMatches(/(.*强.*|.*停.*|.*结.*|.*行.*)/).findOne().click();
  386. textMatches(/(.*确.*|.*定.*)/).findOne().click();
  387. log(app.getAppName(douyinUtils.packageName) + "应用已被关闭");
  388. sleep(2000);
  389. back();
  390. } else {
  391. log(app.getAppName(douyinUtils.packageName) + "应用不能被正常关闭或不在后台运行");
  392. back();
  393. }
  394. }
  395. /**
  396. * 随机进入直播间
  397. */
  398. douyinUtils.toLive = function () {
  399. click(device.width * 0.4, device.height * 0.5);
  400. waitTime(3, "点击直播");
  401. desc("直播").findOne().click();
  402. waitTime(3, "直播加载中")
  403. }
  404. /**
  405. * 点赞
  406. */
  407. douyinUtils.Dz = function () {
  408. press(device.width * 0.4, device.height * 0.4, 10);
  409. sleep(50)
  410. press(device.width * 0.4, device.height * 0.4, 10);
  411. }
  412. /**
  413. * 识别性别
  414. * @returns 0,是男,1是女,2是未知
  415. */
  416. douyinUtils.getSex = function () {
  417. waitTime(0, "识别性别");
  418. var p = images.captureScreen();
  419. waitTime(1, '识别性别');
  420. var sexwg = className("android.widget.TextView").textMatches("\\d+岁").findOnce();
  421. if (sexwg == null) {
  422. return 2;
  423. }
  424. var bound = sexwg.bounds();
  425. // eslint-disable-next-line no-undef
  426. var point = findColor(p, "#18DCF3", {
  427. region: [bound.left, bound.top, 100, 50],
  428. threshold: 8
  429. });
  430. log("坐标", point)
  431. if (point != null) {
  432. return 0;
  433. }
  434. // eslint-disable-next-line no-undef
  435. var point2 = findColor(p, "#FD5473", {
  436. region: [bound.left, bound.top, 100, 50],
  437. threshold: 8
  438. });
  439. if (point2 != null) {
  440. return 1;
  441. }
  442. return 2;
  443. }
  444. /**
  445. * 取得用户的年龄和地区??
  446. * @returns
  447. */
  448. douyinUtils.getUserAgeAndArea = function () {
  449. var wg = id("im2").findOnce()
  450. var rs = { age: '未知', area: '未知' }
  451. if (!wg) {
  452. return rs;
  453. }
  454. var children = wg.find(className('android.widget.TextView'));
  455. var ta;
  456. if (children.length > 1) {
  457. rs.area = children[1].text();
  458. ta = children[0].text();
  459. if (ta.indexOf('岁') != -1) {
  460. rs.age = ta.replace("岁", '');
  461. }
  462. if (ta.replace(/\d+岁/, '').length > 1) {
  463. rs.area = ta;
  464. }
  465. console.log(1, rs);
  466. return rs;
  467. }
  468. if (children.length > 0) {
  469. ta = children[0].text();
  470. if (!ta.indexOf('岁') == -1) {
  471. rs.age = ta.replace("", '');
  472. }
  473. if (ta.replace(/\d+岁/, '').length > 1) {
  474. rs.area = ta;
  475. }
  476. console.log(2, rs);
  477. return rs;
  478. }
  479. return rs;
  480. }
  481. /**
  482. * 把字符串格试的日期转换成标准时间
  483. * @param {*} timeStr 字符串格试的日期
  484. * @returns 反回成标准时间
  485. */
  486. douyinUtils.toStandardTime = function (timeStr) {
  487. var units = ["刚刚", "分钟", '小时', "昨天", '天'];
  488. var unitVales = [0, 0.0166, 1, 1, 24];
  489. let index = 0;
  490. for (; index < units.length; index++) {
  491. const element = units[index];
  492. if (timeStr.indexOf(element) != -1) {
  493. break;
  494. }
  495. }
  496. console.log(index, "index");
  497. var time;
  498. if (index == units.length) {
  499. console.log("固定日期", timeStr)
  500. console.log(timeStr.match(/(\d+-\d+-\d+)|(\d+-\d+)/g).join(''))
  501. timeStr = timeStr.match(/(\d+-\d+-\d+)|(\d+-\d+)/g).join('');
  502. if (timeStr.length < 6) {
  503. timeStr = '2021-' + timeStr;
  504. }
  505. time = StringToDate(timeStr)
  506. console.log(time)
  507. var cha = (new Date().getTime() - time.getTime()) / 1000 / 60 / 60;
  508. return cha;
  509. }
  510. var num = parseInt(timeStr.replace(/[^0-9]/ig, "")) || 1;
  511. if (index == 3) {
  512. num = 18
  513. }
  514. return unitVales[index] * num;
  515. }
  516. /**
  517. * 字符串转日期
  518. * @param {*} str
  519. * @returns
  520. */
  521. function StringToDate(str) {
  522. var strDate = str.split(" ");
  523. var strDatepart = strDate[0].split("-");
  524. var dtDate = new Date(strDatepart[0], strDatepart[1] - 1, strDatepart[2]);
  525. return dtDate;
  526. }
  527. /**
  528. * 抖音搜索
  529. * @param {*} text 内容 输入的文字
  530. */
  531. function inputHs(text) {
  532. className("android.widget.EditText").findOne().click();
  533. waitTime(1, "进入输入框页,准备输入文字");
  534. className("android.widget.EditText").findOne().setText(text);
  535. log("停留在这里,说明id发生了变化,手动点点击输入框试试");
  536. var times = 0;
  537. // eslint-disable-next-line no-constant-condition
  538. while (true) {
  539. //发送id
  540. var t = id("b4l").findOnce();
  541. if (t != null) {
  542. t.click();
  543. break;
  544. }
  545. t = desc("发送").findOnce()
  546. if (t != null) {
  547. t.click();
  548. break;
  549. }
  550. if (times > 1) {
  551. log("一直无法点到发送,点击坐标试试");
  552. var bqwg = desc("表情").findOnce();
  553. if (bqwg != null) {
  554. let rect = bqwg.bounds();
  555. click(rect.right + 10, rect.centerY());
  556. break;
  557. }
  558. }
  559. var m = className("android.widget.EditText").findOnce();
  560. if (m != null) {
  561. click(m.bounds().centerX(), m.bounds().centerY())
  562. }
  563. times++;
  564. sleep(1000);
  565. }
  566. }
  567. douyinUtils.sentMsg=function(msg){
  568. inputHs(msg);
  569. }
  570. /**
  571. * 随机选择一条进行发送
  572. * @param {话术数组} msgs
  573. */
  574. douyinUtils.sendHs = function (msgs) {
  575. var tmp = msgs[random(0, msgs.length - 1)];
  576. var contents = tmp.split(/-+/);
  577. for (let index = 0; index < contents.length; index++) {
  578. const element = contents[index];
  579. inputHs(element);
  580. }
  581. }
  582. /**
  583. * 输入搜索文字
  584. * @param {*} txt 要搜索的内容
  585. */
  586. douyinUtils.inputToSearch = function (txt) {
  587. waitTime(6, "准备输入文字");
  588. className("android.widget.EditText").findOne().setText(txt);
  589. waitTime(6, "输入完成");
  590. //click("搜索")
  591. //eslint-disable-next-line no-constant-condition
  592. while (true) {
  593. console.log(text('搜索').find().length);
  594. var t = text("搜索").findOnce();
  595. // console.log("查找搜索",t);
  596. if(t){
  597. let rect = t.bounds();
  598. log(rect.centerX(), rect.centerY());
  599. click(rect.centerX(), rect.centerY());
  600. }
  601. sleep(1000)
  602. if (id("android:id/text1").text("视频").exists()) {
  603. sleep(3000)
  604. break;
  605. }
  606. }
  607. }
  608. /**
  609. * 点击作品
  610. */
  611. douyinUtils.clickZp = function () {
  612. var t = id("android:id/text1").textStartsWith("作品").findOnce();
  613. if (t) {
  614. var txt = t.text();
  615. click(txt);
  616. waitTime(1);
  617. }
  618. //部分作品看不到
  619. var i = random(0,5);
  620. while (i < 5) {
  621. douyinUtils.commentNextPage();
  622. i++;
  623. }
  624. // eslint-disable-next-line no-undef
  625. var vwg = descMatches("视频\\d+").findOne().parent();
  626. //console.log(vwg);
  627. var sp1 = vwg.findOne(className("android.view.View"));
  628. if (sp1 != null) {
  629. sp1.click();
  630. }
  631. }
  632. douyinUtils.isEndOfComment=function(){
  633. var rs =false;
  634. rs =rs||text("暂时没有更多了").findOnce()
  635. rs=rs||textMatches(".*来抢沙发.*").findOnce()
  636. rs=rs||textMatches(".*部分评论.*").findOnce();
  637. rs=rs||textMatches(".*上限.*").findOnce();
  638. return rs;
  639. }
  640. /**
  641. * 跟据抖音UID跳转到用户页
  642. * @param {*} uid
  643. */
  644. douyinUtils.openUserProfileByUid = function (uid) {
  645. var tmp = "snssdk1128://user/profile/" + uid + "?refer=web&gd_label=click_wap_profile_follow&type=need_follow&needlaunchlog=1"
  646. app.startActivity({
  647. data: tmp
  648. });
  649. }
  650. /**
  651. * 读取用户信息
  652. * @returns 反回用户信息
  653. */
  654. douyinUtils.readUserInfo = function () {
  655. douyinUtils.toMy();
  656. var userInfo={};
  657. try {
  658. waitTime(3);
  659. var liked = id('bmk').findOne().text();
  660. var subed = id('co9').findOne().text();
  661. var friends = id('co3').findOne().text();
  662. console.log(common.strToNumber(liked));
  663. userInfo.huozanNumber = common.strToNumber(liked);
  664. userInfo.concernNumber = common.strToNumber(subed);
  665. userInfo.friendNumber = common.strToNumber(friends);
  666. click('编辑资料');
  667. waitTime(3)
  668. var items = id('k6c').find();
  669. var infos = [];
  670. for (let index = 0; index < items.length; index++) {
  671. const item = items[index];
  672. var info = item.text();
  673. console.log(info);
  674. infos.push(info);
  675. }
  676. if (infos.length == 0) {
  677. waitTime(10, "读取失败");
  678. return null;
  679. }
  680. userInfo.name = infos[0];
  681. userInfo.account = infos[1];
  682. userInfo.synopsis = infos[2]; //概要
  683. userInfo.gender = infos[3]
  684. userInfo.age = infos[4]
  685. userInfo.address = infos[5]
  686. userInfo.school = infos[6]
  687. } catch (error) {
  688. console.log(error);
  689. }
  690. return userInfo;
  691. }
  692. module.exports = douyinUtils;