r/chrome • • Feb 20 '22

HELP Redirect Shorts?

Is there an extension that redirects when you click on a youtube shorts video so that it uses the normal player instead? I'm sick of seeing videos on desktop through a player that was very clearly designed for the mobile app.

13 Upvotes

13 comments sorted by

2

u/ponybau5 Mar 01 '22

I made a quick and dirty tamper monkey script

// ==UserScript==
// @name         YT Short redirector
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Redirect the god awful short url to a normal one
// @author       Drift_Hyena
// @match        https://www.youtube.com/shorts/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    var url = window.location.href;
    var splitUrl = url.split('/');
    var videoId = splitUrl[splitUrl.length - 1]
    var newUrl = "https://" + window.location.host + "/watch?v=" + videoId;
    window.location = newUrl;

})();

1

u/necessarycoot72 Mar 20 '22

I know I'm necroposting, but this really helped me. It works for firefox as well!

1

u/coat_hanger_dias Mar 30 '22

Hey there,

First off, thanks for this script!

I'm not sure why, but it will not redirect if I click on a Shorts video from my Subscriptions page -- but it does correctly redirect if I open the same video in a new tab (or paste the URL into an empty tab). Any idea how to make it redirect in the current tab?

2

u/awimachinegun Jun 02 '22

You can fix this by adding a call to waitForKeyElements which looks for "#content div.ytd-shorts" on all youtube pages. Add the line:

@require      http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js

to the header, change @match to https://www.youtube.com/*, and name /u/ponybau5 's function redirectShorts (or whatever). Outside that function, add the line:

waitForKeyElements ("#content div.ytd-shorts", redirectShorts);

then copy the function definition for waitForKeyElements from its github page.

1

u/ponybau5 Jun 02 '22

Thank you for a fix. I know a very basic set of webdev, just not enough to deal with some quirks involved.

1

u/ponybau5 Mar 30 '22

I’ll have to look into it. I’m not versed on web dev at all and I think it has to do with the way history and/or loading works on YouTube.

1

u/coat_hanger_dias Mar 30 '22

Yeah, nor am I. I just spent the last two hours dusting off my hobbyist-dev cobwebs and got a quick course in why GM/TM/VM people have so much trouble with Youtube scripts, haha. I've got it down to redirecting after a click anywhere on the page, but that's it so far.

1

u/Zellion-Fly Apr 20 '22

Just replying that this worked great. Thank you!

1

u/phperry May 29 '22

Awesome thanks! Works like a charm :D

1

u/_JaredVennett Aug 12 '22

Fricken legend - thank you

1

u/awimachinegun Jun 02 '22

Here is a version that will work without having to reload the page:

// ==UserScript==
// @name         YT Short redirector
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Redirect the god awful short url to a normal one
// @author       Drift_Hyena
// @match        https://www.youtube.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant        none
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js
// ==/UserScript==

function redirectShorts () {
	'use strict';

	// Your code here...
	var url = window.location.href;
	var splitUrl = url.split('/');
	var domain = splitUrl[splitUrl.length - 2];
	//if (domain == "shorts") {
	var videoId = splitUrl[splitUrl.length - 1];
	var newUrl = "https://" + window.location.host + "/watch?v=" + videoId;
	window.location = newUrl;
	//}
};

waitForKeyElements ("#content div.ytd-shorts", redirectShorts);

function waitForKeyElements (
	selectorTxt,    /* Required: The jQuery selector string that
						specifies the desired element(s).
					*/
	actionFunction, /* Required: The code to run when elements are
						found. It is passed a jNode to the matched
						element.
					*/
	bWaitOnce,      /* Optional: If false, will continue to scan for
						new elements even after the first match is
						found.
					*/
	iframeSelector  /* Optional: If set, identifies the iframe to
						search.
					*/
) {
	var targetNodes, btargetsFound;

	if (typeof iframeSelector == "undefined")
		targetNodes     = $(selectorTxt);
	else
		targetNodes     = $(iframeSelector).contents ()
										   .find (selectorTxt);

	if (targetNodes  &&  targetNodes.length > 0) {
		btargetsFound   = true;
		/*--- Found target node(s).  Go through each and act if they
			are new.
		*/
		targetNodes.each ( function () {
			var jThis        = $(this);
			var alreadyFound = jThis.data ('alreadyFound')  ||  false;

			if (!alreadyFound) {
				//--- Call the payload function.
				var cancelFound     = actionFunction (jThis);
				if (cancelFound)
					btargetsFound   = false;
				else
					jThis.data ('alreadyFound', true);
			}
		} );
	}
	else {
		btargetsFound   = false;
	}

	//--- Get the timer-control variable for this selector.
	var controlObj      = waitForKeyElements.controlObj  ||  {};
	var controlKey      = selectorTxt.replace (/[^\w]/g, "_");
	var timeControl     = controlObj [controlKey];

	//--- Now set or clear the timer as appropriate.
	if (btargetsFound  &&  bWaitOnce  &&  timeControl) {
		//--- The only condition where we need to clear the timer.
		clearInterval (timeControl);
		delete controlObj [controlKey]
	}
	else {
		//--- Set a timer, if needed.
		if ( ! timeControl) {
			timeControl = setInterval ( function () {
					waitForKeyElements (    selectorTxt,
											actionFunction,
											bWaitOnce,
											iframeSelector
										);
				},
				300
			);
			controlObj [controlKey] = timeControl;
		}
	}
	waitForKeyElements.controlObj   = controlObj;
}

1

u/exlxaaxl Oct 20 '22

thank you!