Skip to content

Instantly share code, notes, and snippets.

@Yonezpt
Last active August 29, 2015 14:13
Show Gist options
  • Save Yonezpt/cf655fe7f9751877fb3d to your computer and use it in GitHub Desktop.
Save Yonezpt/cf655fe7f9751877fb3d to your computer and use it in GitHub Desktop.
Shows YouTube header when moving mouse to the top of the browser
// ==UserScript==
// @version 7
// @name Mouseover show Youtube Header
// @namespace https://github.com/YePpHa/YouTubeCenter/issues/1393
// @description Shows YouTube header when moving the mouse to the top of the browser
// @match *://www.youtube.com/*
// @run-at document-start
// @grant none
// @noframes
// ==/UserScript==
(function () {
'use strict';
var sheet =
'#masthead-positioner,#masthead-positioner-height-offset{margin-top:0;transition:margin-top 1s}\n' +
'#body #body-container .hide{margin-top:-50px}',
core = function () {
var header,
offset;
function mouseTrack(a) {
header = document.getElementById('masthead-positioner');
offset = document.getElementById('masthead-positioner-height-offset');
if (location.href.indexOf('/watch') !== -1) {
if (a.clientY <= 90 && header && header.classList.contains('hide')) {
header.classList.remove('hide');
if ((window.chrome && document.body.scrollTop <= 50) || document.documentElement.scrollTop <= 50) {
offset.classList.remove('hide');
}
} else if (a.clientY > 90 && header && !header.classList.contains('hide') && !header.contains(document.activeElement)) {
header.classList.add('hide');
offset.classList.add('hide');
}
}
}
function reset(){
if (location.href.indexOf('/watch') === -1 && header && header.classList.contains('hide')) {
header.classList.remove('hide');
offset.classList.remove('hide');
}
}
function scroll(a) {
if (window.chrome && document.body.scrollTop === 50) {
document.body.scrollTop = 0;
} else if (a.pageY === 50) {
document.documentElement.scrollTop = 0;
}
}
window.addEventListener('mousemove', mouseTrack, false);
window.addEventListener('spfdone', reset, false);
window.addEventListener('scroll', scroll, true);
};
function inject(a, b) {
var injection = document.createElement(b);
document.head.appendChild(injection);
injection.textContent = a;
}
inject(sheet, 'style');
inject('(' + core + ')()', 'script');
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment