Guest User

Tampermonkey script for fixing the embedded YouTube player (remove play button, hide GUI faster)

a guest
Sep 13th, 2026
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         YouTube Embed Cleaner - Instant Hide + Fullscreen Timeout
  3. // @namespace    custom
  4. // @version      1.5
  5. // @match        https://www.youtube.com/embed/*
  6. // @match        https://www.youtube-nocookie.com/embed/*
  7. // @grant        none
  8. // @run-at       document-idle
  9. // ==/UserScript==
  10.  
  11. (function () {
  12.     'use strict';
  13.  
  14.     const HIDE_AFTER_MS = 1000;
  15.  
  16.     const style = document.createElement('style');
  17.  
  18.     style.textContent = `
  19.         /* Remove dark gradient/background permanently */
  20.         .player-controls-background-container,
  21.         .player-controls-background {
  22.             background: transparent !important;
  23.             background-image: none !important;
  24.             opacity: 0 !important;
  25.             pointer-events: none !important;
  26.         }
  27.  
  28.         /* Hide main UI */
  29.         html.tm-controls-hidden player-top-controls,
  30.         html.tm-controls-hidden player-middle-controls,
  31.         html.tm-controls-hidden player-bottom-controls,
  32.         html.tm-controls-hidden yt-progress-bar,
  33.  
  34.         html.tm-controls-hidden .player-controls-top,
  35.         html.tm-controls-hidden .player-controls-middle,
  36.         html.tm-controls-hidden .player-controls-bottom,
  37.  
  38.         html.tm-controls-hidden .ytmVideoInfoOverlay,
  39.  
  40.         html.tm-controls-hidden .ytwPlayerTopControlsHost,
  41.         html.tm-controls-hidden .ytwPlayerMiddleControlsHost,
  42.         html.tm-controls-hidden .ytwPlayerBottomControlsHost,
  43.  
  44.         /* Share / action menu */
  45.         html.tm-controls-hidden player-fullscreen-action-menu,
  46.         html.tm-controls-hidden .ytwPlayerFullscreenActionMenuHost,
  47.  
  48.         /* More-videos / thumbnail overlays */
  49.         html.tm-controls-hidden .videoThumbnailGroupOverlayBottomLeftRightGroup,
  50.         html.tm-controls-hidden .videoThumbnailGroupOverlayLeftRightGroup,
  51.         html.tm-controls-hidden ytm-thumbnail-overlay-time-status-renderer {
  52.  
  53.             opacity: 0 !important;
  54.             visibility: hidden !important;
  55.             pointer-events: none !important;
  56.             transition: none !important;
  57.             animation: none !important;
  58.         }
  59.  
  60.         /* Remove the large center play/pause control */
  61.         player-middle-controls,
  62.         .ytwPlayerMiddleControlsHost,
  63.         .player-controls-middle {
  64.             display: none !important;
  65.         }
  66.  
  67.         /* Disable YouTube fade delay */
  68.         player-top-controls,
  69.         player-middle-controls,
  70.         player-bottom-controls,
  71.         yt-progress-bar,
  72.         .player-controls-top,
  73.         .player-controls-middle,
  74.         .player-controls-bottom,
  75.         .ytmVideoInfoOverlay,
  76.         player-fullscreen-action-menu {
  77.             transition: none !important;
  78.         }
  79.     `;
  80.  
  81.     document.head.appendChild(style);
  82.  
  83.     let hideTimer = null;
  84.  
  85.     function hideControls() {
  86.         clearTimeout(hideTimer);
  87.         document.documentElement.classList.add('tm-controls-hidden');
  88.     }
  89.  
  90.     function showControls() {
  91.         document.documentElement.classList.remove('tm-controls-hidden');
  92.     }
  93.  
  94.     function resetHideTimer() {
  95.         showControls();
  96.  
  97.         clearTimeout(hideTimer);
  98.  
  99.         hideTimer = setTimeout(() => {
  100.             hideControls();
  101.         }, HIDE_AFTER_MS);
  102.     }
  103.  
  104.     /*
  105.      * Any activity inside the player:
  106.      * show UI and restart 2-second countdown.
  107.      */
  108.     window.addEventListener('mousemove', resetHideTimer, { passive: true });
  109.     window.addEventListener('mousedown', resetHideTimer, { passive: true });
  110.     window.addEventListener('keydown', resetHideTimer);
  111.  
  112.     /*
  113.      * Entering the player also starts the countdown.
  114.      */
  115.     window.addEventListener('mouseover', resetHideTimer, { passive: true });
  116.  
  117.     /*
  118.      * Leaving the iframe still hides instantly.
  119.      */
  120.     window.addEventListener('mouseout', (event) => {
  121.         if (
  122.             event.relatedTarget === null &&
  123.             event.toElement === null
  124.         ) {
  125.             hideControls();
  126.         }
  127.     });
  128.  
  129.     document.documentElement.addEventListener('mouseleave', hideControls);
  130.  
  131.     /*
  132.      * Start hidden.
  133.      */
  134.     hideControls();
  135. })();
Advertisement
Add Comment
Please, Sign In to add comment