Greasy Fork is available in English.

Redirect YT video to embedded video

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

Versão de: 12/11/2023. Veja: a última versão.

Você precisará instalar uma extensão como Tampermonkey, Greasemonkey ou Violentmonkey para instalar este script.

Você precisará instalar uma extensão como Tampermonkey ou Violentmonkey para instalar este script.

Você precisará instalar uma extensão como Tampermonkey ou Violentmonkey para instalar este script.

Você precisará instalar uma extensão como Tampermonkey ou Userscripts para instalar este script.

Você precisará instalar uma extensão como o Tampermonkey para instalar este script.

Você precisará instalar um gerenciador de scripts de usuário para instalar este script.

(Eu já tenho um gerenciador de scripts de usuário, me deixe instalá-lo!)

Você precisará instalar uma extensão como o Stylus para instalar este estilo.

Você precisará instalar uma extensão como o Stylus para instalar este estilo.

Você precisará instalar uma extensão como o Stylus para instalar este estilo.

Você precisará instalar um gerenciador de estilos de usuário para instalar este estilo.

Você precisará instalar um gerenciador de estilos de usuário para instalar este estilo.

Você precisará instalar um gerenciador de estilos de usuário para instalar este estilo.

(Eu já possuo um gerenciador de estilos de usuário, me deixar fazer a instalação!)

// ==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
})();