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.

431 lines
16 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.

// // 创建悬浮窗
// var window = floaty.window(
// <vertical>
// <button id="task1" text="进入直播间" w="auto" h="40"/>
// <button id="task2" text="自动点赞" w="auto" h="40"/>
// <button id="task3" text="滑屏点赞关注" w="auto" h="40"/>
// <button id="task4" text="发评论" w="auto" h="40"/>
// <button id="task5" text="自动发帖" w="auto" h="40"/>
// </vertical>
// );
// window.setPosition(100, 100);
// // 布尔值用来跟踪任务的运行状态
// var isTask1Running = false;
// var isTask2Running = false;
// var isTask3Running = false;
// var isTask4Running = false;
// var isTask5Running = false;
var taskThread1, taskThread2, taskThread3, taskThread4, taskThread5;
var isTask1Running = false, isTask2Running = false, isTask3Running = false, isTask4Running = false, isTask5Running = false;
// 创建悬浮窗
var window = floaty.window(
<vertical>
<button id="task1" text="进入直播间" w="auto" h="40"/>
<button id="task2" text="自动点赞" w="auto" h="40"/>
<button id="task3" text="滑屏点赞关注" w="auto" h="40"/>
<button id="task4" text="发评论" w="auto" h="40"/>
<button id="task5" text="自动发帖" w="auto" h="40"/>
</vertical>
);
window.setPosition(100, 100);
// 用于中断所有正在运行的任务
function stopAllTasks() {
if (taskThread1 && taskThread1.isAlive()) taskThread1.interrupt();
if (taskThread2 && taskThread2.isAlive()) taskThread2.interrupt();
if (taskThread3 && taskThread3.isAlive()) taskThread3.interrupt();
if (taskThread4 && taskThread4.isAlive()) taskThread4.interrupt();
if (taskThread5 && taskThread5.isAlive()) taskThread5.interrupt();
isTask1Running = isTask2Running = isTask3Running = isTask4Running = isTask5Running = false;
}
// 任务1启动并操作小红书应用
function task1() {
while (!threads.currentThread().isInterrupted()) {
var packageName = "com.xingin.xhs";
// 启动小红书应用
if (app.getAppName(packageName)) {
toast("启动小红书...");
app.launch(packageName);
log("Package launched: " + packageName);
sleep(3000); // 等待应用启动
} else {
toast("找不到小红书应用");
log("Error: 找不到小红书应用");
return;
}
// 刷新主页
toast('刷新主页面...');
swipe(540, 500, 540, 1500, 500);
sleep(2000);
console.log('主页刷新完成');
// 查找并进入直播区域
var liveAreaButtonText = '直播'; // 确保文本正确
var liveAreaButton = text(liveAreaButtonText).visibleToUser().findOne(10000);
if (liveAreaButton) {
click("直播");
sleep(2000);
console.log('已进入直播区域');
} else {
console.error("未找到直播区域按钮: " + liveAreaButtonText);
return;
}
// 进入具体直播间
var specificLiveButtonId = 'com.xingin.xhs:id/eox';
var specificLiveButton = id(specificLiveButtonId).visibleToUser().findOne(2000); // 加长查找等待时间
if (specificLiveButton) {
var bounds = specificLiveButton.bounds();
click(bounds.centerX(), bounds.centerY()+500);
sleep(2000); // 等待直播间加载
console.log('已进入具体直播间');
}
}
}
//任务5自动发帖
function task5() {
while (!threads.currentThread().isInterrupted()) {
function clickbutton(buttonid)
{
if (buttonid)
{
var button = id(buttonid).visibleToUser().findOne();
if (button)
{
var bounds = button.bounds();
var centerX = bounds.centerX();
var centerY = bounds.centerY();
click(centerX,centerY);
}
}
}
var addButtonId = 'com.xingin.xhs:id/dvd';//需要修改
clickbutton(addButtonId);
sleep(1000);
var wenzi = text("文字").findOne();
click("文字");
var taolunId = 'com.xingin.xhs:id/ca8'; //需要修改
clickbutton(taolunId);
// 定义评论内容
var comments = ["好天气!", "赞一个!", "好开心!", "软件工程!", "auto.js!"];
//找评论框
var kuangId = 'com.xingin.xhs:id/bhc'; //需要修改
clickbutton(kuangId);
//输入评论
if (kuangId)
{
var randomComment = comments[random(0, comments.length - 1)];
log('准备输入评论: ' + randomComment);
var editText = id("bhc").findOne(2000); //要修改
setText(randomComment);
sleep(2000);
var nextId = 'com.xingin.xhs:id/bed'; //需要修改
clickbutton(nextId);
sleep(5000);
var nextId2 = 'com.xingin.xhs:id/g48'; //需要修改
clickbutton(nextId2);
sleep(2000);
var fabu = 'com.xingin.xhs:id/alz'; //需要修改
clickbutton(fabu);
}
}
}
function task2() {
while (!threads.currentThread().isInterrupted()) {
// 创建悬浮窗
var window = floaty.window(
<vertical gravity="center" w="wrap_content" h="wrap_content" bg="#FFFFFF" padding="16">
<text textColor="#000000" textSize="16sp" margin="8">点赞速度</text>
<seekbar id="speedSlider" max="18" progress="5" w="120" h="30" />
<text id="speedText" textColor="#000000" textSize="16sp" margin="8">0.5/</text>
</vertical>
);
// 设置悬浮窗的位置
window.setPosition(700, 300);
// 初始化点赞速度
var currentInterval = 500; // 初始间隔为0.5秒
var totalLikes = 300; // 总共点赞次数
var likesCount = 0; // 当前点赞次数
// 监听进度条变化
window.speedSlider.setOnSeekBarChangeListener({
onProgressChanged: function(seekBar, progress, fromUser) {
var newInterval = (progress + 2) * 100; // 映射到200-2000毫秒
currentInterval = newInterval;
window.speedText.setText((newInterval / 1000).toFixed(1) + "秒/次");
},
onStartTrackingTouch: function(seekBar) {},
onStopTrackingTouch: function(seekBar) {}
});
// 自动点赞功能
function autoLike(interval) {
if (likesCount >= totalLikes) {
toast("点赞完成!");
return;
}
var likeButtonId = 'com.xingin.xhs:id/tl'; // 假设这是点赞按钮的ID
var likeButton = id(likeButtonId).visibleToUser().findOne(10000);
if (likeButton) {
log('找到点赞按钮,准备点赞');
var likeBounds = likeButton.bounds();
var likeCenterX = likeBounds.centerX();
var likeCenterY = likeBounds.centerY();
// 快速连续点击两次
click(likeCenterX, likeCenterY);
sleep(100); // 短暂延迟,确保第一次点击生效
click(likeCenterX, likeCenterY);
likesCount++;
log('已点赞 ' + likesCount + ' 次');
} else {
console.error("未找到点赞按钮: " + likeButtonId);
toast("未找到点赞按钮: " + likeButtonId);
}
// 递归调用自身,实现持续点赞
setTimeout(() => {
autoLike(currentInterval);
}, interval);
}
// 开始点赞
autoLike(currentInterval);
toast('点赞开始,可以通过悬浮窗调整点赞速度');
}
}
function task3() {
while (!threads.currentThread().isInterrupted()) {
// 迭代查找直播间并进行点赞和滑动
var maxScrolls = 10; // 最大滑动次数
var swipeInterval = 3000; // 滑动间隔时间,可以加长等待时间
for (var i = 0; i < maxScrolls; i++) {
// 自动点赞
var likeButtonId = 'com.xingin.xhs:id/tl'; // 点赞按钮的ID
var likeButton = id(likeButtonId).visibleToUser().findOne(10000);
if (likeButton) {
log('找到点赞按钮,准备点赞');
var likeBounds = likeButton.bounds();
var likeCenterX = likeBounds.centerX();
var likeCenterY = likeBounds.centerY();
click(likeCenterX, likeCenterY);
sleep(100);
click(likeCenterX, likeCenterY);
console.log('完成点赞');
} else {
console.error("未找到点赞按钮: " + likeButtonId);
}
// 查找关注按钮并点击
var followButtonId = 'com.xingin.xhs:id/j10';
var followButton = id(followButtonId).visibleToUser().findOne();
if (followButton) {
var bounds = followButton.bounds();
click(bounds.centerX(), bounds.centerY());
sleep(1000);
} else {
log("未找到关注按钮: " + followButtonId);
}
// 滑动到下一个直播
sleep(2000);
toast('滑动到下一个直播间...');
swipe(540, 1200, 540, 500, 500); // 定义在直播间的滑动动作
sleep(5000);
console.log('滑动完成');
}
}
}
function task4() {
while (!threads.currentThread().isInterrupted()) {
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(7000); // 等待输入完成
// 点击发送按钮
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(3000); // 等待发送完成
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');
}
}
// 按钮事件监听
window.task1.click(() => {
stopAllTasks();
isTask1Running = true;
taskThread1 = threads.start(task1);
});
window.task2.click(() => {
stopAllTasks();
isTask2Running = true;
taskThread2 = threads.start(task2);
});
window.task3.click(() => {
stopAllTasks();
isTask3Running = true;
taskThread3 = threads.start(task3);
});
window.task4.click(() => {
stopAllTasks();
isTask4Running = true;
taskThread4 = threads.start(task4);
});
window.task5.click(() => {
stopAllTasks();
isTask5Running = true;
taskThread5 = threads.start(task5);
});
// 保持悬浮3窗和主线程运行
setInterval(() => {}, 1000);