mirror of
https://github.com/TonyJiangWJ/Auto.js.git
synced 2026-06-21 21:01:43 +08:00
docs, scripts
This commit is contained in:
parent
21c4a38b86
commit
dbacf93399
@ -69,6 +69,11 @@
|
||||
"type": "markdown",
|
||||
"path":"documentation"
|
||||
},
|
||||
{
|
||||
"title": "应用",
|
||||
"type": "markdown",
|
||||
"path":"documentation"
|
||||
},
|
||||
{
|
||||
"title": "模块与第三方jar",
|
||||
"type": "markdown",
|
||||
|
||||
@ -41,16 +41,30 @@ launchApp("微信");
|
||||
|
||||
设置剪贴板内容。此剪贴板即系统剪贴板,在一般应用的输入框中"粘贴"既可使用。
|
||||
|
||||
### getClip()
|
||||
|
||||
返回系统剪贴板的内容。
|
||||
|
||||
### waitForActivity(activity\[, period = 200\])
|
||||
* activity Activity名称
|
||||
* period 轮询等待间隔(毫秒)
|
||||
|
||||
等待指定的Activity出现。
|
||||
|
||||
|
||||
### waitForPackage(package\[, period = 200\])
|
||||
* package 包名
|
||||
* period 轮询等待间隔(毫秒)
|
||||
|
||||
等待指定的应用出现。例如`waitForPackage("com.tencent.mm")`为等待当前界面为微信。
|
||||
|
||||
### isStopped()
|
||||
当脚本处于应当停止运行的状态时返回true, 否则返回false。
|
||||
由于脚本引擎的关系,有时即使强制停止正在运行的脚本也不会生效,此时会出现isStopped()为true但脚本仍在运行的情况。
|
||||
|
||||
### notStopped()
|
||||
当脚本处于应当停止运行的状态时返回false, 否则返回false。
|
||||
为了避免脚本处于循环中无法正常结束,在诸如while(true)的循环中建议使用while(notStopped())代替,例如:
|
||||
```
|
||||
while(notStopped()){
|
||||
//do something
|
||||
}
|
||||
```
|
||||
|
||||
### stop()
|
||||
立即停止脚本运行。
|
||||
|
||||
|
||||
46
app/src/main/assets/help/documentation/应用.md
Normal file
46
app/src/main/assets/help/documentation/应用.md
Normal file
@ -0,0 +1,46 @@
|
||||
|
||||
### app.intent(intent)
|
||||
* intent \<Object\> 一个表示Intent对象,其属性可以包括:
|
||||
* action \<String\> 这个Intent的Action,比如"android.intent.action.SEND"
|
||||
* type \<String\> 这个Intent的MimeType,比如"text/plain"
|
||||
* data \<String\> 这个Intent的Data(Uri),可以是文件路径或者Url等。
|
||||
* category \<Array\> 这个Intent的Category的字符串数组。
|
||||
* packageName \<String\> 目标包名
|
||||
* className \<String\> 目标Activity或Service等组件的名称
|
||||
* extras \<Object\> 以键值对构成的这个Intent的Extras。
|
||||
|
||||
返回用intent对象构造的android.content.Intent对象。
|
||||
|
||||
如果你看了一脸懵逼,请百度[安卓Intent](https://www.baidu.com/s?wd=android%20Intent)。
|
||||
|
||||
### app.startActivity(intent)
|
||||
* intent \<Object\> 与app.intent函数的参数一样的intent对象。
|
||||
|
||||
相当于context.startActivity(intent)。
|
||||
|
||||
|
||||
### app.sendBroadcast(intent)
|
||||
* intent \<Object\> 与app.intent函数的参数一样的intent对象。
|
||||
|
||||
相当于context.sendBroadcast(intent)。
|
||||
|
||||
### app.viewFile(path)
|
||||
* path \<String\> 文件路径
|
||||
|
||||
用其他应用查看文件。
|
||||
|
||||
### app.editFile(path)
|
||||
* path \<String\> 文件路径
|
||||
|
||||
用其他应用编辑文件。
|
||||
|
||||
### app.uninstall(packageName)
|
||||
* packageName \<String\> 应用包名
|
||||
|
||||
卸载应用。
|
||||
|
||||
### app.openUrl(url)
|
||||
* url \<String\> 网站的Url
|
||||
|
||||
用浏览器打开网站url。
|
||||
|
||||
@ -1,18 +1,27 @@
|
||||
控制台通常用来输出一些调试信息和运算结果。
|
||||
|
||||
### openConsole()
|
||||
### console.show()
|
||||
|
||||
显示控制台。
|
||||
### clearConsole()
|
||||
### console.clear()
|
||||
|
||||
清空控制台。
|
||||
|
||||
### log(text)
|
||||
### console.log(text)
|
||||
|
||||
* text \<String\> | \<Object\> 要打印到控制台的信息
|
||||
|
||||
### print(text)
|
||||
等同于log。
|
||||
在控制台中输出文本text并换行,例如`log("Hello world");`。当text是一个对象时则会转换String以后再输出。
|
||||
|
||||
在控制台中输出日志,例如`log("Hello world");`。当text是一个对象时则会转换String以后再输出。
|
||||
### print(text)
|
||||
|
||||
在控制台中输出文本text。
|
||||
|
||||
### err(error)
|
||||
### console.error(error)
|
||||
* error \<String\> | \<Object\>
|
||||
|
||||
在控制台中输出错误信息,以红色字体显示,例如:
|
||||
@ -29,4 +38,19 @@ try{
|
||||
### toast(message)
|
||||
* message \<String\> | \<Object\> 要显示的信息
|
||||
|
||||
以气泡显示信息message几秒。(具体时间取决于安卓系统)
|
||||
以气泡显示信息message几秒。(具体时间取决于安卓系统)
|
||||
|
||||
### toastLog(message)
|
||||
* message \<String\> | \<Object\> 要显示的信息
|
||||
|
||||
相当于`toast(message);log(message)`。
|
||||
|
||||
### console.assert(value, message)
|
||||
* value \<Boolean\> 要断言的布尔值
|
||||
* message \<String\> value为false时要输出的信息
|
||||
|
||||
断言。如果value为false则输出message并停止脚本运行。
|
||||
|
||||
### console.input(data\[, ...args\])
|
||||
|
||||
### console.rawInput(data\[, ...args\])
|
||||
|
||||
@ -49,10 +49,18 @@ while(!click("扫一扫"));
|
||||
* i \<Number\> 表示要输入的为第i + 1个输入框
|
||||
* text \<String\> 要输入的文本
|
||||
|
||||
返回是否输入成功。当找不到对应的文本框时返回false。
|
||||
不加参数i则会在所有输入框都输入text。例如`input("测试")`。
|
||||
|
||||
### setText(\[i, \]text)
|
||||
* i \<Number\> 表示要输入的为第i + 1个输入框
|
||||
* text \<String\> 要输入的文本
|
||||
|
||||
返回是否输入成功。当找不到对应的文本框时返回false。
|
||||
不加参数i则会把所有输入框的文本都置为text。例如`input("测试")`。
|
||||
这里的输入文本的意思是,把输入框的文本置为text,而不是在原来的文本上追加。
|
||||
|
||||
|
||||
### back()
|
||||
模拟按下返回键
|
||||
|
||||
|
||||
@ -4,9 +4,9 @@ var 好友验证信息 = "AutoJs自动添加群好友";
|
||||
var 延迟 = 500;
|
||||
|
||||
launchApp("QQ");
|
||||
toast("请打开要加的群");
|
||||
sleep(500);
|
||||
if(currentActivity() != "com.tencent.mobileqq.activity.TroopMemberListActivity"){
|
||||
toast("请打开要加的群的聊天窗口");
|
||||
openGroupMemberList();
|
||||
}
|
||||
|
||||
@ -16,7 +16,7 @@ while(true){
|
||||
var count = list.childCount();
|
||||
for(var i = 0; i < count; i++){
|
||||
var child = list.child(i);
|
||||
if(!child || child.className() != "android.widget.FrameLayout"){
|
||||
if(!child || child.className() != "android.widget.FrameLayout"){
|
||||
continue;
|
||||
}
|
||||
if(!isGroupMember(child) || isMyself(child)){
|
||||
@ -29,20 +29,21 @@ while(true){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function isGroupMember(child){
|
||||
if(child.childCount() != 1){
|
||||
return false;
|
||||
}
|
||||
if(!child.findByText("Baby Q").isEmpty()){
|
||||
return false;
|
||||
var tvName = child.findOne(id("tv_name"));
|
||||
if(!tvName){
|
||||
return false;
|
||||
}
|
||||
return child.child(0) && child.child(0).className() == "android.widget.FrameLayout";
|
||||
log(tvName.text());
|
||||
return tvName.text() != "Baby Q";
|
||||
}
|
||||
|
||||
function isMyself(child){
|
||||
var l = child.findByText("我");
|
||||
return l && l.size() > 0;
|
||||
var i = child.findOne(text("我"));
|
||||
if(!i){
|
||||
return false;
|
||||
}
|
||||
return i.id() && !i.id().endsWith("tv_name");
|
||||
}
|
||||
|
||||
function addAsFriend(){
|
||||
@ -61,9 +62,9 @@ function addAsFriend(){
|
||||
if(click("取消")){
|
||||
sleep(400);
|
||||
}
|
||||
back();
|
||||
while(!back());
|
||||
}else{
|
||||
back();
|
||||
while(!back());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -5,12 +5,7 @@ function 下滑(){
|
||||
}
|
||||
|
||||
function 赞(){
|
||||
var like = className("ImageView").desc("赞").find();
|
||||
if(like){
|
||||
like.click();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
className("ImageView").desc("赞").click();
|
||||
}
|
||||
|
||||
function 显示更多(){
|
||||
@ -21,16 +16,11 @@ function 显示更多(){
|
||||
|
||||
toast("请打开自己的资料页,点击点赞图标");
|
||||
sleep(100);
|
||||
waitForActivity("com.tencent.mobileqq.activity.VisitorsActivity");
|
||||
|
||||
while(notStopped()){
|
||||
var i = 0;
|
||||
while(i < 10){
|
||||
i += 赞() ? 1 : 0;
|
||||
click("取消");
|
||||
for(let i = 0; i < 10; i++){
|
||||
赞();
|
||||
}
|
||||
显示更多();
|
||||
if(currentActivity() == "com.tencent.mobileqq.activity.VisitorsActivity"){
|
||||
下滑();
|
||||
}
|
||||
下滑();
|
||||
}
|
||||
@ -1,21 +1,29 @@
|
||||
"auto";
|
||||
|
||||
var 延迟 = 100;
|
||||
|
||||
launchApp("QQ");
|
||||
toast("请打开自己的资料页,点击点赞图标");
|
||||
sleep(500);
|
||||
waitForActivity("com.tencent.mobileqq.activity.VisitorsActivity");
|
||||
|
||||
while(notStopped()){
|
||||
for(var i = 0; i < 10; i++){
|
||||
className("ImageView").desc("赞").untilFind().each(function(like){
|
||||
var parent = like.parent();
|
||||
if(like.parent().findByText("(好友)")){
|
||||
var list = className("AbsListView").findOne();
|
||||
list.children().each(function(child){
|
||||
if(!child)
|
||||
return;
|
||||
var l = child.findByText("(好友)");
|
||||
if(l.size() > 0){
|
||||
var like = child.findOne(className("ImageView").desc("赞"));
|
||||
for(let i = 0; i < 10; i++){
|
||||
like.click();
|
||||
}
|
||||
});
|
||||
}
|
||||
sleep(延迟);
|
||||
}
|
||||
}
|
||||
});
|
||||
click("显示更多");
|
||||
click("显示更多");
|
||||
if(currentActivity() == "com.tencent.mobileqq.activity.VisitorsActivity"){
|
||||
className("AbsListView").scrollable().scrollForward();
|
||||
list.scrollForward();
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,10 @@
|
||||
"auto";
|
||||
|
||||
launchApp("QQ");
|
||||
toast("请打开要点赞的群");
|
||||
sleep(500);
|
||||
if(currentActivity() != "com.tencent.mobileqq.activity.TroopMemberListActivity"){
|
||||
openGroupMemberList();
|
||||
toast("请打开要点赞的群的聊天窗口");
|
||||
openGroupMemberList();
|
||||
}
|
||||
|
||||
while(true){
|
||||
@ -31,18 +31,20 @@ while(true){
|
||||
|
||||
|
||||
function isGroupMember(child){
|
||||
if(child.childCount() != 1){
|
||||
return false;
|
||||
}
|
||||
if(!child.findByText("Baby Q").isEmpty()){
|
||||
return false;
|
||||
var tvName = child.findOne(id("tv_name"));
|
||||
if(!tvName){
|
||||
return false;
|
||||
}
|
||||
return child.child(0) && child.child(0).className() == "android.widget.FrameLayout";
|
||||
log(tvName.text());
|
||||
return tvName.text() != "Baby Q";
|
||||
}
|
||||
|
||||
function isMyself(child){
|
||||
var l = child.findByText("我");
|
||||
return l && l.size() > 0;
|
||||
var i = child.findOne(text("我"));
|
||||
if(!i){
|
||||
return false;
|
||||
}
|
||||
return i.id() && !i.id().endsWith("tv_name");
|
||||
}
|
||||
|
||||
function like(){
|
||||
|
||||
@ -140,7 +140,7 @@ public class SettingsActivity extends BaseActivity {
|
||||
.entry(getString(R.string.text_join_qq_group), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!IntentUtil.joinQQGroup(getActivity(), "vjHXzZlpGcXNe-YEWzQ85mm_z8y-curC")) {
|
||||
if (!IntentUtil.joinQQGroup(getActivity(), "-7riBQuwFUUqdgYL5vFeIdBfH4H9m-Uj")) {
|
||||
Toast.makeText(getActivity(), R.string.text_mobile_qq_not_installed, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@
|
||||
<string name="text_recorded">录制结束</string>
|
||||
<string name="text_copy_to_clip">复制到剪贴板</string>
|
||||
<string name="text_file_write_fail">文件写入失败</string>
|
||||
<string name="text_join_qq_group">加入QQ交流群</string>
|
||||
<string name="text_join_qq_group">加入QQ互赞&交流群</string>
|
||||
<string name="text_copied">已复制到剪贴板</string>
|
||||
<string name="text_use_volume_control_record">使用音量键控制</string>
|
||||
<string name="summary_use_volume_control_record">开启后每次音量变化会开始或停止脚本录制</string>
|
||||
|
||||
@ -81,6 +81,8 @@
|
||||
|
||||
<Preference android:title="@string/text_check_update"/>
|
||||
|
||||
<Preference android:title="@string/text_join_qq_group"/>
|
||||
|
||||
<Preference android:title="@string/text_issue_report"/>
|
||||
|
||||
<Preference android:title="@string/text_about_me_and_repo"/>
|
||||
|
||||
@ -48,5 +48,12 @@ module.exports = function(__runtime__, scope){
|
||||
}
|
||||
}
|
||||
|
||||
scope.waitForPackage = function(packageName, delay){
|
||||
delay = delay || 200;
|
||||
while(scope.currentPackage() != packageName){
|
||||
sleep(delay);
|
||||
}
|
||||
}
|
||||
|
||||
scope.setScreenMetrics = __runtime__.setScreenMetrics.bind(__runtime__);
|
||||
}
|
||||
@ -27,4 +27,6 @@ public class PRandomAccessBinaryFile extends RandomAccessFile {
|
||||
return super.readLine();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user