To Top Buttonfiguccio

Aggiunge un pulsante per tornare all'inizio delle pagine.

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

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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.

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

// ==UserScript==
// @name           To Top Buttonfiguccio
// @author         figuccio
// @namespace      https://greatest.deepsurf.us/users/237458
// @description    Aggiunge un pulsante per tornare all'inizio delle pagine.
// @version        0.4
// @match          *://*/*
// @noframes
// @grant          GM_addStyle
// @icon           https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @license        MIT
// ==/UserScript==
(function() {
    'use strict';

    var toTopButton = document.createElement('div');
    toTopButton.innerHTML = '<button id="toTopButton" type="button" title="Torna su">🡹</button>';
    toTopButton.setAttribute('id', 'toTopContainer');
    document.body.appendChild(toTopButton);

    // Attiva il pulsante appena aggiunto.
    document.getElementById("toTopButton").addEventListener("click", function() {
        window.scrollTo(0, 0);
    });

    // Stile del pulsante.
    GM_addStyle(`
        #toTopButton {
            position: fixed;
            bottom: 2px;
            right: 170px;
            text-align: left;
            font-size: 11pt;
            font-weight: bold;
            cursor: pointer;
            color: red !important;
            background-color: yellow;
            border: 2px solid black;
            border-radius: 12px;
            padding: 6px 15px;
            z-index: 99999;
            text-decoration: none;
        }
    `);

    // Mostra o nasconde il pulsante in base alla posizione dello scroll.
    function toggleButtonVisibility() {
        var button = document.getElementById("toTopContainer");
        if (document.body.scrollTop > 500 || document.documentElement.scrollTop > 500) {
            button.style.display = 'block';
        } else {
            button.style.display = 'none';
        }
    }

    // Aggiorna la visibilità del pulsante all'avvio e ad ogni scroll.
    window.addEventListener('load', toggleButtonVisibility);
    window.addEventListener('scroll', toggleButtonVisibility);
})();