Redirects any opened YT video to the YT embedded video to make the video take the whole screen.
// ==UserScript==// @name Redirect YT video to embedded video// @namespace YTRedir// @version 19// @description Redirects any opened YT video to the YT embedded video to make the video take the whole screen.// @author hacker09// @include https://m.youtube.com/*// @include https://www.youtube.com/*// @icon https://www.youtube.com/s/desktop/03f86491/img/favicon.ico// @run-at document-start// @grant none// @noframes// ==/UserScript==(function() {'use strict';const BypassTT = window.trustedTypes?.createPolicy('BypassTT', { createHTML: HTML => HTML }); //Bypass trustedTypesfunction Run() { //Creates a new functionif ((location.pathname !== '/') && (location.href.match('/watch') !== null) && (location.href.match(/&list=|&t=1s|embed/) === null)) //As long as it's not the YT index page, the URL is a video, it's not a playlist/embedded video, and doesn't have '&t=1s' in the end of the URL{ //Starts the if conditionconst YTID = location.href.split(/(vi\/|v%3D|v=|\/v\/|youtu\.be\/|\/embed\/)/)[2].split(/[^0-9a-z_\-]/i)[0]; //Store the YT video IDlocation = 'https://www.youtube.com/embed/' + YTID + '?autoplay=1&mute=1'; //Redirect to the embedded YT URL} //Finishes the if condition} //Finishes the Run functionRun(); //Calls the Run functionwindow.ontransitionrun = function() { //When the video is changedRun(); //Calls the Run function}; //Finishes the transition run event listenerwindow.onload = function() { //When the page loadsif (location.href.match('embed') !== null) //As long as the URL is an embedded video{ //Starts the if conditiondocument.querySelector(".ytp-error-content-wrap-subreason > span > a, .ytp-error-content-wrap-subreason > div > a") !== null ? open(document.querySelector(".ytp-error-content-wrap-subreason > span > a, .ytp-error-content-wrap-subreason > div > a").href += '&t=1s', '_self') : ''; //If the video can only be seen on youtube.com, redirect itdocument.querySelector("a.ytp-title-link").outerHTML = (html => BypassTT?.createHTML(html) || html)(document.querySelector("a.ytp-title-link").outerHTML); //Remove the event listeners of the elementdocument.querySelector("a.ytp-title-link").href += '&t=1s'; //Add URL parameter to start video on the first second of the video, so that the script won't redirect the URLdocument.querySelector("a.ytp-title-link").target = '_self'; //Open the video in the same tabdocument.querySelector(".ytp-button.yt-uix-sessionlink").outerHTML = (html => BypassTT?.createHTML(html) || html)(document.querySelector(".ytp-button.yt-uix-sessionlink").outerHTML); //Remove the event listeners of the elementdocument.querySelector(".ytp-button.yt-uix-sessionlink").href += '&t=1s'; //Add URL parameter to start video on the first second of the video, so that the script won't redirect the URLdocument.querySelector(".ytp-button.yt-uix-sessionlink").target = '_self'; //Open the video in the same tabsetTimeout(function() { //Starts the setimeout functiondocument.querySelector('#movie_player').playVideo(); //Play the videodocument.querySelector(".ytp-mute-button.ytp-button").title.match('Unmute') !== null ? document.querySelector(".ytp-mute-button.ytp-button").click() : ''; //Unmute the video}, 500); //Finishes the setimeout function} //Finishes the if condition}; //Finishes the onload event listener})();