// 确保无障碍服务已开启
auto.waitFor();
// 定义小红书包名
var packageName = "com.xingin.xhs";
// 创建悬浮窗
var window = floaty.window(
// 添加退出按钮
);
// 设置悬浮窗位置
window.setPosition(50, 100);
// 初始化变量
var isRunning = false;
var isPaused = false;
var clickCount = 0;
var targetCount = 1000;
var clickInterval = 200;
var clickThread = null;
var dd = 0;
// 输入框事件处理
function setupInput(windowInput) {
windowInput.on("key", function(keyCode, event) {
if (event.getAction() == event.ACTION_DOWN && keyCode == keys.back) {
window.disableFocus();
event.consumed = true;
}
});
windowInput.on("touch_down", () => {
window.requestFocus();
windowInput.requestFocus();
});
}
setupInput(window.countInput);
setupInput(window.speedInput);
// 确定按钮事件
window.ok.on("click", () => {
let input1Content = window.countInput.getText();
let input2Content = window.speedInput.getText();
if (input1Content == "") input1Content = 1000;
if (input2Content == "") input2Content = 200;
targetCount = parseInt(input1Content);
clickInterval = parseInt(input2Content);
window.disableFocus();
dd = (dd == 0 ? 1 : 0);
log("点赞次数: " + targetCount);
log("点赞间隔: " + clickInterval);
});
// 双击函数
function doubleClick(x, y) {
click(x, y);
sleep(20);
click(x, y);
sleep(20);
click(x, y);
}
// 开始按钮事件
window.start.click(() => {
if (!isRunning) {
isRunning = true;
isPaused = false;
window.start.setText("停止");
// 启动点赞线程
clickThread = threads.start(function() {
while (isRunning) {
if (!isPaused) {
try {
// 执行点赞
doubleClick(500, 1300);
clickCount++;
// 更新计数器
ui.run(() => {
window.counter.setText("已点赞:" + clickCount);
window.status.setText("状态:正在点赞");
});
// 控制点赞间隔
sleep(clickInterval);
} catch (e) {
toast("错误: " + e);
}
} else {
sleep(100);
}
}
});
} else {
// 停止点赞
isRunning = false;
window.start.setText("开始");
window.status.setText("状态:已停止");
if (clickThread != null) {
clickThread.interrupt();
}
}
});
// 暂停按钮事件
window.pause.click(() => {
if (isRunning) {
isPaused = !isPaused;
window.pause.setText(isPaused ? "继续" : "暂停");
window.status.setText("状态:" + (isPaused ? "已暂停" : "正在点赞"));
}
});
// 退出按钮事件
window.exit.on("click", () => {
isRunning = false;
if (clickThread != null) {
clickThread.interrupt();
}
toast("脚本已退出");
exit(); // 退出脚本
});
// 启动小红书并进入直播间
function startXiaohongshu() {
app.launchPackage(packageName);
toast("小红书已打开");
sleep(3000);
swipe(500, 1200, 500, 1320, 700);
let zhibo = desc("直播").findOne();
if (zhibo) {
let bounds = zhibo.bounds();
click(bounds.left + 50, bounds.top + 50);
sleep(3000);
click(337, 800);
sleep(2000);
return true;
}
return false;
}
// 启动应用
if (startXiaohongshu()) {
toast("已进入直播间,请调整点赞参数");
} else {
toast("进入直播间失败");
}
// 保持脚本运行
setInterval(() => {
if (!auto.service) {
toast("无障碍服务已关闭!");
isRunning = false;
}
}, 1000);