Last active
May 17, 2023 08:38
-
-
Save lassekongo83/8c025d93da1061c69c13c2040b8ee9da to your computer and use it in GitHub Desktop.
Redirects YouTube shorts videos to the "watch" player.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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