【油猴脚本】自动回复

脚本

可以自动回复消息,想接bot的或者什么的自己接入,可以自己写一点东西调用接口。


// ==UserScript==
// @name         linux.do自动回复帖子
// @namespace    http://tampermonkey.net/
// @version      0.0.1
// @description  自动回复linux.do帖子
// @author       zhc
// @match        https://linux.do/*
// @icon         https://www.google.com/s2/favicons?domain=linux.do
// @grant        none
// ==/UserScript==

(function() {
    'use strict';


    let autoReplyEnabled = false; // 控制自动回复是否启用的变量

    // 在页面上添加一个控制按钮
    const controlButton = document.createElement('button');
    controlButton.textContent = '启动自动回复';
    controlButton.style.position = 'fixed';
    controlButton.style.bottom = '20px';
    controlButton.style.right = '20px';
    controlButton.style.zIndex = '9999';
    document.body.appendChild(controlButton);

    // 给控制按钮添加点击事件
    controlButton.addEventListener('click', () => {
        autoReplyEnabled = !autoReplyEnabled;
        controlButton.textContent = autoReplyEnabled ? '停止自动回复' : '启动自动回复';
        console.log(`自动回复已${autoReplyEnabled ? '启动' : '停止'}`);
    });

    // 函数:模拟点击用户元素
    function clickUserElement() {
        const userElement = document.getElementById('current-user');
        if (userElement) {
            userElement.click();
            console.log('模拟点击用户元素');
            // 延时以等待用户菜单加载
            setTimeout(clickRepliesButton, 1000);
        } else {
            console.log('用户元素未找到');
        }
    }

    // 函数:模拟点击“回复”按钮
    function clickRepliesButton() {
        const repliesButton = document.querySelector('#user-menu-button-replies');
        if (repliesButton) {
            repliesButton.click();
            console.log('模拟点击回复按钮');
            // 延时以等待回复内容加载
            setTimeout(clickFirstUnreadReply, 2000);
        } else {
            console.log('回复按钮未找到');
        }
    }

    // 函数:点击第一个未读回复并显示内容
    function clickFirstUnreadReply() {
        const firstUnreadReply = document.querySelector('ul[aria-labelledby="user-menu-button-replies"] > li.notification.unread.replied');
        if (firstUnreadReply) {
            const aTag = firstUnreadReply.querySelector('a[href]');
            if (aTag) {
                aTag.click(); // 模拟点击第一个未读回复
                const postId = aTag.getAttribute('href').split('/').pop();
                console.log(`aTag href: ${aTag.getAttribute('href')}, postId: ${postId}`);
                // 延时以确保文章内容加载
                setTimeout(() => showArticleContent(postId), 1000);
            } else {
                console.log('未找到 <a> 标签');
            }
        } else {
            console.log('未找到未读回复');
        }
    }

    // 函数:显示文章内容
    function showArticleContent(postId) {
        const postContent = document.querySelector(`article#post_${postId} .cooked`);
        if (postContent) {
            console.log(postContent.innerText);
            // 尝试找到并点击“回复”按钮
            const replyButton = document.querySelector(`article#post_${postId} .reply.create`);
            if (replyButton) {
                replyButton.classList.add('d-hover');
                replyButton.click();
                console.log('点击了回复按钮');
                replyButton.classList.remove('d-hover');
                setTimeout(() => reply(postContent.innerText), 3000);
            } else {
                console.log('未找到回复按钮。');
            }
        } else {
            console.log(`未找到ID为${postId}的文章内容。`);
        }
    }

    function reply(text){
        // 假设已经执行了点击回复按钮的操作
        // 现在等待3秒后进行下一步操作
        // 找到输入框
        const textarea = document.querySelector('textarea.d-editor-input');

        if (textarea) {
            // 输入"666"
            textarea.value = '俺也不清楚。!俺也不知道。!俺也不懂。!自动回复-> 此条为bot回复(请举报)';

            // 创建并触发一个'input'事件,这对于许多由输入驱动的UI来说是必要的
            const event = new Event('input', {
                bubbles: true,
                cancelable: true,
            });

            // 触发事件以确保任何绑定到文本框输入的逻辑都能响应这次改变
            textarea.dispatchEvent(event);

            // 创建⌘Enter (Command + Enter) 模拟事件
            // 对于Mac使用metaKey,Windows/Linux使用ctrlKey
            const cmdEnterEvent = new KeyboardEvent('keydown', {
                key: 'Enter',
                code: 'Enter',
                keyCode: 13,
                charCode: 13,
                metaKey: true, // Mac用户
                // ctrlKey: true, // Windows/Linux用户
                bubbles: true
            });

            // 触发⌘Enter事件
            setTimeout(textarea.dispatchEvent(cmdEnterEvent), 1000);

            console.log('已输入"666"并模拟按键⌘Enter。');

        } else {
            console.log('未找到输入框。');
        }
    }

    console.log('脚本开始运行');

    setInterval(() => {
        if (autoReplyEnabled) {
            clickUserElement();
        }
    }, 30000); // 每30秒检查一次

})();

注意事项

  1. mac 用户
    metaKey: true, // Mac用户
    // ctrlKey: true, // Windows/Linux用户
  2. windows、Linux 用户
    // metaKey: true, // Mac用户
    ctrlKey: true, // Windows/Linux用户
  3. 回复相同内容会提示:
    出错了:正文 与您最近发布的内容过于相似

最后

论坛有机器人检测。不能太嚣张放肆。。。。

12 个赞

刑!!!

3 个赞

刑!!!刑!!!刑!!!

3 个赞

刑!!!刑!!!刑!!!
刑!!!刑!!!刑!!!

3 个赞

行走的徽章

:u7981: 不可以使用AI生成内容发帖。为维护中文互联网环境,这里绝对不允许使用AI生成内容!

4 个赞

兄弟,举办了

3 个赞

点赞看帖什么的就算了,自动回复被抓一律禁言!

45 个赞

所以说,我没有用!:dog:

3 个赞

真~在天子脚下动土 :rofl:

3 个赞

刑!!!

3 个赞

那就写个自动看帖吧 :crazy_face:

2 个赞

越来越刑了

1 个赞

很刑!

1 个赞

ok 有空可以看看,。。

2 个赞

不过应当增加随机事件:自动回复-> 此条为bot回复,请举报我(

声明:本条为人工手打

2 个赞

我们已经有你用了的官方证据了,你主动自首,争取宽大处理。

1 个赞

一个论坛如果帖子都是自动发的,那还有什么价值?
所以这是底线,一定不会睁一只眼闭一只眼。

22 个赞

始皇都炸出来了

1 个赞

突然想到了国外的ai论坛,全是gpt :joy:

1 个赞

想起来之前的狗屁不通生成器

2 个赞