70games自动评论

Automatically comments on a specific page on https://70games.net 2023/12/16 14:02:53

目前为 2023-12-16 提交的版本。查看 最新版本

// ==UserScript==
// @name         70games自动评论
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Automatically comments on a specific page on https://70games.net 2023/12/16 14:02:53
// @author       You
// @match        *://*.70games.net/*
// @grant        none
// ==/UserScript==


(function() {
    'use strict';

    // 评论内容
    var commentText = '感谢!'; // 可以将“感谢”替换为任何你想要自动评论的内容~

    // 检查页面是否包含指定的文字
    function hasRequiredText() {
        return document.body.innerText.includes('本内容需要评论后才可以查看,请评论后再查看。');
    }

    // 滚动到页面顶部
    function scrollToTop() {
        console.log('Scrolling to the top...');
        window.scrollTo(0, 0);
    }

    // 发表评论
    function postComment() {
        console.log('Posting comment...');
        // 获取评论框
        var commentBox = document.getElementById('message'); // 评论框ID

        if (commentBox) {
            // 输入评论内容
            commentBox.value = commentText;

            // 提交评论表单
            var submitButton = document.getElementById('submit'); // 提交按钮ID
            if (submitButton) {
                submitButton.click();
            }
        }
    }

    // 页面加载完成时执行
    window.onload = function() {
        console.log('Page loaded.');
        // 如果页面包含指定的文字,则按顺序执行滚动到顶部、发表评论、刷新页面等操作
        if (hasRequiredText()) {
            setTimeout(scrollToTop, 100); // 0.5秒后滚动到顶部。ps:实际上是0.1秒后,如果你的网速太差~电脑太旧~你可以把它调高!
            setTimeout(postComment, 200); // 1秒后发表评论。ps:实际上是0.2秒后,如果你的网速太差~电脑太旧~你可以把它调高!

            // 刷新页面一次
            setTimeout(function() {
                console.log('Reloading the page...');
                window.location.reload();
            }, 300); // 2秒后刷新页面,可以根据需要调整时间。ps:实际上是0.3秒后…………!
        } else {
            console.log('Required text not found. Stopping the script.');
        }
    };
})();