Scroll To Top/Bottom Button

Add buttons to scroll to top and bottom of page in the bottom right corner of the screen

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Scroll To Top/Bottom Button
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Add buttons to scroll to top and bottom of page in the bottom right corner of the screen
// @match        *://*/*
// @grant        GM_addStyle
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Check if running in top-level document and not in an iframe
    if (window.self === window.top && !window.frameElement) {
        // Define the styles for the buttons
        var styles = `
            .scroll-to-btn {
                position: fixed;
                right: 20px;
                font-size: 50px;
                border: none;
                color: white;
                border-radius: 10%;
                cursor: pointer;
                z-index: 9999; /* set z-index to a high value */
                background-color: transparent;
                filter: grayscale(90%);
                /* transform: rotateX(30deg)  translateZ(50px) ;*/
            }
            .scroll-to-btn.top {
                bottom: 95px;
            }
            .scroll-to-btn.bottom {
                bottom: 40px;
            }
        `;

        // Add the styles to the page
        GM_addStyle(styles);

        // Create the scroll to top button
        var scrollToTopBtn = document.createElement("button");
        scrollToTopBtn.innerText = "🔼";
        scrollToTopBtn.classList.add("scroll-to-btn", "top");
        scrollToTopBtn.addEventListener("click", function() {
            window.scrollTo({top: 0, behavior: 'smooth',timingFunction: 'cubic-bezier(0,.84,.49,.99)'});
        });

        // Create the scroll to bottom button
        var scrollToBottomBtn = document.createElement("button");
        scrollToBottomBtn.innerText = "🔽";
        scrollToBottomBtn.classList.add("scroll-to-btn", "bottom");
        scrollToBottomBtn.addEventListener("click", function() {
            window.scrollTo({top: document.body.scrollHeight, behavior: 'smooth',timingFunction: 'cubic-bezier(0,.84,.49,.99)'});
        });

        // Add the buttons to the page
        document.body.appendChild(scrollToTopBtn);
        document.body.appendChild(scrollToBottomBtn);
    }
})();