GitHub Scroll To Top

Adds a scroll to top button to github

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

Δημιουργός
C Pritch
Ημερήσιες εγκαταστάσεις
0
Σύνολο εγκαταστάσεων
5
Βαθμολογίες
0 0 0
Έκδοση
2025-04-11
Δημιουργήθηκε την
11/04/2025
Ενημερώθηκε την
11/04/2025
Μέγεθος
4 KB
Άδεια
MIT
Εφαρμόζεται σε

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.