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.
163 lines
6.3 KiB
163 lines
6.3 KiB
// 预设的评论短语数组
|
|
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(
|
|
<frame bg="#99000000" w="300" h="300" padding="10" cornerRadius="15dp">
|
|
<vertical gravity="center">
|
|
<text text="自动评论控制" textSize="18sp" textColor="#FFFFFF" gravity="center" />
|
|
<horizontal gravity="center" padding="5">
|
|
<button id="decrease" text="-" w="40" h="40" textColor="#FFFFFF" bg="#FF4081" />
|
|
<text id="currentInterval" text={commentInterval + " ms"} textSize="16sp" textColor="#FFFFFF" w="auto" gravity="center" margin="10"/>
|
|
<button id="increase" text="+" w="40" h="40" textColor="#FFFFFF" bg="#FF4081" />
|
|
</horizontal>
|
|
<horizontal gravity="center" padding="5">
|
|
<text text="当前评论内容:" textColor="#FFFFFF" textSize="14sp" />
|
|
<text id="currentComments" text={comments.join(', ')} textSize="14sp" textColor="#FFFFFF" />
|
|
</horizontal>
|
|
<button id="addComment" text="添加评论内容" w="auto" h="40" bg="#4CAF50" textColor="#FFFFFF" marginTop="5dp"/>
|
|
<button id="stop" text="停止评论" w="auto" h="40" bg="#F44336" textColor="#FFFFFF" marginTop="5dp"/>
|
|
</vertical>
|
|
</frame>
|
|
);
|
|
|
|
// 增加按钮事件
|
|
window.increase.click(() => {
|
|
commentInterval += 1000;
|
|
updateDisplay(window);
|
|
console.log("增加评论间隔:" + commentInterval);
|
|
});
|
|
|
|
// 减少按钮事件
|
|
window.decrease.click(() => {
|
|
commentInterval = Math.max(1000, commentInterval - 1000);
|
|
updateDisplay(window);
|
|
console.log("减少评论间隔:" + commentInterval);
|
|
});
|
|
|
|
// 添加新评论内容
|
|
window.addComment.click(() => {
|
|
paused = true; // 暂停评论
|
|
dialogs.input("输入新的评论内容").then(input => {
|
|
input = String(input).trim(); // 强制转换为字符串并去除空格
|
|
if (input) {
|
|
lastAddedComment = input; // 将新添加的评论保存
|
|
comments.push(lastAddedComment); // 添加到评论数组中
|
|
updateDisplay(window);
|
|
console.log("添加的评论内容:" + input);
|
|
} else {
|
|
console.log("未输入任何内容");
|
|
}
|
|
paused = false; // 重启评论
|
|
}).catch(error => {
|
|
console.error("对话框输入出错:" + error);
|
|
paused = false; // 解除暂停状态
|
|
});
|
|
});
|
|
|
|
// 停止评论按钮事件
|
|
window.stop.click(() => {
|
|
running = false;
|
|
console.log("评论已停止");
|
|
window.close(); // 关闭悬浮窗
|
|
});
|
|
|
|
window.setPosition(100, 200); // 设置悬浮窗位置
|
|
});
|
|
}
|
|
|
|
// 启动悬浮窗口和自动评论功能
|
|
createControlWindow();
|
|
autoComment();
|
|
console.log("自动评论功能启动");
|