Reddit Stream Button

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

目前為 2024-11-11 提交的版本,檢視 最新版本

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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