Reddit Stream Button

Agrega un botón en Reddit para abrir Reddit-stream

Stan na 11-11-2024. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Reddit Stream Button
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Agrega un botón en Reddit para abrir Reddit-stream
// @author       Daniel
// @match        *://www.reddit.com/r/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Función para agregar el botón
    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 = "Ver en Reddit Stream";
        button.style.margin = "10px";
        button.style.padding = "8px 12px";
        button.style.backgroundColor = "#FF5700";
        button.style.color = "white";
        button.style.border = "none";
        button.style.borderRadius = "4px";
        button.style.cursor = "pointer";

        // Obtén el nombre del subreddit desde la URL
        const subredditMatch = window.location.pathname.match(/\/r\/([^/]+)/);
        if (subredditMatch) {
            const subreddit = subredditMatch[1];
            button.onclick = () => {
                window.open(`https://reddit-stream.com/r/${subreddit}`, "_blank");
            };

            // Inserta el botón en la cabecera del subreddit
            const header = document.querySelector("header");
            if (header) {
                header.appendChild(button);
            }
        }
    }

    // Espera a que el DOM se cargue completamente
    window.addEventListener("load", addStreamButton);

    // 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 });
})();