Skip to content

Instantly share code, notes, and snippets.

@lassekongo83
Last active May 17, 2023 08:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lassekongo83/8c025d93da1061c69c13c2040b8ee9da to your computer and use it in GitHub Desktop.
Save lassekongo83/8c025d93da1061c69c13c2040b8ee9da to your computer and use it in GitHub Desktop.
Redirects YouTube shorts videos to the "watch" player.
// ==UserScript==
// @name Youtube shorts redirect
// @namespace ViolentMonkey Scripts
// @version 0.3
// @match *://*.youtube.com/*
// @grant none
// @run-at document-start
// ==/UserScript==
(function() {
'use strict';
const replaceShortsLinks = () => {
[...document.querySelectorAll('a[href*="/shorts/"]')]
.forEach(a => {
a.href = a.href.replace(/\/shorts\/(.*)/, '/watch?v=$1')
});
};
window.addEventListener("yt-navigate-finish", replaceShortsLinks, true);
let oldHref = document.location.href;
if (window.location.href.indexOf('youtube.com/shorts') > -1) {
window.location.replace(window.location.toString().replace('/shorts/', '/watch?v='));
}
function shortsRedirector() {
if (oldHref != document.location.href) {
oldHref = document.location.href;
if (window.location.href.indexOf('youtube.com/shorts') > -1) {
window.location.replace(window.location.toString().replace('/shorts/', '/watch?v='));
}
}
}
window.addEventListener("yt-navigate-finish", shortsRedirector, true);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment