Steam好友管理

自动点击Steam好友申请页面的所有“接受”按钮,并定时刷新页面。

当前为 2024-09-09 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Steam好友管理
// @version     2024.9.9.1
// @description 自动点击Steam好友申请页面的所有“接受”按钮,并定时刷新页面。
// @include     https://steamcommunity.com/profiles/*
// @grant       none
// @note        更新于 2024年9月09日
// @author      怀沙2049
// @license     GNU GPLv3
// @run-at      document-end
// @grant       GM_registerMenuCommand
// @grant       GM_addStyle
// @grant       GM_openInTab
// @grant       GM_setValue
// @grant       GM_getValue
// @grant       GM_xmlhttpRequest
// @namespace   https://greasyfork.org/zh-CN/users/1192640
// ==/UserScript==

(function() {
    'use strict';

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

    // 设置刷新间隔
    var refreshInterval = 5000; // 5秒
    var delayBeforeRefresh = 120000; // 增加120秒的延迟

    // 定义一个函数来执行点击按钮和刷新页面的操作
    function checkAndClickButtons() {
        // 获取页面上的所有“接受”按钮
        var acceptButtons = document.querySelectorAll('.invite_action_txt');

        // 确保有按钮被找到
        if (acceptButtons.length > 0) {
            // console.log("找到了 " + acceptButtons.length + " 个按钮。");

            // 遍历并点击所有找到的“接受”按钮
            for (var i = 0; i < acceptButtons.length; i++) {
                if (acceptButtons[i].textContent === '接受') {
                    // console.log("点击按钮:" + acceptButtons[i].textContent);
                    acceptButtons[i].click();
                }
            }
        } else {
            // console.log("没有找到任何按钮。");
        }

        // 在延迟后刷新页面
        setTimeout(function() {
            // console.log("即将刷新页面...");
            window.location.replace(location.href); // 使用 replace 方法刷新页面
        }, delayBeforeRefresh);
    }

    // 定义一个函数来递归调用 checkAndClickButtons
    function scheduleNextCycle() {
        // 在刷新间隔后执行 checkAndClickButtons
        setTimeout(checkAndClickButtons, refreshInterval);
    }

    // 当DOM加载完成后,调用初始化函数
    if (document.readyState === 'complete' || document.readyState === 'interactive') {
        // 如果DOM已经加载完成,则立即执行一次
        checkAndClickButtons();
    } else {
        // 否则,等待DOM加载完成
        document.addEventListener('DOMContentLoaded', function() {
            checkAndClickButtons();
        });
    }

    // 设置首次刷新的定时器
    scheduleNextCycle();
})();