這期給大家加上按標題關鍵字,來評論我們設置好的話術。大家想增加什么功能,可以留言,做好后分享給大家。廢話不多說,直接上代碼
一、還是給大家展示下難看的UI界面
本次也會將自動刷視頻,自動點贊的代碼提供給大家,想看詳細的解釋,看我前面的文章就可以了。
二、代碼講解
(1)增加評論開關和話術文本框。
<linear padding="5 0 0 0">
<text textSize="16sp" textSize="15sp" textColor="black" text="評論開關" />
<Switch id="plkg" textColor="red" checked="true" />
</linear>
<linear padding="5 0 0 0">
<text textColor="black" text="標題關鍵字:" />
<input id="btmc" w="120" text="腳本" />
</linear>
<linear padding="5 0 0 0">
<text textColor="black" text="評論內容1:" />
<input id="plnr" w="240" text="阿輝腳本V:YH841280" />
</linear>
(2)評論的主要代碼。在獲取標題控件的時候,可以采用兩種方式。
1.visibleToUser(true);控件是否可見。
2.boundsInside(x,y,x2,y2);限定范圍。
我采用的是第一種方式,如果不加這兩個限定,我們獲取的評論標題則是上一個視頻的標題。
下面的代碼就是將評論按鈕打開,將我們設置好的話術評論。如果不知道怎么怎么點擊評論按鈕的,可以看下我上一篇文章的講解。
function 評論功能() {
//獲取標題控件
var 標題 = className('android.widget.TextView').depth(24).drawingOrder(1).visibleToUser(true).findOnce();
if (標題) {
//標題內容
var titleText = 標題.text();
log(titleText);
//設置的關鍵字
var keyword = ui.btmc.text();
log(keyword)
//判斷標題中是否存在關鍵字
if (titleText.indexOf(keyword) != -1) {
var weight = map.get("評論");
var left = weight.left;
var right = weight.right;
var top = weight.top;
var bottom = weight.bottom;
var x = random(left, right)
var y = random(top, bottom)
click(x, y);
text('留下你的精彩評論吧').waitFor();
click('留下你的精彩評論吧');
sleep(1000)
var 評論1 = ui.plnr.text();
setText(評論1);
//點擊發送
var 發送 = className('android.widget.ImageView').depth(10).drawingOrder(7).visibleToUser(true).findOne();
發送.click();
sleep(1000);
//關閉評論
var x = className('android.widget.ImageView').depth(6).drawingOrder(5).visibleToUser(true).findOne();
x.click();
// sleep(1000);
} else {
log('不包含關鍵字')
}
}
}
二、完成代碼如下
"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">
<text textSize="16sp" textSize="15sp" textColor="black" text="點贊開關" />
<Switch id="dzkg" textColor="red" checked="true" />
</linear>
<linear padding="5 0 0 0">
<text textColor="black" text="點贊概率" />
<input id="dzgl" w="auto" inputType="number" text="50" />
<text textColor="black" text="%" />
</linear>
<linear padding="5 0 0 0">
<text textSize="16sp" textSize="15sp" textColor="black" text="評論開關" />
<Switch id="plkg" textColor="red" checked="true" />
</linear>
<linear padding="5 0 0 0">
<text textColor="black" text="標題關鍵字:" />
<input id="btmc" w="120" text="腳本" />
</linear>
<linear padding="5 0 0 0">
<text textColor="black" text="評論內容1:" />
<input id="plnr" w="240" text="阿輝腳本V:YH841280" />
</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.dzgl.setText(map.get('dzgl'));
ui.btmc.setText(map.get('btmc'));
ui.plnr.setText(map.get('plnr'));
}
//指定確定按鈕點擊時要執行的動作
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 養號功能() {
保存數據();
//等待關注的出現
desc("關注").waitFor();
//保存點贊坐標
獲取坐標();
sleep(1000);
//獲取 需要刷的視頻數
var 視頻數 = random(Number(ui.gk.text()), Number(ui.gk1.text()));
toastLog("正在進行養號功能");
sleep(2000);
for (let i = 0; i < 視頻數; i++) {
倒計時(ui.tl.text(), ui.tl1.text())
toastLog("養號進度:" + (i + 1) + "/" + 視頻數)
sleep(random(1500, 1800))
//看的差不多了 開始點贊
if (ui.dzkg.checked) {
點贊功能()
}
if (ui.plkg.checked) {
評論功能();
}
sleep(2000)
gesture(500,
[device.width / 2, (device.height / 2) + (device.height / 2) / 2],
[random(50, device.width - 50), device.height / 10])
}
}
//點贊功能
function 點贊功能() {
var 點贊概率 = Number(ui.dzgl.text());
//隨機取一個數值
var 概率 = random(1, 100);
//開始點贊
if (點贊概率 >= 概率) {
var weight = map.get("點贊");
var left = weight.left;
var right = weight.right;
var top = weight.top;
var bottom = weight.bottom;
//隨機取一點進行點擊
var x = random(left, right)
var y = random(top, bottom)
click(x, y)
}
};
function 評論功能() {
//獲取標題控件
var 標題 = className('android.widget.TextView').depth(24).drawingOrder(1).visibleToUser(true).findOnce();
if (標題) {
//標題內容
var titleText = 標題.text();
log(titleText);
//設置的關鍵字
var keyword = ui.btmc.text();
log(keyword)
//判斷標題中是否存在關鍵字
if (titleText.indexOf(keyword) != -1) {
var weight = map.get("評論");
var left = weight.left;
var right = weight.right;
var top = weight.top;
var bottom = weight.bottom;
var x = random(left, right)
var y = random(top, bottom)
click(x, y);
text('留下你的精彩評論吧').waitFor();
click('留下你的精彩評論吧');
sleep(1000)
var 評論1 = ui.plnr.text();
setText(評論1);
//點擊發送
var 發送 = className('android.widget.ImageView').depth(10).drawingOrder(7).visibleToUser(true).findOne();
發送.click();
sleep(1000);
//關閉評論
var x = className('android.widget.ImageView').depth(6).drawingOrder(5).visibleToUser(true).findOne();
x.click();
// sleep(1000);
} else {
log('不包含關鍵字')
}
}
}
//獲取坐標
function 獲取坐標() {
toast("正在獲取坐標,請稍后");
var point = [];
//獲取點贊坐標
weight = descStartsWith("未選中").findOne().bounds();
if (this.坐標驗證(weight)) {
map.put("點贊", weight);
}
//獲取評論坐標
weight = descStartsWith("評論").findOne().bounds();
if (this.坐標驗證(weight)) {
map.put("評論", weight);
}
}
//坐標驗證
function 坐標驗證() {
var left = weight.left;
var right = weight.right;
var top = weight.top;
var bottom = weight.bottom;
if (left > 0 && right > 0 && top > 0 && bottom > 0) {
return true;
} else {
return false;
}
}
//保存數據
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());
map.put("dzgl", ui.dzgl.text());
map.put("btmc", ui.btmc.text());
map.put("plnr", ui.plnr.text());
};
function 倒計時(mix1, max2) {
var 倒數 = random(Number(mix1), Number(max2))
log("隨機延遲:" + 倒數)
while (true) {
if (倒數 <= 0) {
toastLog("倒計時完畢")
sleep(1000)
break
}
toastLog("倒計時:" + 倒數)
sleep(2000)
倒數 -= 2
}
}
4.后續功能
代碼直接復制就可以運行,功能會持續更新,也請大家多提提意見和方向,大家想要什么功能,可以留言,我盡快給大家將代碼提供出來。謝謝大家的支持!