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.

178 lines
5.1 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.

// 确保无障碍服务已开启
auto.waitFor();
// 定义小红书包名
var packageName = "com.xingin.xhs";
// 创建悬浮窗
var window = floaty.window(
<frame gravity="center" bg="#88000000">
<vertical padding="10">
<text text="直播点赞控制" textColor="#ffffff" textSize="16sp"/>
<input id="countInput" hint="点赞次数(默认1000)" textColor="#ffffff" textSize="14sp" focusable="true"/>
<input id="speedInput" hint="点赞间隔ms(默认200)" textColor="#ffffff" textSize="14sp" focusable="true"/>
<horizontal>
<button id="start" text="开始" w="80" h="40"/>
<button id="pause" text="暂停" w="80" h="40"/>
<button id="ok" text="确定" w="80" h="40"/>
<button id="exit" text="退出" w="80" h="40"/> // 添加退出按钮
</horizontal>
<text id="status" text="状态:等待开始" textColor="#ffffff" textSize="14sp"/>
<text id="counter" text="已点赞0" textColor="#ffffff" textSize="14sp"/>
</vertical>
</frame>
);
// 设置悬浮窗位置
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);