User:Overandoutnerd/Scripts/goToTop
From Wikipedia, the free encyclopedia
A personal JavaScript user script that adds a Material-You-style “scroll to top” floating button.
The button appears after scrolling down the page and smoothly scrolls the page back to the top when clicked. This script runs across the Wikipedia only for the user who installs it.
Features
- Floating button fixed to the bottom-right corner
- Appears only after scrolling down
- Smooth scroll back to top
- Material-inspired rounded design
- Click ripple effect
- Automatic adaptation to light and dark themes
- Supports Wikipedia theme changes without page reload
Usage
- Scroll any Wikipedia page.
- Once the page is scrolled beyond a predefined distance, a button appears in the lower-right corner.
- Click the button to smoothly scroll back to the top of the page.
No configuration or user interaction is required after installation.
Installation
- To install the script, add this to your common.js file.
importScript('User: Overandoutnerd/Scripts/goToTop.js'); // Backlink: [[User:Overandoutnerd/Scripts/goToTop.js]]
- Save the page.
- Clear your browser cache or hard reload the page.
The script will run automatically on all Wikipedia pages after installation.
Theme
The script detects Wikipedia’s active theme and adapts automatically:
- Explicit dark mode
- Automatic mode based on system theme
- Light mode
Theme changes are detected dynamically, meaning the button updates instantly when switching between light and dark mode without requiring a page reload. The script avoids hard dependency on a single theme class to ensure compatibility across different skins and devices, including mobile views.
Scope and limitations
- This script runs only for the logged-in user who installs it.
- Other users viewing your user page will not see the button
- This is enforced by Wikipedia’s client-side scripting security model
- The script does not modify page content or affect editing
See also
Attribution
Adapted and customized by Overandoutnerd.
The script is based on the original goToTop user script by Numbermaniac.
The version hosted here includes customization and enhancements, including updated styling, positioning, and touch-friendly behavior.