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.

128 lines
4.8 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(2000); // 等待应用启动
} 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(2000);
console.log('点击直播区域按钮');
} else {
console.error("未找到直播区域按钮: " + liveAreaButtonText);
toast("未找到直播区域按钮: " + liveAreaButtonText);
exit();
}
// 进入具体直播间(通过控件 ID
var specificLiveButtonId = 'com.xingin.xhs:id/eox'; // 假设这是具体直播间控件的ID
var specificLiveButton = id(specificLiveButtonId).visibleToUser().findOne(10000);
if (specificLiveButton) {
var bounds = specificLiveButton.bounds();
var centerX = bounds.centerX();
var centerY = bounds.centerY();
log('找到具体直播间按钮,中心坐标: (' + centerX + ', ' + centerY + ')');
toast('准备点击具体直播间按钮');
click(centerX, centerY);
sleep(3000);
console.log('点击具体直播间按钮');
} else {
console.error("未找到具体直播间按钮: " + specificLiveButtonId);
toast("未找到具体直播间按钮: " + specificLiveButtonId);
exit();
}
// 创建悬浮窗
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(100, 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('点赞开始,可以通过悬浮窗调整点赞速度');
} catch (e) {
toast("脚本执行异常: " + e.toString());
console.error("脚本执行异常: " + e.toString());
}