您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Adds a customizable scroll-to-top button near the page bottom.
Hey! So you've got this JavaScript UserScript called "Scroll to Top Button". Let's dive into what it does, how it ticks, and whether you should trust it on your browser.
What is it for? Simple:
Ever been deep down a super long webpage (think infinite scroll feeds, massive articles, long forum threads) and just wished for a quick "zap me back to the top" button? That's exactly what this script does. It adds a little button, usually chilling near the bottom-right corner of your screen, that only shows up when you've scrolled down a bit. Click it, and whoosh, you're back at the top.
How Does it Work (The Gist)?
DOMContentLoaded
). No point trying to add a button if there's nowhere to put it yet, right?_injS
function) to define how the button looks (size, color, position, roundness, shadow, etc.) and how it animates (fade in/out, grow/shrink on hover). It gives these styles a unique ID (_sid
) to avoid messing with the site's own styles._crB
function) using JavaScript, gives it a unique ID (_bid
), sets its text label (for accessibility), adds a neat SVG up-arrow icon, and most importantly, tells it what to do when clicked (_scT
function).<body>
.window.addEventListener('scroll', ...)
)._deb
function). This means it waits until you've stopped scrolling for a tiny moment (like 150 milliseconds, configurable!) before checking if you've scrolled far enough down (_cfg.bh.shThrPx
, default 300 pixels) to show the button (_hSE
function). If you scroll back up near the top, it hides the button again. It also re-checks if the page layout changes (MutationObserver
) or if you resize the window._scT
function):
_cfg.bh.smScr
).behavior: 'auto'
)._cfg.bh.natSmScr
and checks browser support). If yes, it uses behavior: 'smooth'
._smS
function). This uses requestAnimationFrame
(which is efficient for animations) and fancy math functions ("easing functions" like easeInOutCubic
stored in _eas
) to make the scroll look nice and smooth over a set duration (_cfg.sc.durMs
, default 800ms)._cfg
object right at the top of the script.Is it Safe to Use?
Yes, generally very safe. Here's why:
@grant none
: This is the most important line in the UserScript header for safety. It means the script tells your UserScript manager "Hey, I don't need any special permissions or access to browser APIs that could be risky." It runs in the standard web page environment.(function () { ... })();
which helps prevent its variables and functions from accidentally interfering with the website's own JavaScript.@noframes
: This prevents it from running inside embedded frames (iframes) on a page, which can sometimes be a vector for tricky behavior, though it's mostly just to ensure it behaves predictably on the main page.In short: It's a well-behaved script focused solely on adding a visual element and interacting with standard browser scrolling. It's about as safe as a UserScript gets.
Who is this for?
Anyone who browses the web and gets tired of manually scrolling back to the top of long pages. It's a simple quality-of-life improvement. If you like tweaking things, the configuration options are a nice bonus!