Auto.js 是個基于 JavaScript 語言運作在Android平台上的腳本架構。
1.手機安裝Auto.js和vscode
(1)vscode下載下傳位址 https://code.visualstudio.com/
2.開發環境
VsCode — 步驟: 打開Vscode carl +shirt +x 安裝antojs擴充
Autojs手機端 4.1.0版 如果沒有apk的小夥伴可以私信我
安裝好autojs擴充後 啟動服務
3.建立檔案開發
(1)我采用了Auto.js提供的UI界面,簡單的添加了輸入框和無障礙啟動的判斷。

(2)代碼如下
"ui";
var color = "#009688";
ui.layout(
<drawer id="drawer">
<vertical>
<appbar>
<toolbar id="toolbar" title="自動化腳本" />
<tabs id="tabs" />
</appbar>
<viewpager id="viewpager">
<frame>
<vertical>
<linear padding="5 0 0 0">
<Switch id="autoService" textColor="red" text="無障礙服務(注意!必須開啟才能正常運作腳本)" checked="{{auto.service != null}}" />
</linear>
<linear padding="5 0 0 0">
<text textSize="16sp" textSize="15sp" textColor="black" text="養号開關" />
<Switch id="yhkg" textColor="red" checked="true" />
</linear>
<linear padding="5 0 0 0">
<text textColor="black" text="刷" />
<input id="gk" w="auto" inputType="number" text="5" />
<text textColor="black" text="-" />
<input id="gk1" w="auto" inputType="number" text="10" />
<text textColor="black" text="個視訊,每個停留," />
<input id="tl" w="auto" inputType="number" text="5" />
<text textColor="black" text="-" />
<input id="tl1" w="auto" inputType="number" text="10" />
<text textColor="black" text="秒" />
</linear>
<linear padding="5 0 0 0">
<button id="ok" w="*" h="auto" layout_gravity="bottom" style="Widget.AppCompat.Button.Colored" text="啟動" />
</linear>
</vertical>
</frame>
<frame>
<text text="第二頁内容" textColor="red" textSize="16sp" />
</frame>
<frame>
<text text="作者聯系方式VX:YH841280" textColor="Black" textSize="16sp" />
</frame>
</viewpager>
</vertical>
<vertical layout_gravity="left" bg="#ffffff" w="280">
<img w="280" h="200" scaleType="fitXY" src="http://images.shejidaren.com/wp-content/uploads/2014/10/023746fki.jpg" />
<list id="menu">
<horizontal bg="?selectableItemBackground" w="*">
<img w="50" h="50" padding="16" src="{{this.icon}}" tint="{{color}}" />
<text textColor="black" textSize="15sp" text="{{this.title}}" layout_gravity="center" />
</horizontal>
</list>
</vertical>
</drawer>
);
//建立選項菜單(右上角)
ui.emitter.on("create_options_menu", menu => {
menu.add("設定");
menu.add("關于");
});
//監聽選項菜單點選
ui.emitter.on("options_item_selected", (e, item) => {
switch (item.getTitle()) {
case "設定":
toast("還沒有設定");
break;
case "關于":
alert("關于", "Auto.js界面模闆 v1.0.0");
break;
}
e.consumed = true;
});
activity.setSupportActionBar(ui.toolbar);
//設定滑動頁面的标題
ui.viewpager.setTitles(["首頁", "賬号管理", "關于"]);
//讓滑動頁面和标簽欄關聯
ui.tabs.setupWithViewPager(ui.viewpager);
//讓工具欄左上角可以打開側拉菜單
ui.toolbar.setupWithDrawer(ui.drawer);
ui.menu.setDataSource([
{
title: "選項一",
icon: "@drawable/ic_android_black_48dp"
},
{
title: "選項二",
icon: "@drawable/ic_settings_black_48dp"
},
{
title: "選項三",
icon: "@drawable/ic_favorite_black_48dp"
},
{
title: "退出",
icon: "@drawable/ic_exit_to_app_black_48dp"
}
]);
ui.menu.on("item_click", item => {
switch (item.title) {
case "退出":
ui.finish();
break;
}
})
//建立儲存對象
var map = storages.create("短視訊資料");
if(map.get('gk')){
ui.gk.setText(map.get('gk'));
ui.gk1.setText(map.get('gk1'));
ui.tl.setText(map.get('tl'));
ui.tl1.setText(map.get('tl1'));
}
//指定确定按鈕點選時要執行的動作
ui.autoService.on("check", function (checked) {
// 使用者勾選無障礙服務的選項時,跳轉到頁面讓使用者去開啟
if (checked && auto.service == null) {
app.startActivity({
action: "android.settings.ACCESSIBILITY_SETTINGS"
});
}
if (!checked && auto.service != null) {
auto.service.disableSelf();
}
});
//啟動
ui.ok.click(function () {
threads.start(function () {
toastLog("腳本開始運作")
if (app.launch("com.ss.android.ugc.aweme")) {
sleep(2000)
//判斷養号功能開關是否打開
if (ui.yhkg.checked) {
養号功能()
}
} else {
alert("請安裝抖音,腳本停止")
exit()
}
})
})
//開始養号功能
function 養号功能() {
儲存資料();
//擷取 需要刷的視訊數
var 視訊數 = random(Number(ui.gk.text()), Number(ui.gk1.text()));
toastLog("正在進行養号功能");
sleep(2000);
//等待關注的出現
desc("關注").waitFor();
sleep(1000);
for (let i = 0; i < 視訊數; i++) {
倒計時(ui.tl.text(), ui.tl1.text())
toastLog("養号進度:" + (i + 1) + "/" + 視訊數)
sleep(random(1500, 1800))
// log(device.width / 2, (device.height / 2) + (device.height / 2) / 2);
// log(random(50,device.width-50), device.height / 10);
gesture(500,
[device.width / 2, (device.height / 2) + (device.height / 2) / 2],
[random(50, device.width - 50), device.height / 10])
}
}
//儲存資料
function 儲存資料() {
map.put("gk", ui.gk.text());
map.put("gk1", ui.gk1.text());
map.put("tl", ui.tl.text());
map.put("tl1", ui.tl1.text());
};
function 倒計時(mix1, max2) {
var 倒數 = random(Number(mix1), Number(max2))
log("随機延遲:" + 倒數)
while (true) {
if (倒數 <= 0) {
toastLog("倒計時完畢")
sleep(1000)
break
}
toastLog("倒計時:" + 倒數)
sleep(2000)
倒數 -= 2
}
}
可以設定刷多少個視訊,每個視訊播放的時間!
有不明白的地方可以私信我。直接複制代碼就可以運作。
4.後續功能
功能會持續更新,下期将點贊的代碼提供給大家。謝謝大家的支援!