TAG = "DYSX-> ";
SAVED = storages.create(“dyzs”);
COUNT = 0;
function ErrorHandle(Msg, suicide) {
console.setSize(device.width / 2, device.height);
console.show();
console.error(Msg);
if (suicide) {
threads.shutDownAll();
engines.stopAll();
}
runtime.sleep(5000);
console.hide();
};
function clickItem(item) {
if (!item) {
return false
}
item.click();
let area = item.bounds();
let x = area.centerX();
let y = area.centerY();
try {
click(x, y);
} catch (e) {
try {
Tap(x, y);
runtime.sleep(1000);
} catch (e) {
try {
var ra = new RootAutomator();
// 保险点击
ra.tap(x, y, 1);
runtime.sleep(800);
ra.press(x, y, 10, 1);
ra.exit();
} catch (e) {
ErrorHandle(“在此设备上需要Root权限才能运行本脚本!”, true);
}
}
}
}
function clickHelper(item, is_auto, is_root, is_ge_sdk23) {
if (!item) {
return false
}
if (is_auto) {
item.click();
return
}
let area = item.bounds();
let x = area.centerX();
let y = area.centerY();
if (is_ge_sdk23) {
// Android 7.0 以上的点击
click(x, y);
}
if (is_root) {
try {
Tap(x, y);
runtime.sleep(1000);
} catch (e) {
try {
var ra = new RootAutomator();
// 保险点击
ra.tap(x, y, 1);
runtime.sleep(800);
ra.press(x, y, 10, 1);
ra.exit();
} catch (e) {
ErrorHandle("在此设备上需要Root权限才能运行本脚本!", true);
}
}
}
}
function getGender() {
function genderRecog(text_) {
// 预备性别校验(根据文本)
let gender = “未知”;
const p1 = new RegExp(“男”);
const p2 = new RegExp(“女”);
if (p1.test(text_)) {
gender = “男”;
} else if (p2.test(text_)) {
gender = “女”;
} else {
function warpGenderRec() {
let W_gender = null;
if (textEndsWith(“岁”).findOne(2000)) {
Z = textEndsWith(“岁”).findOne().bounds();
console.hide();
ox = Z.left + device.width / 1080 * 23;
oy = Z.top + device.height / 1920 * 32;
console.log(TAG + “定位颜色点坐标X Y为:”, ox, oy);
colorValue = images.pixel(images.captureScreen(), ox, oy);
console.info(TAG + “colorValueAbs: " + colorValue);
if (colorValue + 16211275 < 2000000) {
W_gender = “男”;
} else if (colorValue + 2537115 < 2000000) {
W_gender = “女”;
}
}
return W_gender
}
// 执行函数
gender = warpGenderRec();
}
return gender
}
try {
msgUi = id(“d4z”).findOne(4000).children();
} catch (e) {
if (text(“男”).findOne(3000)) { return “男” } else return genderRecog(”");
}
}
console.verbose(msg_);
gender = genderRecog(msg_);
return gender
}
function SendMsg() {
if (id(“abe”).findOne(1000)) {
toastLog(TAG + “企业用户,返回继续下一个”);
return false
}
if (getGender() != “男”) {
toastLog(TAG + “不符合性别条件,返回继续”);
return false
} else {
toastLog(TAG + “符合性别条件,开始进行消息发送”)
};
toastLog(TAG + “点击关注”);
runtime.sleep(1500);
if (!id(“cst”).findOne(2000)) {
console.show();
console.error(TAG + “关注失败1:”);
// console.log(id(“cac”).findOne(1000));
runtime.sleep(2000);
console.hide();
click(597, 475);
runtime.sleep(1000);
click(597, 475);
}
if (dealFlashWin(5)){
return false
}
if (text("已请求").findOne(100)){
return false
}
} else {
toastLog(TAG + "关注失败");
return false
};
toastLog(TAG + "开始发送私信消息");
// 点击私信
try {
id("cst").findOne(3000).click();
} catch (e) {
click(850, 472);
click(850, 472);
}
dealFlashWin(1);
runtime.sleep(500);
ready_send_msgs = SAVED.get("dy_sx_zh", "").split("\n");
if (ready_send_msgs.length < 1) {
ErrorHandle("招呼设置错误", true);
}
for (let i = 0; i < ready_send_msgs.length; i++) {
a = className("android.widget.EditText").findOne(1000);
a.click();
let t = ready_send_msgs[i];
console.verbose(TAG + "设置消息:[" + i + "] " + t);
className("android.widget.EditText").findOne(2000).setText(t);
runtime.sleep(1000);
className("android.widget.EditText").findOne(2000).setText(t);
className("android.widget.EditText").findOne(2000).setText(t);
runtime.sleep(500);
desc("发送").findOne(6000).click();
runtime.sleep((3 - i) * 2000);
}
COUNT++;
toastLog(TAG + "三条消息发送完毕");
toastLog(TAG + "当前执行成功数 " + COUNT);
}
function returnListPage() {
while (!textEndsWith(“条评论”).findOne(2000)) {
if (id(“j4”).findOne(2000)) {
clickHelper(id(“j4”).findOne(), false, false, true);
} else {
desc(“返回”).findOne(2000).click();
}
toastLog(“点击返回”);
}
return true
}
function Start() {
toastLog(TAG + “等待打开抖音界面”);
runtime.sleep(3000);
let tc = 0;
while (!textEndsWith(“条评论”).findOne(1500)) {
tc++;
if (tc > 30) {
toastLog(TAG + “三秒内未发现抖音界面,脚本退出”);
ErrorHandle(“未发现评论页面,脚本退出”, true);
}
}
do {
// 当前页面处理逻辑
// try {
returnListPage();
runtime.sleep(5000);
CARD_LIST = className(“android.support.v7.widget.RecyclerView”).findOne().children();
SIZE = CARD_LIST.size();
toastLog(TAG + "发现当前页面存在评论人数: " + SIZE);
CARD_LIST.each(
function (CARD_UI) {
console.hide();
runtime.sleep(2000);
if (!CARD_UI_INNER) {
console.error(currentActivity());
console.error(TAG + “元素定位错误!”);
return
}
}
)
console.log(TAG + “当前页面扫描完毕,自动下拉一页”);
// } catch (e) {
// console.error(e.message + “\n” + e.stack);
// ErrorHandle(e.message + “\n\n” + e.stack, false);
// continue
// }
} while (returnListPage() && className(“android.support.v7.widget.RecyclerView”).findOne().scrollForward());
console.warn(TAG + “当前评论页面扫描发送完毕,请检查!”)
}
function dealFlashWin(WIN_TYPE) {
switch (WIN_TYPE) {
case 1:
ui = text(“确认”).findOne(500);
if (ui){
ui.click();
return true
}
case 2:
ui = text(“我知道了”).findOne(500);
if (ui){
ui.click();
return true
}
case 3:
ui = text(“好的”).findOne(500);
if (ui){
ui.click();
return true
}
case 4:
ui = text(“以后再说”).findOne(500);
if (ui){
ui.click();
return true
}
case 5:
ui = text(“取消”).findOne(500);
if (ui){
ui.click();
return true
}
default:
return false
}
}
threads.start(function(){
setInterval(function(){
console.verbose(“监控弹窗ing…”);
dealFlashWin(2);
dealFlashWin(3);
dealFlashWin(4);
},500);
})
Start();