add setText and add group memeber script

This commit is contained in:
hyb1996 2017-07-12 11:47:32 +08:00
parent e5cc3ef4f9
commit fcfb3a69e0
9 changed files with 97 additions and 42 deletions

View File

@ -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;
}

View File

@ -11,7 +11,7 @@ function 赞(){
function 显示更多(){
for(let i = 0; i < 2;i++){
click("显示更多");
}
}
}
toast("请打开自己的资料页,点击点赞图标");

View File

@ -1,5 +1,6 @@
"auto";
//漏赞过多请稍微调大延迟
var 延迟 = 200;

View File

@ -1,10 +1,11 @@
"auto";
toast("请打开一个聊天窗口");
sleep(500);
while(true){
input("我喜欢你");
setText("我喜欢你");
click("发送");
sleep(200);
}

View File

@ -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;
}

View File

@ -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);

View File

@ -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;

View File

@ -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);
}
};
}

View File

@ -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<InstrumentationInfo> 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();
}
}
}