Better Short Player

Replaces shorts player with the "normal" youtube player

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Better Short Player
// @version      0.7
// @description  Replaces shorts player with the "normal" youtube player
// @author       Phorz
// @match        https://www.youtube.com/*
// @license      MIT
// @grant        GM_addStyle
// @namespace http://tampermonkey.net/
// ==/UserScript==

(function() {
  'use strict';

  // Regex to match video URLs with "shorts" in them
  const playerUrlRegex = /\/shorts\/(.+)/;

  // Flag to keep track if it's the first time starting the script
  let firstStart = true;

  /**
   * Replaces the shorts player with the normal YouTube player
   */
  function replacePlayer() {
    const match = window.location.href.match(playerUrlRegex);
    if (match) {
      const videoId = match[1];
      const player = document.querySelector(".video-stream.html5-main-video");
      if (player) {
        GM_addStyle(`
          ytd-reel-player-overlay-renderer #overlay.ytd-reel-player-overlay-renderer {
            visibility: hidden;
          }
          .player-controls.ytd-reel-video-renderer {
            display: none;
          }`);
        const oldPlayer = document.getElementById("embed-player");
        if (oldPlayer) {
          oldPlayer.remove();
        }
        const newPlayer = document.createElement("iframe");
        newPlayer.width = player.clientWidth;
        newPlayer.height = player.clientWidth * 1.776;
        newPlayer.src = `https://www.youtube.com/embed/${videoId}?autoplay=1`;
        newPlayer.frameBorder = "0";
        newPlayer.allow = "fullscreen";
        newPlayer.id = "embed-player";
        player.parentNode.replaceChild(newPlayer, player);
        firstStart = false;
      }
    }
  }

  /**
   * Called when a navigation event has finished
   */
  function onNavigationFinish() {
      setTimeout(replacePlayer, 500);
  }

  /**
   * Starts the script
   */
  function start() {
    // Listen for navigation events
    window.addEventListener('yt-navigate-finish', onNavigationFinish);
  }

  /**
   * Stops the script
   */
  function stop() {
    window.removeEventListener('yt-navigate-finish', onNavigationFinish);
  }

  // Start the script when the page is loaded
  if (document.readyState === "complete") {
    start();
  } else {
    window.addEventListener("load", start);
  }

  // Stop the script when the page is unloaded
  window.addEventListener("unload", stop);
})();