Reddit Stream Button

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

目前为 2024-11-11 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Reddit Stream Button
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Agrega un botón en Reddit para abrir Reddit-stream
  6. // @author Daniel
  7. // @match *://www.reddit.com/r/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Función para agregar el botón
  16. function addStreamButton() {
  17. // Evita agregar múltiples botones
  18. if (document.querySelector("#reddit-stream-button")) return;
  19.  
  20. // Crea el botón y lo personaliza
  21. const button = document.createElement("button");
  22. button.id = "reddit-stream-button";
  23. button.textContent = "Ver en Reddit Stream";
  24. button.style.margin = "10px";
  25. button.style.padding = "8px 12px";
  26. button.style.backgroundColor = "#FF5700";
  27. button.style.color = "white";
  28. button.style.border = "none";
  29. button.style.borderRadius = "4px";
  30. button.style.cursor = "pointer";
  31.  
  32. // Obtén el nombre del subreddit desde la URL
  33. const subredditMatch = window.location.pathname.match(/\/r\/([^/]+)/);
  34. if (subredditMatch) {
  35. const subreddit = subredditMatch[1];
  36. button.onclick = () => {
  37. window.open(`https://reddit-stream.com/r/${subreddit}`, "_blank");
  38. };
  39.  
  40. // Inserta el botón en la cabecera del subreddit
  41. const header = document.querySelector("header");
  42. if (header) {
  43. header.appendChild(button);
  44. }
  45. }
  46. }
  47.  
  48. // Espera a que el DOM se cargue completamente
  49. window.addEventListener("load", addStreamButton);
  50.  
  51. // Observa cambios en la página para agregar el botón si se carga dinámicamente
  52. const observer = new MutationObserver(addStreamButton);
  53. observer.observe(document.body, { childList: true, subtree: true });
  54. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址