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 เพื่อติดตั้งสคริปต์นี้

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==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);
})();