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.

Fra 20.11.2021. Se den seneste versjonen.

// ==UserScript==
// @name         Redirect YT video to embedded video
// @namespace    YTRedir
// @version      0.3
// @description  Redirects any opened YT video to the YT embedded video to make the video take the whole screen.
// @author       hacker09
// @match        https://www.youtube.com/watch?v=*
// @match        https://m.youtube.com/watch?v=*
// @match        https://www.youtube.com/embed/*
// @icon         https://www.youtube.com/s/desktop/03f86491/img/favicon.ico
// @run-at       document-start
// @grant        none
// ==/UserScript==

(function() {
  'use strict';

  function Run() { //Creates a new function
    if (location.href.match(/&list=|&t=1s|embed/) === null) //As long as it's not a playlist/embedded video and doesn't have '&t=1s' in the end of the URL
    { //Starts the if condition
      const NoFeature = location.href.replace('&feature=emb_title', ''); //Remove the feature URL parameters
      const YTID = 'https://www.youtube.com/embed/' + location.search.replace('?v=', '') + '?autoplay=1'; //Store embedded URL
      location = NoFeature.replace(location.href, YTID); //Redirect the YT Link
    } //Finishes the if condition
  } //Finishes the Run function

  Run(); //Calls the Run function

  window.ontransitionrun = function() { //When the video is changed
    if (location.href.match('/watch') !== null) //As long as the URL is a video
    { //Starts the if condition
      Run(); //Calls the Run function
    } //Finishes the if condition
  }; //Finishes the transitionend event listener

  if (location.href.match('embed') !== null) //As long as the URL is a embedded video
  { //Starts the if condition
    window.onload = function() { //When the page loads
      document.querySelector(".ytp-title-text > a").outerHTML = document.querySelector(".ytp-title-text > a").outerHTML; //Remove the event listeners of the element
      document.querySelector(".ytp-title-text > a").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-title-text > a").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
    }; //Finishes the onload event listener
  } //Finishes the if condition
})();