Skip to content

Instantly share code, notes, and snippets.

@vic4key
Last active December 7, 2021 17:35
Show Gist options
  • Save vic4key/8e5c3497bf3f2270464aaf83a23abd4d to your computer and use it in GitHub Desktop.
Save vic4key/8e5c3497bf3f2270464aaf83a23abd4d to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name GitHub - Header Sticky On Top
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author Vic P. @ https://vic.onl/
// @match https://github.com
// @match https://github.com/*/*
// @match https://gist.github.com/*
// @exclude https://gist.github.com/*/*
// @icon https://github.githubassets.com/pinned-octocat.svg
// @grant none
// ==/UserScript==
let get_header_style = height => `
body {
padding-top: ${height}px;
}
.js-header-wrapper {
z-index: 120;
position: fixed !important;
width: 100%;
min-width: 1020px;
top: 0;
left: 0;
transform: translate3d(0, 0, 0);
transition: transform .3s;
}
.js-header-wrapper.hidden {
transform: translate3d(0, -${height}px, 0);
}`;
(function() {
'use strict';
let header = document.querySelector('.js-header-wrapper');
document.querySelector('head').insertAdjacentHTML('beforeend', `<style>${get_header_style(header.offsetHeight)}</style>`);
window.addEventListener('scroll', () => header.classList.remove('hidden'));
header.addEventListener('dblclick', () => window.scroll({ // use native smooth scrolling (Chrome >= 61, Firefox >= 36)
top: 0,
behavior: 'smooth'
}));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment