Reddit Stream Button

Agrega un botón en Reddit para abrir Reddit-stream en la barra superior del subreddit

当前为 2024-11-11 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Reddit Stream Button
// @namespace    http://tampermonkey.net/
// @version      1.0.1
// @description  Agrega un botón en Reddit para abrir Reddit-stream en la barra superior del subreddit
// @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.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 = "14px";

        // 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 barra superior del subreddit
            const header = document.querySelector("header");
            if (header) {
                // Encuentra el contenedor donde insertar el botón
                const subredditBar = header.querySelector('div[data-testid="subreddit-nav-bar"]') || header;
                subredditBar.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();
})();