Advertisement
freddyncalm

Youtube Shorts to Watch?v= for TamperMonkey

Jun 19th, 2025 (edited)
535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.20 KB | Source Code | 0 0
  1. // ==UserScript==
  2. // @name         Redirigir YouTube Shorts a Watch (con soporte SPA)
  3. // @namespace    https://www.youtube.com/
  4. // @version      1.1
  5. // @description  Redirige automáticamente Shorts a formato Watch, incluso sin recarga (SPA)
  6. // @match        https://www.youtube.com/*
  7. // @run-at       document-start
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12.     'use strict';
  13.  
  14.     function redirectIfShorts(url) {
  15.         const match = url.match(/^https:\/\/www\.youtube\.com\/shorts\/([^/?#]+)/);
  16.         if (match) {
  17.             const videoId = match[1];
  18.             const newUrl = `https://www.youtube.com/watch?v=${videoId}`;
  19.             if (location.href !== newUrl) {
  20.                 window.location.replace(newUrl);
  21.             }
  22.         }
  23.     }
  24.  
  25.     // Detecta carga inicial
  26.     redirectIfShorts(window.location.href);
  27.  
  28.     // Observa cambios en la URL sin recarga (SPA)
  29.     let lastUrl = location.href;
  30.     new MutationObserver(() => {
  31.         const currentUrl = location.href;
  32.         if (currentUrl !== lastUrl) {
  33.             lastUrl = currentUrl;
  34.             redirectIfShorts(currentUrl);
  35.         }
  36.     }).observe(document, {subtree: true, childList: true});
  37. })();
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement