Skip to content

Instantly share code, notes, and snippets.

@Yonezpt
Last active August 16, 2023 07:22
Show Gist options
  • Save Yonezpt/c007c82d9299cfa32f01 to your computer and use it in GitHub Desktop.
Save Yonezpt/c007c82d9299cfa32f01 to your computer and use it in GitHub Desktop.
Userscript that hides the YouTube header when a video is playing
// ==UserScript==
// @version 6
// @name Hide YouTube Header
// @namespace https://github.com/YePpHa/YouTubeCenter/issues/786
// @description Hides YouTube header when a video is playing
// @match *://www.youtube.com/*
// @run-at document-start
// @grant none
// @noframes
// ==/UserScript==
(function () {
'use strict';
var sheet =
'#masthead-positioner,#masthead-positioner-height-offset{max-height:90px;transition:max-height 1s;overflow:hidden}\n' +
'#body #body-container .hide{max-height:0 !important;}',
core = function () {
var detour = window.onYouTubePlayerReady;
function playerReady(a) {
var header = document.getElementById('masthead-positioner'),
offset = document.getElementById('masthead-positioner-height-offset');
function stateChange(b) {
if (!/0|2|5/.test(b) && !header.classList.contains('hide') && location.href.indexOf('/watch') !== -1) {
header.classList.add('hide');
offset.classList.add('hide');
} else if (/0|2|5/.test(b) && header.classList.contains('hide')) {
header.classList.remove('hide');
offset.classList.remove('hide');
}
}
if (location.href.indexOf('/watch') !== -1) {
header.classList.add('hide');
offset.classList.add('hide');
}
a.addEventListener('onStateChange', stateChange, false);
}
window.onYouTubePlayerReady = function (){
playerReady(arguments[0]);
detour.apply(window, arguments);
};
};
function inject(a, b) {
var injection = document.createElement(b);
document.head.appendChild(injection);
injection.textContent = a;
}
inject(sheet, 'style');
inject('(' + core + ')()', 'script');
}());
@VitaliyAT
Copy link

VitaliyAT commented Aug 16, 2023

Could you do in this script or in other, that when you push or switch to Theater mode all upper head (options, YT logo, search, mic, create, notification, account - this line) is sliding up? Move mouse upper area - it's sliding down, but up high video.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment