Last active
December 7, 2021 17:35
-
-
Save vic4key/8e5c3497bf3f2270464aaf83a23abd4d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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