GitHub Scroll To Top

Adds a scroll to top button to github

Tendrás que instalar una extensión para tu navegador como Tampermonkey, Greasemonkey o Violentmonkey si quieres utilizar este script.

You will need to install an extension such as Tampermonkey to install this script.

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Userscripts para instalar este script.

Necesitará instalar una extensión como Tampermonkey para instalar este script.

Necesitarás instalar una extensión para administrar scripts de usuario si quieres instalar este script.

(Ya tengo un administrador de scripts de usuario, déjame instalarlo)

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

(Ya tengo un administrador de estilos de usuario, déjame instalarlo)

Autor
C Pritch
Instalaciones diarias
0
Instalaciones totales
5
Calificaciones
0 0 0
Versión
2025-04-11
Creado
11/04/2025
Actualizado
11/04/2025
Tamaño
3.81 KB
Licencia
MIT
Funciona en

GitHub Scroll To Top Butto

Summary

This userscript adds a convenient "Scroll to Top" button to GitHub pages. The button remains hidden until you scroll down the page, at which point it smoothly slides into view in the bottom-right corner. Clicking the button provides a smooth scroll animation back to the top of the page.

Features

  • Smooth Scrolling: Uses window.scrollTo({ behavior: 'smooth' }) for a pleasant scroll-to-top experience.
  • Animated Appearance: The button fades and slides into view only when you've scrolled down a certain amount (default: 200 pixels), keeping the UI clean when near the top.
  • Fixed Positioning: Stays accessible in the bottom-right corner regardless of scroll position (once visible).
  • Dynamic Loading: Waits for GitHub's main content area (.application-main) to appear before adding the button, ensuring compatibility with GitHub's dynamic page loading.
  • Simple Styling: Basic, clean button style that fits reasonably well with GitHub's UI.

How It Works

  1. The script runs early (@run-at document-start) to set up an observer.
  2. It waits for the document.body to be available.
  3. It checks if the element with the class .application-main exists.
    • If yes, it adds the button immediately.
    • If not, it uses a MutationObserver to watch for when .application-main is added to the page.
  4. Once the button is added:
    • It's initially styled to be hidden (opacity: 0) and positioned slightly off-screen (transform: translateY(50px)).
    • A CSS transition is applied for smooth animation effects.
    • A scroll event listener is attached to the window.
  5. When the user scrolls:
    • The listener checks if the vertical scroll distance (window.scrollY) exceeds a threshold (default: 200px).
    • If it exceeds the threshold, the button's style is updated to opacity: 1 and transform: translateY(0), causing it to slide/fade in.
    • If it's below the threshold, the styles are reverted, hiding the button again.
  6. Clicking the button triggers window.scrollTo({ top: 0, behavior: 'smooth' }).

Installation

  1. Ensure you have a userscript manager extension installed in your browser (e.g., Tampermonkey, Greasemonkey, Violentmonkey).
  2. Install the script directly from Greasy Fork:
  3. Your userscript manager should prompt you to install the script. Confirm the installation. Updates will also be handled through Greasy Fork and your manager.

Customization

You can adjust the scroll distance required before the button appears by changing the scrollThreshold variable near the top of the script code (default is 200). If you modify the script locally, be aware that updates from Greasy Fork might overwrite your changes unless you disable automatic updates for this script in your manager.