main.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. "ui";
  2. ui.layout(
  3. <vertical padding="16" id="parent">
  4. <TextView text="快捷输入" gravity="center" textSize="24sp" padding="10 10 10 10" />
  5. <horizontal>
  6. <TextView w="auto" text="文本话术库【hs0—hsN】,保存在download目录下的文件hs0到hsN.txt,每一行为一条话术" />
  7. </horizontal>
  8. <horizontal>
  9. <TextView w="auto" text="话术库" />
  10. <input w="auto" id="totalhs" minWidth="50" inputType="number" text="4" />
  11. <TextView w="auto" text="个(总数)" />
  12. </horizontal>
  13. <horizontal>
  14. <TextView w="auto" text="保存在download/hs0-hsN.txt" />
  15. <button w="*" id="hs" text="wps编辑话术" />
  16. </horizontal>
  17. <horizontal>
  18. <TextView w="auto" text="打开app" />
  19. <input w="auto" id="app" minWidth="150" text="抖音" />
  20. <button w="auto" id="openapp" text="开始工作" />
  21. </horizontal>
  22. </vertical>
  23. );
  24. var common = require("../../common/common.js");
  25. const { resetConsole } = require("../../common/common.js");
  26. var filePath = "/sdcard/Download/";
  27. var storage = storages.create("com.example.kjsr");
  28. var totalhs = storage.get("totalhs", 3);
  29. var appName = storage.get("appName", "抖音");
  30. ui.totalhs.setText(totalhs + "");
  31. ui.app.setText(appName);
  32. ui.hs.click(function () {
  33. toast("打开wps,表情编辑话术");
  34. launch("cn.wps.moffice_eng");
  35. totalhs = Number(ui.totalhs.text());
  36. storage.put("totalhs", totalhs);
  37. hszs();
  38. });
  39. ui.openapp.click(function () {
  40. var appName = ui.app.text();
  41. threads.start(function () {
  42. // resetConsole();
  43. readhss();
  44. launchApp(appName);
  45. storage.put("appName", appName);
  46. floatyWindow();
  47. });
  48. });
  49. function hszs() {
  50. threads.start(function () {
  51. for (var index = 0; index <= totalhs; index++) {
  52. common.checkFile(filePath + "hs" + index + ".txt");
  53. }
  54. })
  55. }
  56. function floatyWindow() {
  57. var window = floaty.window(
  58. <vertical>
  59. <horizontal>
  60. <button id="tu" text="移动"></button>
  61. <button id="yc" text="隐藏"></button>
  62. </horizontal>
  63. <grid id="actions" spanCount="7" >
  64. <button id="action" text="{{this.key}}" h="40" bg="#ffffffff" />
  65. </grid>
  66. </vertical>
  67. );
  68. window.setPosition(device.width * 0.1, device.height * 0.5);
  69. window.exitOnClose();
  70. window.actions.setDataSource(initKeys());
  71. window.actions.on("item_bind", function (itemView, itemHolder) {
  72. itemView.action.on("click", function () {
  73. var text = itemHolder.item.key;
  74. log(text)
  75. threads.start(function () {
  76. if (text != "del") {
  77. var txt = geths(text);
  78. var edwg = className("android.widget.EditText").findOnce()
  79. if (edwg != null) {
  80. if (edwg.text() != "发送消息...") {
  81. txt = edwg.text() + txt;
  82. }
  83. ui.run(() => {
  84. edwg.setText(txt);
  85. })
  86. }
  87. } else {
  88. var edwg = className("android.widget.EditText").findOnce()
  89. if (edwg != null) {
  90. ui.run(() => {
  91. edwg.setText(" ");
  92. })
  93. }
  94. }
  95. });
  96. });
  97. });
  98. window.tu.click(() => {
  99. window.setAdjustEnabled(!window.isAdjustEnabled());
  100. return true;
  101. });
  102. var yc = false;
  103. window.yc.click(() => {
  104. yc = !yc;
  105. if (yc) {
  106. ui.run(function () {
  107. window.actions.setDataSource([]);
  108. })
  109. } else {
  110. ui.run(function () {
  111. window.actions.setDataSource(initKeys());
  112. })
  113. }
  114. });
  115. }
  116. function initKeys() {
  117. var arr = [];
  118. for (var index = 0; index <= totalhs; index++) {
  119. arr.push({ key: index });
  120. }
  121. arr.push({ key: 'del' });
  122. return arr;
  123. }
  124. function geths(index) {
  125. log(parseInt(index))
  126. log(hss[parseInt(index)]);
  127. return zuhehs(parseInt(index));
  128. }
  129. function randomHs(hs) {
  130. var rs = hs[random(0, hs.length - 1)];
  131. if (rs == "" || rs == null) {
  132. rs = "话术文1件没有内容";
  133. }
  134. return rs;
  135. }
  136. function zuhehs(index) { //组合话术
  137. var result = randomHs(hss[index]);
  138. return result;
  139. }
  140. var hss = [];
  141. function readhss() { //读取话术
  142. var filePath = "/sdcard/Download/";
  143. for (var index = 0; index <= totalhs; index++) {
  144. var bqhss = common.readlines(filePath + "hs" + index + ".txt");
  145. log(bqhss);
  146. hss.push(bqhss);
  147. }
  148. }
  149. setInterval(
  150. function () {
  151. }, 1000
  152. )