Hide Youtube video title and player control bar

Hide Youtube video title and player control bar when paused.

目前為 2023-02-23 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name            Hide Youtube video title and player control bar
// @description     Hide Youtube video title and player control bar when paused.
// @author          Wanten
// @copyright       2023 Wanten
// @license         MIT
// @supportURL      https://github.com/WantenMN/userscript-youtube/issues
// @icon            https://youtube.com/favicon.ico
// @homepageURL     https://github.com/WantenMN/userscript-youtube
// @namespace       https://greasyfork.org/en/scripts/460569
// @version         0.0.6
// @match           http*://*.youtube.com/watch?*
// @match           http*://youtube.com/watch?*
// @match           http*://*.youtu.be/watch?*
// @match           http*://youtu.be/watch?*
// @run-at          document-end
// @grant           GM_addStyle
// ==/UserScript==


(function () {
  "use strict";

  /**
   * settings-start
   */
  //shortcut key to toggle the script
  const toggleKey = 'e';

  //Hide or show player progress bar, when pause a video by click spacebar or press K 
  //true or false
  const hideProgressBar = true;

  //Whether to hide video title and player control bar when mousemove
  //true: show
  //false:hide
  const isMouseMoveToggle = true;
  /**
   * settings-end
   */

  const enableStyle = `
  .ytp-chrome-top {
    display: none !important;
  }
  .ytp-gradient-top {
    display: none !important;
  }
  .ytp-chrome-controls {
    display: none !important;
  }
  .ytp-gradient-bottom {
    display: none !important;
  }
  .ytp-progress-bar-container {
    bottom: 10px !important;
    ${hideProgressBar ? 'display: none !important;' : ''}
  }
  .caption-window, .caption-window.ytp-caption-window-bottom, .caption-window ytp-caption-window-top {
    margin-bottom: 0px !important;
    margin-top: 0px !important;
  }
  .annotation {
    display: none !important;
  }
  `;

  let enableFlag = false;
  let styleTag = null;
  let mouseMoveSetTimeoutID = null;

  //keydown toggle
  window.addEventListener("keydown", (e) => {
    if (e.key === toggleKey) {
      clearTimeout(mouseMoveSetTimeoutID)
      enableFlag = !enableFlag;
      styleTag && removeStyleTag();
      enableFlag && addStyleTag();
    }
  });

  //mousemove toggle
  window.addEventListener("mousemove", (e) => {
    clearTimeout(mouseMoveSetTimeoutID)
    if (!isMouseMoveToggle || !enableFlag) return;
    styleTag && removeStyleTag();
    mouseMoveSetTimeoutID = setTimeout(() => {
      enableFlag && addStyleTag();
    }, 3500)
  });

  const addStyleTag = () => {
    styleTag = GM_addStyle(enableStyle);
  }

  const removeStyleTag = () => {
    document.head.removeChild(styleTag);
    styleTag = null;
  }
})();