ChatGPT返回顶部

使用↑符号的返回顶部按钮,并尝试滚动所有可能的滚动容器

当前为 2024-05-11 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         ChatGPT返回顶部
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  使用↑符号的返回顶部按钮,并尝试滚动所有可能的滚动容器
// @author       Hill
// @match        https://chatgpt.com/*
// @grant        none
// @run-at       document-end
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // 创建返回顶部的按钮
    var btnTop = document.createElement('button');
    btnTop.innerText = '↑'; // 使用“↑”符号
    btnTop.style.position = 'fixed';
    btnTop.style.top = '20px';
    btnTop.style.right = '20px';
    btnTop.style.padding = '10px';
    btnTop.style.zIndex = '1000';
    btnTop.style.cursor = 'pointer';
    btnTop.style.fontSize = '24px'; // 调整字体大小以增大箭头

    // 点击事件处理函数,尝试滚动所有可能的滚动容器
    btnTop.onclick = function() {
        var scrollableElements = document.querySelectorAll('html, body, div');
        scrollableElements.forEach(function(elem) {
            if (elem.scrollHeight > elem.clientHeight) { // 检查元素是否具有滚动条
                try {
                    elem.scrollTo({top: 0, behavior: 'smooth'});
                    console.log('尝试滚动元素:', elem);
                } catch (error) {
                    console.error('滚动元素错误:', error);
                }
            }
        });
    };

    // 将按钮添加到页面上
    document.body.appendChild(btnTop);

    console.log('返回顶部按钮已创建并就绪');
})();