Skip to content

Instantly share code, notes, and snippets.

@lbmaian
Last active January 2, 2026 21:12
Show Gist options
  • Select an option

  • Save lbmaian/c53f48e04a3303d059c042f779a82604 to your computer and use it in GitHub Desktop.

Select an option

Save lbmaian/c53f48e04a3303d059c042f779a82604 to your computer and use it in GitHub Desktop.
YouTube - Redirect /shorts/ and /live/
// ==UserScript==
// @name YouTube - Redirect /shorts/ and /live/
// @namespace https://gist.github.com/lbmaian/c53f48e04a3303d059c042f779a82604
// @downloadURL https://gist.github.com/lbmaian/c53f48e04a3303d059c042f779a82604/raw/youtube-redirect-shorts.user.js
// @updateURL https://gist.github.com/lbmaian/c53f48e04a3303d059c042f779a82604/raw/youtube-redirect-shorts.user.js
// @version 0.4
// @description Redirects YouTube "/shorts/" and "/live/" URLs to "/watch?v=" URLs
// @author lbmaian
// @match https://*.youtube.com/*
// @grant window.onurlchange
// @icon https://www.youtube.com/favicon.ico
// ==/UserScript==
(function() {
'use strict';
function onurlchange() {
let pathSegments = location.pathname.split('/', 3);
if (pathSegments[1] === 'shorts' || pathSegments[1] === 'live') {
let newSearch = location.search;
if (newSearch[0] === '?') {
newSearch = '&' + newSearch.substring(1);
}
let newHref = location.origin + '/watch?v=' + pathSegments[2] + newSearch + location.hash;
console.log("Redirecting %s to %s", location.href, newHref);
location.replace(newHref);
}
}
if (window.onurlchange === null) { // if onurlchange supported
window.addEventListener('urlchange', onurlchange);
} else {
window.setInterval(onurlchange, 500);
}
onurlchange();
})();
@lbmaian

lbmaian commented Oct 19, 2022

Copy link
Copy Markdown
Author

If using the Enhancer for YouTube extension, this is userscript is no longer useful with that extension's new "Convert Shorts" option

@lbmaian

lbmaian commented Mar 13, 2024

Copy link
Copy Markdown
Author

0.2: Updated to work on m.youtube.com as well
0.2.2: Add update URL and rename to "Redirect shorts" - this may require a uninstall+reinstall

@lbmaian

lbmaian commented Oct 19, 2024

Copy link
Copy Markdown
Author

0.3: Also redirect /live/ in addition to /shorts/ (and rename script accordingly)
edit: but keep update url the same: https://gist.github.com/lbmaian/c53f48e04a3303d059c042f779a82604/raw/youtube-redirect-shorts.user.js

@lbmaian

lbmaian commented Oct 26, 2024

Copy link
Copy Markdown
Author

0.4: fix bug where query params in the original URL (like ?t=123) were effectively clobbered

@yekjk26-beep

Copy link
Copy Markdown

Perfect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment