Skip to content

Instantly share code, notes, and snippets.

@LukeNewNew
Created February 9, 2025 18:13
Show Gist options
  • Save LukeNewNew/b9fe2ab788964d165a9872c2d2ebf6cb to your computer and use it in GitHub Desktop.
Save LukeNewNew/b9fe2ab788964d165a9872c2d2ebf6cb to your computer and use it in GitHub Desktop.
YouTube shorts redirect
// ==UserScript==
// @name YouTube shorts redirect
// @namespace http://tampermonkey.net/
// @version 0.3
// @author Fuim
// @match *://*.youtube.com/*
// @icon https://www.google.com/s2/favicons?domain=youtube.com
// @grant none
// @run-at document-start
// @license GNU GPLv2
// ==/UserScript==
(function () {
'use strict';
function redirect() {
if (location.pathname.startsWith("/shorts")) {
// 0 1 2
// /shorts/abcde123456
const videoId = location.pathname.split("/")[2];
const newUrl = "https://www.youtube.com/watch?v=" + videoId;
window.location.replace(newUrl);
}
}
// Run it normally once in case a youtube shorts url was opened directly
redirect();
// Use this event so it'll work when navigating inside of youtube.
// Otherwise, people have to refresh the page for it to work.
// Some other events that might work? yt-page-data-updated, yt-page-type-changed, yt-navigate-finish
document.addEventListener("yt-navigate-start", redirect);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment