Adds a small floating button to scroll to the top of the page
// ==UserScript==
// @name Simple Scroll To Top Button
// @namespace https://greasyfork.org/
// @version 1.0
// @description Adds a small floating button to scroll to the top of the page
// @author You
// @match *://*/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
const button = document.createElement('button');
button.textContent = '↑ Top';
Object.assign(button.style, {
position: 'fixed',
bottom: '20px',
right: '20px',
zIndex: '9999',
padding: '10px 14px',
border: 'none',
borderRadius: '8px',
background: '#222',
color: '#fff',
cursor: 'pointer',
fontSize: '14px',
boxShadow: '0 2px 8px rgba(0,0,0,0.25)',
display: 'none'
});
document.body.appendChild(button);
window.addEventListener('scroll', () => {
button.style.display = window.scrollY > 200 ? 'block' : 'none';
});
button.addEventListener('click', () => {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
})();