From 812c1af60cb28f629788437a24fcd73dea0c62ed Mon Sep 17 00:00:00 2001 From: pfc8hp2r6 <2317678682@qq.com> Date: Sat, 2 Nov 2024 18:12:13 +0800 Subject: [PATCH] ADD file via upload --- 自动评论.js | 162 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 自动评论.js diff --git a/自动评论.js b/自动评论.js new file mode 100644 index 0000000..80c5d7b --- /dev/null +++ b/自动评论.js @@ -0,0 +1,162 @@ +// 预设的评论短语数组 +let comments = [ + "直播很棒!", + "喜欢这个直播!", + "主播加油!", + "很有趣的内容", + "学到了很多", + "期待下次直播", + "赞一个", + "分享给朋友了", + "继续关注", + "支持主播" +]; + +// 评论间隔时间(毫秒) +let commentInterval = 5000; // 默认间隔5秒 +let running = true; // 控制评论开关 +let paused = false; // 控制是否暂停自动评论 +let lastAddedComment = ""; // 记录最新添加的评论 + +// 生成随机评论的函数 +function generateRandomComment() { + // 优先发送刚添加的评论 + if (lastAddedComment) { + let tempComment = lastAddedComment; + lastAddedComment = ""; // 清空,确保只发送一次 + return tempComment; + } + const randomIndex = Math.floor(Math.random() * comments.length); + return comments[randomIndex]; +} + +// 自动评论的函数 +function autoComment() { + function performComment() { + if (!running || paused) return; // 停止或暂停评论时退出 + + try { + console.log("正在尝试点击评论框..."); + let commentButton = className("android.widget.Button").text("说点什么…").findOne(5000); + sleep(1000); + if (commentButton) { + commentButton.click(); + console.log("点击了评论框"); + } else { + console.error("未找到评论框,重试中..."); + setTimeout(performComment, commentInterval); + return; + } + + console.log("正在输入评论..."); + let commentEditText = className("android.widget.EditText").findOne(5000); + sleep(1000); + if (commentEditText) { + let commentText = generateRandomComment(); + commentEditText.setText(commentText); + console.log("已输入评论文字:" + commentText); + } else { + console.error("未找到输入框,重试中..."); + setTimeout(performComment, commentInterval); + return; + } + + console.log("正在尝试点击发送按钮..."); + let sendButton = className("android.widget.Button").text("发送").findOne(5000); + sleep(1000); + if (sendButton) { + sendButton.click(); + console.log("点击了发送按钮"); + } else { + console.error("未找到发送按钮,重试中..."); + setTimeout(performComment, commentInterval); + return; + } + } catch (e) { + console.error("自动评论过程中发生错误: " + e); + setTimeout(performComment, commentInterval); + } + + setTimeout(performComment, commentInterval); // 动态更新评论间隔 + } + + performComment(); +} + +// 更新显示信息 +function updateDisplay(window) { + window.currentInterval.setText(commentInterval + " ms"); + window.currentComments.setText(comments.join(", ")); +} + +// 创建悬浮窗口 +function createControlWindow() { + ui.run(() => { + let window = floaty.window( + + + + +