add setText and add group memeber script
This commit is contained in:
66
app/src/main/assets/sample/QQ与微信/QQ加群成员脚本.js
Normal file
66
app/src/main/assets/sample/QQ与微信/QQ加群成员脚本.js
Normal 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;
|
||||||
|
}
|
||||||
@@ -11,7 +11,7 @@ function 赞(){
|
|||||||
function 显示更多(){
|
function 显示更多(){
|
||||||
for(let i = 0; i < 2;i++){
|
for(let i = 0; i < 2;i++){
|
||||||
click("显示更多");
|
click("显示更多");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
toast("请打开自己的资料页,点击点赞图标");
|
toast("请打开自己的资料页,点击点赞图标");
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
"auto";
|
"auto";
|
||||||
|
|
||||||
|
|
||||||
//漏赞过多请稍微调大延迟
|
//漏赞过多请稍微调大延迟
|
||||||
var 延迟 = 200;
|
var 延迟 = 200;
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
"auto";
|
"auto";
|
||||||
|
|
||||||
|
|
||||||
toast("请打开一个聊天窗口");
|
toast("请打开一个聊天窗口");
|
||||||
sleep(500);
|
sleep(500);
|
||||||
|
|
||||||
while(true){
|
while(true){
|
||||||
input("我喜欢你");
|
setText("我喜欢你");
|
||||||
click("发送");
|
click("发送");
|
||||||
sleep(200);
|
sleep(200);
|
||||||
}
|
}
|
||||||
@@ -88,7 +88,7 @@ module.exports = function(__runtime__, scope){
|
|||||||
}, arguments);
|
}, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
automator.input = function(a, b){
|
automator.setText = function(a, b){
|
||||||
if(arguments.length == 1){
|
if(arguments.length == 1){
|
||||||
return __runtime__.automator.setText(__runtime__.automator.editable(-1), a);
|
return __runtime__.automator.setText(__runtime__.automator.editable(-1), a);
|
||||||
}else{
|
}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__(__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;
|
return automator;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,12 +109,20 @@ public class SimpleActionAutomator {
|
|||||||
return performAction(target.createAction(AccessibilityNodeInfo.ACTION_SELECT));
|
return performAction(target.createAction(AccessibilityNodeInfo.ACTION_SELECT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ScriptInterface
|
||||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||||
public boolean setText(ActionTarget target, String text) {
|
public boolean setText(ActionTarget target, String text) {
|
||||||
mScriptRuntime.requiresApi(Build.VERSION_CODES.LOLLIPOP);
|
mScriptRuntime.requiresApi(Build.VERSION_CODES.LOLLIPOP);
|
||||||
return performAction(target.createAction(AccessibilityNodeInfo.ACTION_SET_TEXT, text));
|
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
|
@ScriptInterface
|
||||||
public boolean back() {
|
public boolean back() {
|
||||||
return performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK);
|
return performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK);
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ import static android.support.v4.view.accessibility.AccessibilityNodeInfoCompat.
|
|||||||
|
|
||||||
public class UiObject extends AccessibilityNodeInfoCompat {
|
public class UiObject extends AccessibilityNodeInfoCompat {
|
||||||
|
|
||||||
|
public static final int ACTION_APPEND_TEXT = 0x00200001;
|
||||||
|
|
||||||
private static final String TAG = "UiObject";
|
private static final String TAG = "UiObject";
|
||||||
private static final boolean DEBUG = false;
|
private static final boolean DEBUG = false;
|
||||||
private static int notRecycledCount = 0;
|
private static int notRecycledCount = 0;
|
||||||
|
|||||||
@@ -42,14 +42,18 @@ public class ActionFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
@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)) {
|
return new SearchTargetAction(action, new FilterAction.EditableFilter(index)) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void performAction(UiObject node) {
|
protected void performAction(UiObject node) {
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, node.text() + text);
|
if (action == AccessibilityNodeInfo.ACTION_SET_TEXT) {
|
||||||
node.performAction(getAction(), args);
|
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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user