Steam: Hide Topics & Comments from Blocked Users

Hides topics and comments from blocked users in Steam discussions.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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();
    }
})();