YouTube Fullscreen Enhancer

This userscript improves YouTube's fullscreen mode by enabling the customization of the viewing experience. Users can hide the video title, player controls, and annotations, as well as stabilize captions when pausing or resuming playback. All these features can be easily toggled.

当前为 2023-03-15 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube Fullscreen Enhancer
  3. // @description This userscript improves YouTube's fullscreen mode by enabling the customization of the viewing experience. Users can hide the video title, player controls, and annotations, as well as stabilize captions when pausing or resuming playback. All these features can be easily toggled.
  4. // @author Wanten
  5. // @copyright 2023 Wanten
  6. // @license MIT
  7. // @supportURL https://github.com/WantenMN/userscript-youtube/issues
  8. // @icon https://youtube.com/favicon.ico
  9. // @homepageURL https://github.com/WantenMN/userscript-youtube
  10. // @namespace https://greasyfork.org/en/scripts/460569
  11. // @version 0.1.1
  12. // @match http*://*.youtube.com/*
  13. // @match http*://youtube.com/*
  14. // @match http*://*.youtu.be/*
  15. // @match http*://youtu.be/*
  16. // @run-at document-end
  17. // @grant GM_addStyle
  18. // ==/UserScript==
  19.  
  20. (function () {
  21. 'use strict';
  22.  
  23. // Keyboard shortcut to toggle the script on and off
  24. const toggleKey = 'e';
  25. // Whether to hide or show the player progress bar when the video is paused
  26. // true: hide
  27. // false: show
  28. const hideProgressBar = true;
  29. // Whether to show or hide the video title and player control bar on mousemove
  30. // true: show
  31. // false: hide
  32. const isMouseMoveToggle = true;
  33.  
  34. const enableStyle = `
  35. .ytp-chrome-top {
  36. display: none !important;
  37. }
  38. .ytp-gradient-top {
  39. display: none !important;
  40. }
  41. .ytp-chrome-controls {
  42. display: none !important;
  43. }
  44. .ytp-gradient-bottom {
  45. display: none !important;
  46. }
  47. .ytp-progress-bar-container {
  48. bottom: 10px !important;
  49. ${hideProgressBar ? 'display: none !important;' : ''}
  50. }
  51. .caption-window, .caption-window.ytp-caption-window-bottom, .caption-window ytp-caption-window-top {
  52. margin-bottom: 0px !important;
  53. margin-top: 0px !important;
  54. }
  55. .annotation {
  56. display: none !important;
  57. }
  58. `;
  59.  
  60. let isEnabled = false;
  61. let styleTag = null;
  62. let mouseMoveTimeout = null;
  63.  
  64. const addStyleTag = () => {
  65. styleTag = GM_addStyle(enableStyle);
  66. };
  67.  
  68. const removeStyleTag = () => {
  69. styleTag?.parentNode?.removeChild(styleTag);
  70. styleTag = null;
  71. };
  72.  
  73. const handleKeyDown = (event) => {
  74. if (event.key !== toggleKey) {
  75. return;
  76. }
  77.  
  78. clearTimeout(mouseMoveTimeout);
  79. isEnabled = !isEnabled;
  80.  
  81. if (styleTag) {
  82. removeStyleTag();
  83. }
  84.  
  85. if (isEnabled) {
  86. addStyleTag();
  87. }
  88. };
  89.  
  90. const handleMouseMove = (event) => {
  91. if (!isMouseMoveToggle || !isEnabled) {
  92. return;
  93. }
  94.  
  95. clearTimeout(mouseMoveTimeout);
  96. if (styleTag) {
  97. removeStyleTag();
  98. }
  99.  
  100. mouseMoveTimeout = setTimeout(() => {
  101. if (isEnabled) {
  102. addStyleTag();
  103. }
  104. }, 3500);
  105. };
  106.  
  107. window.onload = () => {
  108. isEnabled = true;
  109. addStyleTag();
  110. };
  111. window.addEventListener('keydown', handleKeyDown);
  112. window.addEventListener('mousemove', handleMouseMove);
  113. })();