Redirect YT video to embedded video

Redirects any opened YT video to the YT embedded video to make the video take the whole screen.

Versione datata 12/11/2023. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Redirect YT video to embedded video
// @namespace    YTRedir
// @version      15
// @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';

  function Run() { //Creates a new function
    if ((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 condition
      const YTID = location.href.split(/(vi\/|v%3D|v=|\/v\/|youtu\.be\/|\/embed\/)/)[2].split(/[^0-9a-z_\-]/i)[0]; //Store the YT video ID
      location = 'https://www.youtube.com/embed/' + YTID + '?autoplay=1&mute=1'; //Redirect to the embedded YT URL
    } //Finishes the if condition
  } //Finishes the Run function

  Run(); //Calls the Run function

  window.ontransitionrun = function() { //When the video is changed
    Run(); //Calls the Run function
  }; //Finishes the transition run event listener

  window.onload = function() { //When the page loads
    if (location.href.match('embed') !== null) //As long as the URL is an embedded video
    { //Starts the if condition
      document.querySelector("a.ytp-title-link").outerHTML = document.querySelector("a.ytp-title-link").outerHTML; //Remove the event listeners of the element
      document.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 URL
      document.querySelector("a.ytp-title-link").target = '_self'; //Open the video in the same tab
      document.querySelector(".ytp-button.yt-uix-sessionlink").outerHTML = document.querySelector(".ytp-button.yt-uix-sessionlink").outerHTML; //Remove the event listeners of the element
      document.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 URL
      document.querySelector(".ytp-button.yt-uix-sessionlink").target = '_self'; //Open the video in the same tab
      if (navigator.userAgent.match('Mobile') !== null) //If the embedded video is being played on a mobile device
      { //Starts the if condition
        document.querySelector('#movie_player').playVideo(); //Play the video
        document.querySelector(".ytp-volume-panel").ariaValueText.match('muted') !== null ? document.querySelector(".ytp-mute-button.ytp-button").click() : ''; //Unmute the video
      } //Finishes the if condition
    } //Finishes the if condition
  }; //Finishes the onload event listener
})();