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

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

  1. // ==UserScript==
  2. // @name Reddit Stream Button
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.2
  5. // @description Agrega un botón en Reddit para abrir Reddit-stream en el credit-bar del post con la URL correcta de Reddit Stream
  6. // @author Daniel
  7. // @match *://www.reddit.com/r/*/comments/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. function addStreamButton() {
  16. // Evita agregar múltiples botones
  17. if (document.querySelector("#reddit-stream-button")) return;
  18.  
  19. // Crea el botón y lo personaliza
  20. const button = document.createElement("button");
  21. button.id = "reddit-stream-button";
  22. button.textContent = "Ver en Reddit Stream";
  23. button.style.marginLeft = "10px";
  24. button.style.padding = "4px 8px";
  25. button.style.backgroundColor = "#FF5700";
  26. button.style.color = "white";
  27. button.style.border = "none";
  28. button.style.borderRadius = "4px";
  29. button.style.cursor = "pointer";
  30. button.style.fontSize = "12px";
  31.  
  32. // Extrae los elementos 'comments' y el ID del post de la URL
  33. const pathMatch = window.location.pathname.match(/\/comments\/([a-z0-9]+)/);
  34. if (pathMatch) {
  35. const postId = pathMatch[1];
  36. button.onclick = () => {
  37. window.open(`https://reddit-stream.com/comments/${postId}/`, "_blank");
  38. };
  39.  
  40. // Encuentra el contenedor de credit-bar para insertar el botón
  41. const creditBar = document.querySelector('div[slot="credit-bar"]');
  42. if (creditBar) {
  43. creditBar.appendChild(button);
  44. }
  45. }
  46. }
  47.  
  48. // Observa cambios en la página para agregar el botón si se carga dinámicamente
  49. const observer = new MutationObserver(addStreamButton);
  50. observer.observe(document.body, { childList: true, subtree: true });
  51.  
  52. // Llama a la función para intentar agregar el botón en la carga inicial
  53. addStreamButton();
  54. })();