Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name YouTube Embed Cleaner - Instant Hide + Fullscreen Timeout
- // @namespace custom
- // @version 1.5
- // @match https://www.youtube.com/embed/*
- // @match https://www.youtube-nocookie.com/embed/*
- // @grant none
- // @run-at document-idle
- // ==/UserScript==
- (function () {
- 'use strict';
- const HIDE_AFTER_MS = 1000;
- const style = document.createElement('style');
- style.textContent = `
- /* Remove dark gradient/background permanently */
- .player-controls-background-container,
- .player-controls-background {
- background: transparent !important;
- background-image: none !important;
- opacity: 0 !important;
- pointer-events: none !important;
- }
- /* Hide main UI */
- html.tm-controls-hidden player-top-controls,
- html.tm-controls-hidden player-middle-controls,
- html.tm-controls-hidden player-bottom-controls,
- html.tm-controls-hidden yt-progress-bar,
- html.tm-controls-hidden .player-controls-top,
- html.tm-controls-hidden .player-controls-middle,
- html.tm-controls-hidden .player-controls-bottom,
- html.tm-controls-hidden .ytmVideoInfoOverlay,
- html.tm-controls-hidden .ytwPlayerTopControlsHost,
- html.tm-controls-hidden .ytwPlayerMiddleControlsHost,
- html.tm-controls-hidden .ytwPlayerBottomControlsHost,
- /* Share / action menu */
- html.tm-controls-hidden player-fullscreen-action-menu,
- html.tm-controls-hidden .ytwPlayerFullscreenActionMenuHost,
- /* More-videos / thumbnail overlays */
- html.tm-controls-hidden .videoThumbnailGroupOverlayBottomLeftRightGroup,
- html.tm-controls-hidden .videoThumbnailGroupOverlayLeftRightGroup,
- html.tm-controls-hidden ytm-thumbnail-overlay-time-status-renderer {
- opacity: 0 !important;
- visibility: hidden !important;
- pointer-events: none !important;
- transition: none !important;
- animation: none !important;
- }
- /* Remove the large center play/pause control */
- player-middle-controls,
- .ytwPlayerMiddleControlsHost,
- .player-controls-middle {
- display: none !important;
- }
- /* Disable YouTube fade delay */
- player-top-controls,
- player-middle-controls,
- player-bottom-controls,
- yt-progress-bar,
- .player-controls-top,
- .player-controls-middle,
- .player-controls-bottom,
- .ytmVideoInfoOverlay,
- player-fullscreen-action-menu {
- transition: none !important;
- }
- `;
- document.head.appendChild(style);
- let hideTimer = null;
- function hideControls() {
- clearTimeout(hideTimer);
- document.documentElement.classList.add('tm-controls-hidden');
- }
- function showControls() {
- document.documentElement.classList.remove('tm-controls-hidden');
- }
- function resetHideTimer() {
- showControls();
- clearTimeout(hideTimer);
- hideTimer = setTimeout(() => {
- hideControls();
- }, HIDE_AFTER_MS);
- }
- /*
- * Any activity inside the player:
- * show UI and restart 2-second countdown.
- */
- window.addEventListener('mousemove', resetHideTimer, { passive: true });
- window.addEventListener('mousedown', resetHideTimer, { passive: true });
- window.addEventListener('keydown', resetHideTimer);
- /*
- * Entering the player also starts the countdown.
- */
- window.addEventListener('mouseover', resetHideTimer, { passive: true });
- /*
- * Leaving the iframe still hides instantly.
- */
- window.addEventListener('mouseout', (event) => {
- if (
- event.relatedTarget === null &&
- event.toElement === null
- ) {
- hideControls();
- }
- });
- document.documentElement.addEventListener('mouseleave', hideControls);
- /*
- * Start hidden.
- */
- hideControls();
- })();
Advertisement
Add Comment
Please, Sign In to add comment