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.

当前为 2021-11-21 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Redirect YT video to embedded video
// @namespace    YTRedir
// @version      0.8
// @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
// ==/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 NoFeatureTitle = location.href.replace('&feature=emb_title', ''); //Remove the feature title URL parameters
      const NoFeatureLogo = NoFeatureTitle.replace('&feature=emb_logo', ''); //Remove the feature logo URL parameters
      const YTID = 'https://www.youtube.com/embed/' + location.search.replace('?v=', '') + '?autoplay=1'; //Store embedded URL
      location = NoFeatureLogo.replace(location.href, YTID); //Redirect the YT Link
    } //Finishes the if condition
  } //Finishes the Run 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
    Run(); //Calls the Run function
  } //Finishes the if condition

  window.ontransitionrun = function() { //When the video is changed
    Run(); //Calls the Run function
  }; //Finishes the transitionend 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
    } //Finishes the if condition
  }; //Finishes the onload event listener
})();