Ucubesavar

Reddit ucubelerini savmak isteyenlere.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Ucubesavar
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Reddit ucubelerini savmak isteyenlere.
// @match        *://*.reddit.com/*
// @grant        none
// @run-at       document-start
// @license MIT
// ==/UserScript==


(function() {
    'use strict';

    const ENGELLENECEK_KULLANICILAR = [
        "birisi",
        "baskasi",
        "birbaskasi"
    ];


    if (ENGELLENECEK_KULLANICILAR.length === 0) return;


    const globalCssSelectors = ENGELLENECEK_KULLANICILAR.map(user => `
        article:has(shreddit-post[author="${user}"]),
        article:has(shreddit-post[author="${user}"]) + hr,
        shreddit-post[author="${user}"],
        shreddit-comment[author="${user}"],
        [data-author="${user}"],
        [author="${user}"]
    `).join(',\n');

    const globalCSS = `
        ${globalCssSelectors} {
            display: none !important;
            visibility: hidden !important;
            height: 0 !important;
            margin: 0 !important;
            padding: 0 !important;
            opacity: 0 !important;
            border: none !important;
            pointer-events: none !important;
        }
    `;


    const chatCssSelectors = ENGELLENECEK_KULLANICILAR.map(user => `
        div.room-message[aria-label^="${user} "]
    `).join(',\n');

    const chatCSS = `
        ${chatCssSelectors} {
            display: none !important;
            height: 0 !important;
            margin: 0 !important;
            padding: 0 !important;
            border: none !important;
            visibility: hidden !important;
        }
    `;

    const injectGlobalStyles = () => {
        const styleEl = document.createElement('style');
        styleEl.textContent = globalCSS;
        document.head.appendChild(styleEl);
    };


    if (document.head) {
        injectGlobalStyles();
    } else {
        document.addEventListener("DOMContentLoaded", injectGlobalStyles);
    }

    const originalAttachShadow = Element.prototype.attachShadow;

    Element.prototype.attachShadow = function(init) {
        const shadowRoot = originalAttachShadow.call(this, init);

        if (this.tagName === 'RS-TIMELINE-EVENT') {
            const shadowStyle = document.createElement('style');
            shadowStyle.textContent = chatCSS;
            shadowRoot.appendChild(shadowStyle);
        }

        return shadowRoot;
    };

})();