Scroll to Bottom

Add a button to scroll to the bottom of the websit

目前為 2023-11-13 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 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 Bottom
// @name:zh      底部按钮
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Add a button to scroll to the bottom of the websit
// @description:zh  添加一个按钮滚动到网站底部
// @author       ghzxs
// @match        *://*/*
// @grant        none
// @license     MIT
// ==/UserScript==

(function() {
    'use strict';

    // Base64-encoded SVG data
    const base64Icon = 'PHN2ZyBzdHJva2U9ImN1cnJlbnRDb2xvciIgZmlsbD0ibm9uZSIgc3Ryb2tlLXdpZHRoPSIyIiB2aWV3Qm94PSIwIDAgMjQgMjQiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgY2xhc3M9Imljb24tc20gbS0xIiBoZWlnaHQ9IjFlbSIgd2lkdGg9IjFlbSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48bGluZSB4MT0iMTIiIHkxPSI1IiB4Mj0iMTIiIHkyPSIxOSI+PC9saW5lPjxwb2x5bGluZSBwb2ludHM9IjE5IDEyIDEyIDE5IDUgMTIiPjwvcG9seWxpbmU+PC9zdmc+';

    // Create the button
    const button = document.createElement('button');
    button.innerHTML = `<img src="data:image/svg+xml;base64,${base64Icon}" alt="Scroll to Bottom">`;

    // Apply styles to the button
    button.style.position = 'fixed';
    button.style.bottom = '16px';
    button.style.right = '16px';
    button.style.zIndex = '9999';
    button.style.backgroundColor = 'none';
    button.style.border = '1px solid none';
    button.style.borderRadius = '50%';
    button.style.padding = '4px';
    button.style.cursor = 'pointer';

    // Add click event listener to scroll to the bottom
    button.addEventListener('click', function() {
        window.scrollTo({
            top: document.body.scrollHeight,
            behavior: 'smooth'
        });
    });

    // Append the button to the body
    document.body.appendChild(button);
})();