Reddit Stream Button

Agrega un botón en Reddit para abrir Reddit-stream en el credit-bar del post con la URL correcta de Reddit Stream y texto centrado en el botón

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Reddit Stream Button
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  Agrega un botón en Reddit para abrir Reddit-stream en el credit-bar del post con la URL correcta de Reddit Stream y texto centrado en el botón
// @author       Daniel
// @match        *://www.reddit.com/r/*/comments/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    function addStreamButton() {
        // Evita agregar múltiples botones
        if (document.querySelector("#reddit-stream-button")) return;

        // Crea el botón y lo personaliza
        const button = document.createElement("button");
        button.id = "reddit-stream-button";
        button.textContent = "Reddit-Stream";
        button.style.marginLeft = "10px";
        button.style.padding = "4px 8px";
        button.style.backgroundColor = "#FF5700";
        button.style.color = "white";
        button.style.border = "none";
        button.style.borderRadius = "4px";
        button.style.cursor = "pointer";
        button.style.fontSize = "12px";

        // Estilos para centrar el texto
        button.style.display = "flex";
        button.style.justifyContent = "center";
        button.style.alignItems = "center";
        button.style.textAlign = "center";

        // Extrae los elementos 'comments' y el ID del post de la URL
        const pathMatch = window.location.pathname.match(/\/comments\/([a-z0-9]+)/);
        if (pathMatch) {
            const postId = pathMatch[1];
            button.onclick = () => {
                window.open(`https://reddit-stream.com/comments/${postId}/`, "_blank");
            };

            // Encuentra el contenedor de credit-bar para insertar el botón
            const creditBar = document.querySelector('div[slot="credit-bar"]');
            if (creditBar) {
                creditBar.appendChild(button);
            }
        }
    }

    // Observa cambios en la página para agregar el botón si se carga dinámicamente
    const observer = new MutationObserver(addStreamButton);
    observer.observe(document.body, { childList: true, subtree: true });

    // Llama a la función para intentar agregar el botón en la carga inicial
    addStreamButton();
})();