Steam Community - Group Members Blocker

Adds an option to block all members of a steam community group.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Steam Community - Group Members Blocker
// @namespace    Royalgamer06
// @version      1.0
// @description  Adds an option to block all members of a steam community group.
// @author       Royalgamer06
// @include      /^http(s)*\:\/\/steamcommunity\.com\/groups\/(?!.+(\#|\/)).*$/
// @grant        unsafeWindow
// @run-at       document-idle
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js
// ==/UserScript==

var members = [],
    total = 0,
    modal = null;

unsafeWindow.initBlocking = function() {
    if (confirm("Are you sure you want to block all members of this group?")) {
        total = parseInt($(".members .count").first().text().match(/[0-9]+/g).join(""));
        modal = ShowBlockingWaitDialog("Executing...", "Gathered " + members.length + "/" + total + " steamID's of " + g_strGroupName + " members.");
        getMembers(1);
    }
};

function getMembers(p) {
    $.get(g_strGroupURL + "/memberslistxml/?xml=1&p=" + p, function(xml) {
        var xmlmembers = Array.from($("steamID64", xml));
        xmlmembers.forEach(function(member) {
            members.push(member.innerHTML);
        });
        modal.Dismiss();
        modal = ShowBlockingWaitDialog("Executing...", "Gathered " + members.length + "/" + total + " steamID's of " + g_strGroupName + " members.");
        if (xmlmembers.length == 1000) {
            getMembers(p+1);
        } else {
            blockMembers();
        }
    });
}

function blockMembers() {
    var blocked = 0;
    var n = 0;
    members.forEach(function(member) {
        $.post("//steamcommunity.com/actions/BlockUserAjax", { sessionID: g_sessionID, steamid: member, block: 1 }, function() {
            blocked++;
            modal.Dismiss();
            modal = ShowBlockingWaitDialog("Executing...", "Blocked " + blocked + "/" + members.length + " members of " + g_strGroupName + ".");
        }).always(function() {
            n++;
            if (n == members.length) {
                modal.Dismiss();
                ShowAlertDialog("All done!", "Blocked " + blocked + " members of " + g_strGroupName + ".<br>" + (n-blocked) + " Members failed to block.<br><br>I hope you found this userscript useful.<br>Please rate this userscript.<br>Feedback is also appreciated.<br>Thank you");
            }
        });
    });
}

jQuery(document).ready(function() {
    if (location.href.match(/^http(s)*\:\/\/steamcommunity\.com\/groups\/(?!.+(\#|\/)).*$/)) $(".responsive_hidden~ .rightbox .weblink").last().after('<div class="weblink"><a href="javascript:initBlocking();">Block All Members</a></div>');
});