Go top

Add a button help to go top of the page

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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         Go top
// @namespace    https://github.com/K1ethoang
// @version      0.3
// @author       K1ethoang
// @match        *://*/*
// @icon         none
// @grant        none
// @description  Add a button help to go top of the page
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    let html = document.querySelector("html");
    let btn = document.createElement("button");

    html.style.scrollBehavior="smooth";

    btn.innerHTML = "Top";
    btn.style.display="none";
    btn.style.position="fixed";
    btn.style.bottom= "20px";
    btn.style.right= "30px";
    btn.style.zIndex="999999";
    btn.style.border= "none";
    btn.style.outline= "none";
    btn.style.backgroundColor= "red";
    btn.style.color= "white";
    btn.style.cursor="pointer";
    btn.style.padding= "12px";
    btn.style.borderRadius="10px";
    btn.style.fontSize="16px";

    btn.addEventListener('mouseover', () => {
    btn.style.backgroundColor = '#555';
    });

    btn.addEventListener('mouseout', () => {
    btn.style.backgroundColor = 'red';
    });

    html.appendChild(btn);

    window.onscroll = function() {scrollFunction()};

    function scrollFunction() {
        if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
            btn.style.display = "block";
        } else {
            btn.style.display = "none";
        }
    }

    function topFunction() {
        document.body.scrollTop = 0;
        document.documentElement.scrollTop = 0;
    }

    btn.addEventListener('click', topFunction);
})();