diff --git a/自动滑动点赞关注.js b/自动滑动点赞关注.js new file mode 100644 index 0000000..f29bec7 --- /dev/null +++ b/自动滑动点赞关注.js @@ -0,0 +1,127 @@ +const appPackageName = "com.xingin.xhs"; // 小红书的包名 + +// 自动打开小红书APP +function openXiaohongshu() { + console.log("正在检查小红书是否已经打开..."); + if (currentPackage() != appPackageName) { + console.log("小红书未打开,正在启动小红书..."); + launch(appPackageName); + sleep(3000); // 增加等待加载时间 + } else { + console.log("小红书已打开,继续操作..."); + } +} + +// 尝试找到直播按钮并点击 +function clickLiveTab() { + try { + console.log("尝试找到直播按钮..."); + let liveButton = id("ims").className("android.view.ViewGroup").desc("直播").findOne(3000); + if (liveButton) { + liveButton.parent().click(); + console.log("点击了直播按钮"); + return true; + } else { + console.log("未找到直播按钮"); + return false; + } + } catch (e) { + console.error("点击直播按钮时出错: " + e); + return false; + } +} + +// 进入直播并随机选择一个直播间,自动滑屏 +function enterRandomLiveRoom() { + console.log("准备进入直播页面..."); + openXiaohongshu(); + sleep(3000); + + if (clickLiveTab()) { + console.log("进入直播页面,等待加载..."); + sleep(3000); // 增加等待时间,确保直播页面加载完成 + + // 假设屏幕尺寸为 2K (1440x2560) + let screenWidth = 1440; + let screenHeight = 2560; + + // 输出屏幕尺寸 + console.log("假设屏幕宽度:" + screenWidth + ",高度:" + screenHeight); + + // 点击屏幕下半部分 + let clickX = screenWidth * 2 / 3; + let clickY = screenHeight * 2 / 4; + console.log("点击坐标 (x, y): (" + clickX + ", " + clickY + ")"); + + let result = click(clickX, clickY); + if (result) { + console.log("点击了屏幕下半部分,尝试进入直播间"); + + // 自动滑屏 + autoSwipe(screenWidth, screenHeight); + } else { + console.log("点击失败,请检查权限"); + } + } else { + console.log("无法进入直播页面"); + } +} + +// 自动滑屏和双击点赞功能,每次滑屏前点击关注按钮 +function autoSwipe(screenWidth, screenHeight) { + console.log("开始自动滑屏..."); + let swipeCount = 5; // 设置滑动次数 + for (let i = 0; i < swipeCount; i++) { + console.log("正在滑动屏幕,第 " + (i + 1) + " 次"); + + // 尝试点击关注按钮 + try { + let followButton = id("j39").findOne(2000); + if (followButton) { + let bounds = followButton.bounds(); // 获取按钮的边界信息 + if (bounds) { + let centerX = bounds.centerX(); + let centerY = bounds.centerY(); + + // 输出 bounds 坐标信息 + console.log("关注按钮的 bounds: 左上角(" + bounds.left + ", " + bounds.top + "), 右下角(" + bounds.right + ", " + bounds.bottom + ")"); + console.log("点击坐标 (x, y): (" + centerX + ", " + centerY + ")"); + + // 使用坐标点击关注按钮 + click(centerX, centerY); + console.log("通过坐标点击了关注按钮"); + } else { + console.log("无法获取关注按钮的边界信息"); + } + } else { + console.log("未找到关注按钮"); + } + } catch (e) { + console.error("点击关注按钮时出错: " + e); + } + + // 从屏幕下方向上滑动 + swipe(screenWidth / 2, screenHeight * 3 / 4, screenWidth / 2, screenHeight / 4, 500); + sleep(2000); // 每次滑动后等待2秒 + + // 双击屏幕中央实现点赞 + let centerX = screenWidth / 2; + let centerY = screenHeight / 2; + console.log("双击坐标 (x, y): (" + centerX + ", " + centerY + ")"); + + // 第一次点击 + click(centerX, centerY); + sleep(50); // 短暂延迟,模拟双击 + // 第二次点击 + click(centerX, centerY); + console.log("已点赞当前直播间"); + + sleep(2000); // 每次双击点赞后再等待2秒 + } + console.log("滑屏操作结束"); +} + +// 执行进入随机直播间功能 +console.log("开始执行进入随机直播间功能..."); +enterRandomLiveRoom(); +console.log("脚本执行完毕");