You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

187 lines
8.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

try {
// 指定小红书的包名
var packageName = "com.xingin.xhs"; // 确保这个包名是正确的
// 检查包名是否存在
if (app.getAppName(packageName)) {
// 使用包名启动应用
toast("启动小红书...");
app.launch(packageName);
log("Package launched: " + packageName);
sleep(5000); // 等待应用启动
} else {
toast("找不到小红书应用");
log("Error: 找不到小红书应用");
exit();
}
// 添加刷新动作,从上往下滑动
toast('开始刷新主页面...');
swipe(540, 500, 540, 1500, 500); // 从屏幕上方向下滑动
sleep(2000); // 等待刷新完成
console.log('刷新主页面完成');
// 使用文本查找直播区域控件
var liveAreaButtonText = '直播'; // 假设这是直播区域的文本
var liveAreaButton = text(liveAreaButtonText).visibleToUser().findOne(10000);
if (liveAreaButton) {
var bounds = liveAreaButton.bounds();
var centerX = bounds.centerX();
var centerY = bounds.centerY();
log('找到直播区域按钮,中心坐标: (' + centerX + ', ' + centerY + ')');
toast('准备点击直播区域按钮');
click(centerX, centerY);
sleep(5000);
console.log('点击直播区域按钮');
} else {
console.error("未找到直播区域按钮: " + liveAreaButtonText);
toast("未找到直播区域按钮: " + liveAreaButtonText);
exit();
}
// 进入具体直播间(通过控件 ID
var specificLiveButtonId = 'com.xingin.xhs:id/eox'; // 假设这是具体直播间控件的ID
var specificLiveButton = id(specificLiveButtonId).visibleToUser().findOne(5000);
if (specificLiveButton) {
var bounds = specificLiveButton.bounds();
var centerX = bounds.centerX();
var centerY = bounds.centerY();
log('找到具体直播间按钮,中心坐标: (' + centerX + ', ' + centerY + ')');
toast('准备点击具体直播间按钮');
click(centerX, centerY);
sleep(5000);
console.log('点击具体直播间按钮');
} else {
console.error("未找到具体直播间按钮: " + specificLiveButtonId);
toast("未找到具体直播间按钮: " + specificLiveButtonId);
exit();
}
var comment;
var centerX;
var centerY;
for (var j = 0; j < 3; j++)
{
// 询问用户是否自行输入评论
var userInputChoice = confirm("您想要自行输入评论吗?", ["是", "否"]);
console.log(userInputChoice)
// 点击编辑文本框使用desc方法
var editTextDesc = "评论输入框"; // 假设这是编辑文本框的描述
var editTextInput = desc(editTextDesc).visibleToUser().findOne(5000);
if (editTextInput) {
var bounds = editTextInput.bounds();
var centerX = bounds.centerX();
var centerY = bounds.centerY();
log('找到编辑文本框,中心坐标: (' + centerX + ', ' + centerY + ')');
toast('准备点击编辑文本框');
click(centerX, centerY);
sleep(2000);
console.log('点击编辑文本框');
} else {
console.error("未找到编辑文本框");
toast("未找到编辑文本框");
exit();
}
if (userInputChoice) {
// 用户选择自行输入
var inputId = 'com.xingin.xhs:id/ft5'; // 假设这是具体直播间控件的ID
var selectInputId = id(inputId).visibleToUser().findOne(5000);
comment = selectInputId.text();
// comment = getInputText(); // 替换为获取外部输入框文本的函数
console.log(comment)
setText(comment); // 输入评论内容
sleep(5000); // 等待输入完成
// 点击发送按钮
var centerXX;
var centerYY;
var sendButtonId = 'com.xingin.xhs:id/hz5'; // 假设这是发送按钮的ID
var sendButton = id(sendButtonId).visibleToUser().findOne(10000);
if (sendButton) {
var bounds = sendButton.bounds();
centerXX = bounds.centerX();
centerYY = bounds.centerY();
log('找到发送按钮,中心坐标: (' + centerX + ', ' + centerY + ')');
toast('准备点击发送按钮');
click(centerXX, centerYY);
sleep(5000); // 等待发送完成
console.log('点击发送按钮');
} else {
console.error("未找到发送按钮: " + sendButtonId);
}
var num = 10;
for (var k = 0; k < num; k++) {
// 重新点击编辑文本框,准备下一条评论
editTextInput = desc(editTextDesc).visibleToUser().findOne(5000);
if (editTextInput) {
click(centerX, centerY);
sleep(1000); // 等待文本框激活
setText(comment); // 输入评论内容
sleep(1000); // 等待发送完成
click(centerXX, centerYY);
sleep(5000); // 等待发送完成
console.log('点击发送按钮');
} else {
console.error("未找到编辑文本框,无法继续发布评论");
break;
}
}
} else {
// 评论内容数组,增加了更多评论选项
var comments = [
"好文章!", "赞一个!", "很有帮助!", "学习到了!",
"期待更多分享!", "这真的很棒!", "非常喜欢这篇!",
"非常有趣!", "太感谢了!", "内容很精彩!",
"我也有同样的感觉!", "你说的太对了!", "继续加油!",
"分享得很好!", "希望能看到更多!", "值得推荐!",
"真是个好主意!", "看完受益匪浅!", "这让我想到了...",
"很不错的观点!", "写得真好!", "我完全同意你的看法!",
"太精彩了,继续努力!", "你真是个天才!", "希望你能多分享一些!"
];
var numberOfComments = 3; // 设置要发布的评论数量
// 发布评论
for (var i = 0; i < numberOfComments; i++) {
// 随机选择评论内容
var randomIndex = random(0, comments.length - 1);
var randomComment = comments[randomIndex];
log('准备输入评论: ' + randomComment);
setText(randomComment); // 输入评论内容
sleep(1000); // 等待输入完成
// 点击发送按钮
var sendButtonId = 'com.xingin.xhs:id/hz5'; // 假设这是发送按钮的ID
var sendButton = id(sendButtonId).visibleToUser().findOne(10000);
if (sendButton) {
var bounds = sendButton.bounds();
var centerXXX = bounds.centerX();
var centerYYY = bounds.centerY();
log('找到发送按钮,中心坐标: (' + centerXXX + ', ' + centerYYY + ')');
toast('准备点击发送按钮');
click(centerXXX, centerYYY);
sleep(5000); // 等待发送完成
console.log('点击发送按钮');
} else {
console.error("未找到发送按钮: " + sendButtonId);
break; // 如果找不到发送按钮,退出循环
}
// 重新点击编辑文本框,准备下一条评论
editTextInput = desc(editTextDesc).visibleToUser().findOne(5000);
if (editTextInput) {
click(editTextInput.bounds().centerX(), editTextInput.bounds().centerY());
sleep(2000); // 等待文本框激活
} else {
console.error("未找到编辑文本框,无法继续发布评论");
break;
}
}
}
}
toast('end, AutoX.js');
} catch (e) {
toast("脚本执行异常: " + e.toString());
console.error("脚本执行异常: " + e.toString());
}