Scroll to Top/bottom for mobile phone

A set of floating buttons on the screen that quickly scroll to the top and bottom of the page, and scroll up/down one page.

当前为 2025-02-21 提交的版本,查看 最新版本

// ==UserScript==
// @name         Scroll to Top/bottom for mobile phone
// @namespace    http://tampermonkey.net/
// @version      2.1
// @description  A set of floating buttons on the screen that quickly scroll to the top and bottom of the page, and scroll up/down one page.
// @author       Kamiya Minoru
// @match        *://*/*
// @exclude      *://www.google.com/*
// @exclude      *://www.google.com.tw/*
// @exclude      *://www.google.co.jp/*
// @exclude      https://www.bilibili.com/
// @exclude      https://*.microsoft/*
// @exclude      https://gemini.google.com/*
// @exclude      https://chatgpt.com/
// @exclude      https://claude.ai/*
// @exclude      https://www.perplexity.ai/*
// @exclude      https://chat.deepseek.com/*
// @exclude      https://www.twitch.tv/
// @noframes
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Create a container for the buttons
    var container = document.createElement('div');
    container.style.position = 'fixed';
    container.style.right = '2px';
    container.style.bottom = '90px';
    container.style.zIndex = '9999'; // Increased zIndex value
    document.body.appendChild(container);

    // Function to create a button
    function createButton(innerHTML, onClick) {
        var button = document.createElement('div');
        button.innerHTML = innerHTML;
        button.style.width = '30px';
        button.style.height = '30px';
        button.style.cursor = 'pointer';
        button.style.backgroundColor = 'transparent';
        button.style.color = 'grey';
        button.style.textAlign = 'center';
        button.style.fontSize = '30px';
        button.style.borderRadius = '0px';
        button.style.userSelect = 'none';
        button.style.marginBottom = '2px'; // Adjusted margin to 2px to prevent overlap
        button.style.opacity = '0.5'; // Set opacity to 0.5 for 50% transparency
        button.style.filter = 'drop-shadow(0 0 0 grey)';
        button.addEventListener('click', onClick);
        container.appendChild(button);
    }

    // SVG Icons
    const upArrowSVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512" width="30" height="30" fill="grey"><path d="M279 224h-71v192c0 17.7-14.3 32-32 32H144c-17.7 0-32-14.3-32-32V224H41c-12.5 0-23.6-7.5-28.7-19.1s-2.1-24.9 6.9-33.9l119-119c12.5-12.5 32.8-12.5 45.3 0l119 119c9 9 11.9 22.4 6.9 33.9s-16.2 19.1-28.7 19.1z"/></svg>`;
    const downArrowSVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512" width="30" height="30" fill="grey"><path d="M41 288h71V96c0-17.7 14.3-32 32-32h32c17.7 0 32 14.3 32 32v192h71c12.5 0 23.6 7.5 28.7 19.1s2.1 24.9-6.9 33.9l-119 119c-12.5 12.5-32.8 12.5-45.3 0l-119-119c-9-9-11.9-22.4-6.9-33.9S28.5 288 41 288z"/></svg>`;
    const upDownSVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512" width="30" height="30" fill="grey"><path d="M169.4 278.6c12.5 12.5 32.8 12.5 45.3 0l136-136c9.2-9.2 9.2-24.1 0-33.3L214.6 3.5c-9.2-9.2-24.1-9.2-33.3 0L45.3 139.3c-9.2 9.2-9.2 24.1 0 33.3l136 136zM214.6 233.4c-9.2 9.2-24.1 9.2-33.3 0l-136-136c-9.2-9.2-9.2-24.1 0-33.3L181.3 3.5c9.2-9.2 24.1-9.2 33.3 0L339.7 97.1c9.2 9.2 9.2 24.1 0 33.3l-136 136zM169.4 278.6c12.5 12.5 32.8 12.5 45.3 0l136-136c9.2-9.2 9.2-24.1 0-33.3L214.6 3.5c-9.2-9.2-24.1-9.2-33.3 0L45.3 139.3c-9.2 9.2-9.2 24.1 0 33.3l136 136zM214.6 233.4c-9.2 9.2-24.1 9.2-33.3 0l-136-136c-9.2-9.2-9.2-24.1 0-33.3L181.3 3.5c9.2-9.2 24.1-9.2 33.3 0L339.7 97.1c9.2 9.2 9.2 24.1 0 33.3l-136 136zM169.4 278.6c12.5 12.5 32.8 12.5 45.3 0l136-136c9.2-9.2 9.2-24.1 0-33.3L214.6 3.5c-9.2-9.2-24.1-9.2-33.3 0L45.3 139.3c-9.2 9.2-9.2 24.1 0 33.3l136 136z"/></svg>`;

    // Create the buttons with embedded SVG icons
    createButton(upArrowSVG, function() {
        window.scrollBy({ top: -window.innerHeight, behavior: 'instant' });
    });
    createButton(downArrowSVG, function() {
        window.scrollBy({ top: window.innerHeight, behavior: 'instant' });
    });
    createButton(upDownSVG, function() {
        if (window.scrollY === 0) {
            window.scrollTo({ top: document.body.scrollHeight, behavior: 'instant' });
        } else {
            window.scrollTo({ top: 0, behavior: 'instant' });
        }
    });
})();