diff --git a/app/src/main/assets/sample/QQ与微信/QQ加群成员脚本.js b/app/src/main/assets/sample/QQ与微信/QQ加群成员脚本.js new file mode 100644 index 00000000..c9844a72 --- /dev/null +++ b/app/src/main/assets/sample/QQ与微信/QQ加群成员脚本.js @@ -0,0 +1,66 @@ +"auto"; + +var 好友验证信息 = "AutoJs自动添加群好友"; +var 延迟 = 500; + +toast("请打开群成员列表"); + +var added = {}; +while(true){ + var list = className("AbsListView").findOne(); + list.children().each(function(child){ + if(child.className() != "android.widget.FrameLayout"){ + return; + } + if(!isGroupMember(child)){ + return; + } + if(isMyself(child)){ + return; + } + child.child(0).click(); + sleep(500); + addAsFriend(); + sleep(延迟); + }); + className("AbsListView").findOne().scrollForward(); +} + + +function isGroupMember(child){ + if(child.childCount() != 1){ + return false; + } + return child.child(0) && child.child(0).className() == "android.widget.FrameLayout"; +} + +function isMyself(child){ + var l = child.findByText("我"); + return l && l.size() > 0; +} + +function addAsFriend(){ + var qq = getQQ(); + if(added[qq]){ + while(!click("返回")); + return; + } + added[qq] = true; + if(click("加好友")){ + sleep(800); + setText(0, 好友验证信息); + while(!click("发送")); + sleep(800); + if(click("取消")){ + sleep(400); + } + back(); + }else{ + back(); + } +} + +function getQQ(){ + var qq = textMatches("\\d{5,12}").findOne().text(); + return qq; +} \ No newline at end of file diff --git a/app/src/main/assets/sample/QQ与微信/QQ名片点赞脚本.js b/app/src/main/assets/sample/QQ与微信/QQ名片点赞脚本.js index 94694c59..0099f2bc 100644 --- a/app/src/main/assets/sample/QQ与微信/QQ名片点赞脚本.js +++ b/app/src/main/assets/sample/QQ与微信/QQ名片点赞脚本.js @@ -11,7 +11,7 @@ function 赞(){ function 显示更多(){ for(let i = 0; i < 2;i++){ click("显示更多"); - } + } } toast("请打开自己的资料页,点击点赞图标"); diff --git a/app/src/main/assets/sample/QQ与微信/好友列表名片点赞(不完美).js b/app/src/main/assets/sample/QQ与微信/好友列表名片点赞(不完美).js index 8fc980d1..c948b2ac 100644 --- a/app/src/main/assets/sample/QQ与微信/好友列表名片点赞(不完美).js +++ b/app/src/main/assets/sample/QQ与微信/好友列表名片点赞(不完美).js @@ -1,5 +1,6 @@ "auto"; + //漏赞过多请稍微调大延迟 var 延迟 = 200; diff --git a/app/src/main/assets/sample/QQ与微信/循环发送消息.js b/app/src/main/assets/sample/QQ与微信/循环发送消息.js index 703dc4ad..a83816da 100644 --- a/app/src/main/assets/sample/QQ与微信/循环发送消息.js +++ b/app/src/main/assets/sample/QQ与微信/循环发送消息.js @@ -1,10 +1,11 @@ "auto"; + toast("请打开一个聊天窗口"); sleep(500); while(true){ - input("我喜欢你"); + setText("我喜欢你"); click("发送"); sleep(200); } \ No newline at end of file diff --git a/autojs/src/main/assets/modules/__automator__.js b/autojs/src/main/assets/modules/__automator__.js index 3163e61c..37351dd8 100644 --- a/autojs/src/main/assets/modules/__automator__.js +++ b/autojs/src/main/assets/modules/__automator__.js @@ -88,7 +88,7 @@ module.exports = function(__runtime__, scope){ }, arguments); } - automator.input = function(a, b){ + automator.setText = function(a, b){ if(arguments.length == 1){ return __runtime__.automator.setText(__runtime__.automator.editable(-1), a); }else{ @@ -96,8 +96,16 @@ module.exports = function(__runtime__, scope){ } } + automator.input = function(a, b){ + if(arguments.length == 1){ + return __runtime__.automator.appendText(__runtime__.automator.editable(-1), a); + }else{ + return __runtime__.automator.appendText(__runtime__.automator.editable(a), b); + } + } + scope.__asGlobal__(__runtime__.automator, ['back', 'home', 'powerDialog', 'notifications', 'quickSettings', 'recents', 'splitScreen']); - scope.__asGlobal__(automator, ['click', 'longClick', 'press', 'swipe', 'gesture', 'gestures', 'gestureAsync', 'gesturesAsync', 'scrollDown', 'scrollUp', 'input']); + scope.__asGlobal__(automator, ['click', 'longClick', 'press', 'swipe', 'gesture', 'gestures', 'gestureAsync', 'gesturesAsync', 'scrollDown', 'scrollUp', 'input', 'setText']); return automator; } diff --git a/autojs/src/main/java/com/stardust/autojs/runtime/simpleaction/SimpleActionAutomator.java b/autojs/src/main/java/com/stardust/autojs/runtime/simpleaction/SimpleActionAutomator.java index dc9c49ba..f9c698ca 100644 --- a/autojs/src/main/java/com/stardust/autojs/runtime/simpleaction/SimpleActionAutomator.java +++ b/autojs/src/main/java/com/stardust/autojs/runtime/simpleaction/SimpleActionAutomator.java @@ -109,12 +109,20 @@ public class SimpleActionAutomator { return performAction(target.createAction(AccessibilityNodeInfo.ACTION_SELECT)); } + @ScriptInterface @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public boolean setText(ActionTarget target, String text) { mScriptRuntime.requiresApi(Build.VERSION_CODES.LOLLIPOP); return performAction(target.createAction(AccessibilityNodeInfo.ACTION_SET_TEXT, text)); } + @ScriptInterface + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) + public boolean appendText(ActionTarget target, String text) { + mScriptRuntime.requiresApi(Build.VERSION_CODES.LOLLIPOP); + return performAction(target.createAction(UiObject.ACTION_APPEND_TEXT, text)); + } + @ScriptInterface public boolean back() { return performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK); diff --git a/automator/src/main/java/com/stardust/automator/UiObject.java b/automator/src/main/java/com/stardust/automator/UiObject.java index cf2f74f4..c7a95563 100644 --- a/automator/src/main/java/com/stardust/automator/UiObject.java +++ b/automator/src/main/java/com/stardust/automator/UiObject.java @@ -36,6 +36,8 @@ import static android.support.v4.view.accessibility.AccessibilityNodeInfoCompat. public class UiObject extends AccessibilityNodeInfoCompat { + public static final int ACTION_APPEND_TEXT = 0x00200001; + private static final String TAG = "UiObject"; private static final boolean DEBUG = false; private static int notRecycledCount = 0; diff --git a/automator/src/main/java/com/stardust/automator/simple_action/ActionFactory.java b/automator/src/main/java/com/stardust/automator/simple_action/ActionFactory.java index 1d444b05..9946cc72 100644 --- a/automator/src/main/java/com/stardust/automator/simple_action/ActionFactory.java +++ b/automator/src/main/java/com/stardust/automator/simple_action/ActionFactory.java @@ -42,14 +42,18 @@ public class ActionFactory { } @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) - public static SimpleAction createActionWithEditableFilter(int action, int index, final String text) { + public static SimpleAction createActionWithEditableFilter(final int action, int index, final String text) { return new SearchTargetAction(action, new FilterAction.EditableFilter(index)) { @Override protected void performAction(UiObject node) { Bundle args = new Bundle(); - args.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, node.text() + text); - node.performAction(getAction(), args); + if (action == AccessibilityNodeInfo.ACTION_SET_TEXT) { + args.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, text); + } else { + args.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, node.text() + text); + } + node.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, args); } }; } diff --git a/automator/src/main/java/com/stardust/uiautomator/Test.java b/automator/src/main/java/com/stardust/uiautomator/Test.java deleted file mode 100644 index bb1b74c0..00000000 --- a/automator/src/main/java/com/stardust/uiautomator/Test.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.stardust.uiautomator; - -import android.content.ComponentName; -import android.content.Context; -import android.content.pm.InstrumentationInfo; -import android.widget.Toast; - -import java.util.List; - -/** - * Created by Stardust on 2017/5/9. - */ - -public class Test { - - - private void runTests(Context context) { - final String packageName = context.getPackageName(); - final List list = - context.getPackageManager().queryInstrumentation(packageName, 0); - if (list.isEmpty()) { - Toast.makeText(context, "Cannot find instrumentation for " + packageName, - Toast.LENGTH_SHORT).show(); - return; - } - final InstrumentationInfo instrumentationInfo = list.get(0); - final ComponentName componentName = - new ComponentName(instrumentationInfo.packageName, - instrumentationInfo.name); - if (!context.startInstrumentation(componentName, null, null)) { - Toast.makeText(context, "Cannot run instrumentation for " + packageName, - Toast.LENGTH_SHORT).show(); - } - } -}