[YouTube] Open Shorts on Default Watch

redirects shorts link to default watch?v=

  1. // ==UserScript==
  2. // @name [YouTube] Open Shorts on Default Watch
  3. // @author pootz10
  4. // @namespace https://www.tampermonkey.net
  5. // @description redirects shorts link to default watch?v=
  6. // @match https://www.youtube.com/shorts/*
  7. // @exclude https://www.youtube.com/watch?v=*
  8. // @exclude https://youtu.be/*
  9. // @version 1.1
  10. // @history 1.1 - added exclude for watch?v= links
  11. // @license GNU
  12. // @grant GM_openInTab
  13. // @grant GM_addStyle
  14. // @run-at document-idle
  15. // ==/UserScript==
  16.  
  17.  
  18. // Função para criar o botão
  19. function addWatchButton() {
  20. const actionsElement = document.querySelector('#actions');
  21. if (!actionsElement) return; // Sai se o elemento não existir
  22.  
  23. // Evita adicionar múltiplos botões
  24. if (document.querySelector('#custom-watch-button')) return;
  25.  
  26. // Cria o botão
  27. const button = document.createElement('button');
  28. button.id = 'custom-watch-button';
  29. button.textContent = 'Watch';
  30.  
  31. // Ação ao clicar no botão
  32. button.addEventListener('click', () => {
  33. const urlParams = new URL(location.href);
  34. const videoId = urlParams.pathname.split('/')[2];
  35. if (videoId) {
  36. const watchUrl = `https://www.youtube.com/watch?v=${videoId}`;
  37. GM_openInTab(watchUrl, { active: true });
  38. }
  39. });
  40.  
  41. // Insere o botão no início das ações
  42. actionsElement.prepend(button);
  43. }
  44.  
  45. // Observa mudanças no DOM para detectar o carregamento do elemento
  46. const observer = new MutationObserver(() => {
  47. addWatchButton();
  48. });
  49.  
  50. observer.observe(document.body, { childList: true, subtree: true });
  51.  
  52. // Adiciona botão imediatamente caso o elemento já esteja carregado
  53. addWatchButton();
  54.  
  55. GM_addStyle(`
  56. #custom-watch-button {
  57. color: #0f0f0f;
  58. background: rgba(0, 0, 0, 0.05);
  59. width: 48px;
  60. height: 48px;
  61. padding: 0;
  62. font-size: 12px;
  63. font-family: "Roboto", "Arial", sans-serif;
  64. font-weight: 500;
  65. line-height: 18px;
  66. border: none;
  67. border-radius: 24px;
  68. cursor: pointer;
  69. display: flex;
  70. align-items: center;
  71. justify-content: center;
  72. position: relative;
  73. margin: 0;
  74. text-transform: none;
  75. }
  76.  
  77. #custom-watch-button:hover {
  78. background: rgba(0, 0, 0, 0.1); /* Ajuste para hover */
  79. }
  80. `);