Redirect YT video to embedded video

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

安装此脚本?
作者推荐脚本

您可能也喜欢Auto Set Youtube Volume

安装此脚本
  1. // ==UserScript==
  2. // @name Redirect YT video to embedded video
  3. // @namespace YTRedir
  4. // @version 19
  5. // @description Redirects any opened YT video to the YT embedded video to make the video take the whole screen.
  6. // @author hacker09
  7. // @include https://m.youtube.com/*
  8. // @include https://www.youtube.com/*
  9. // @icon https://www.youtube.com/s/desktop/03f86491/img/favicon.ico
  10. // @run-at document-start
  11. // @grant none
  12. // @noframes
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17. const BypassTT = window.trustedTypes?.createPolicy('BypassTT', { createHTML: HTML => HTML }); //Bypass trustedTypes
  18.  
  19. function Run() { //Creates a new function
  20. 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
  21. { //Starts the if condition
  22. 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
  23. location = 'https://www.youtube.com/embed/' + YTID + '?autoplay=1&mute=1'; //Redirect to the embedded YT URL
  24. } //Finishes the if condition
  25. } //Finishes the Run function
  26.  
  27. Run(); //Calls the Run function
  28.  
  29. window.ontransitionrun = function() { //When the video is changed
  30. Run(); //Calls the Run function
  31. }; //Finishes the transition run event listener
  32.  
  33. window.onload = function() { //When the page loads
  34. if (location.href.match('embed') !== null) //As long as the URL is an embedded video
  35. { //Starts the if condition
  36. document.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 it
  37. document.querySelector("a.ytp-title-link").outerHTML = (html => BypassTT?.createHTML(html) || html)(document.querySelector("a.ytp-title-link").outerHTML); //Remove the event listeners of the element
  38. 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
  39. document.querySelector("a.ytp-title-link").target = '_self'; //Open the video in the same tab
  40. document.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 element
  41. 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
  42. document.querySelector(".ytp-button.yt-uix-sessionlink").target = '_self'; //Open the video in the same tab
  43. setTimeout(function() { //Starts the setimeout function
  44. document.querySelector('#movie_player').playVideo(); //Play the video
  45. document.querySelector(".ytp-mute-button.ytp-button").title.match('Unmute') !== null ? document.querySelector(".ytp-mute-button.ytp-button").click() : ''; //Unmute the video
  46. }, 500); //Finishes the setimeout function
  47. } //Finishes the if condition
  48. }; //Finishes the onload event listener
  49. })();