Steam: Hide Topics & Comments from Blocked Users

Hides topics and comments from blocked users in Steam discussions.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Steam: Hide Topics & Comments from Blocked Users
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Hides topics and comments from blocked users in Steam discussions.
// @match        https://steamcommunity.com/app/*/discussions*
// @author       Spuner
// @icon         https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Steam_icon_logo.svg/768px-Steam_icon_logo.svg.png
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    function hideBlockedTopics() {
        const searchText = 'Тема, созданная заблокированным пользователем';
        const labelSelector = 'span.forum_topic_label';
        const containerSelector = 'div.forum_topic';
        let hiddenCount = 0;

        const labels = document.querySelectorAll(labelSelector);
        labels.forEach(label => {
            if (label.textContent.includes(searchText)) {
                const topicToHide = label.closest(containerSelector);
                if (topicToHide && topicToHide.style.display !== 'none') {
                    topicToHide.style.display = 'none';
                    hiddenCount++;
                }
            }
        });
        if (hiddenCount > 0) {
            console.log(`[Steam Blocker] Скрыто тем: ${hiddenCount}`);
        }
    }

    function hideBlockedComments() {
        const searchText = 'Пользователь заблокирован';
        const labelSelector = 'span.commentthread_deleted_comment_audit';
        const containerSelector = 'div.commentthread_deleted_comment';
        let hiddenCount = 0;

        const labels = document.querySelectorAll(labelSelector);
        labels.forEach(label => {
            if (label.textContent.includes(searchText)) {
                const commentToHide = label.closest(containerSelector);
                if (commentToHide && commentToHide.style.display !== 'none') {
                    commentToHide.style.display = 'none';
                    hiddenCount++;
                }
            }
        });
        if (hiddenCount > 0) {
            console.log(`[Steam Blocker] Скрыто комментариев: ${hiddenCount}`);
        }
    }

    function applyAllRules() {
        hideBlockedTopics();
        hideBlockedComments();
    }

    const observer = new MutationObserver((mutations) => {
        for (const mutation of mutations) {
            if (mutation.addedNodes.length) {
                setTimeout(applyAllRules, 250);
                return;
            }
        }
    });

    const startObserver = () => {
        if (document.body) {
            observer.observe(document.body, { childList: true, subtree: true });
            applyAllRules();
        } else {
            setTimeout(startObserver, 100);
        }
    };

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', startObserver);
    } else {
        startObserver();
    }
})();