Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Redirigir YouTube Shorts a Watch (con soporte SPA)
- // @namespace https://www.youtube.com/
- // @version 1.1
- // @description Redirige automáticamente Shorts a formato Watch, incluso sin recarga (SPA)
- // @match https://www.youtube.com/*
- // @run-at document-start
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- function redirectIfShorts(url) {
- const match = url.match(/^https:\/\/www\.youtube\.com\/shorts\/([^/?#]+)/);
- if (match) {
- const videoId = match[1];
- const newUrl = `https://www.youtube.com/watch?v=${videoId}`;
- if (location.href !== newUrl) {
- window.location.replace(newUrl);
- }
- }
- }
- // Detecta carga inicial
- redirectIfShorts(window.location.href);
- // Observa cambios en la URL sin recarga (SPA)
- let lastUrl = location.href;
- new MutationObserver(() => {
- const currentUrl = location.href;
- if (currentUrl !== lastUrl) {
- lastUrl = currentUrl;
- redirectIfShorts(currentUrl);
- }
- }).observe(document, {subtree: true, childList: true});
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement