Navigate chat groups

Navigate through chat groups

目前為 2023-06-27 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Navigate chat groups
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Navigate through chat groups
// @author       awyugan
// @match        https://chat.openai.com/*
// @match        https://42share.io/gpt/*
// @grant        GM_addStyle
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    let groups = [];
    let currentGroupIndex = 0;

    function updateGroups() {
        // 获取所有的对话元素,根据当前URL选择不同的元素
        let groupSelector;
        if (window.location.href.startsWith('https://chat.openai.com')) {
            groupSelector = '.group.w-full.text-gray-800.dark\\:text-gray-100.border-b.border-black\\:10.dark\\:border-gray-900\\:50.dark\\:bg-gray-800';
        } else if (window.location.href.startsWith('https://42share.io/gpt')) {
            groupSelector = '.relative.mx-auto.max-w-screen-xl.dark\\:text-gray-100.text-gray-700.w-full.px-4.py-10';
        }
        if (groupSelector) {
            groups = Array.from(document.querySelectorAll(groupSelector));
            currentGroupIndex = 0;
        }
    }

    function navigateToPreviousGroups() {
        if (currentGroupIndex >= 2) {
            // 移动到前两个groups
            currentGroupIndex -= 2;
            groups[currentGroupIndex].scrollIntoView();
        } else if (currentGroupIndex === 1) {
            // 移动到第一个group
            currentGroupIndex = 0;
            groups[currentGroupIndex].scrollIntoView();
        }
    }

    function navigateToNextGroups() {
        if (currentGroupIndex < groups.length - 2) {
            // 移动到后两个groups
            currentGroupIndex += 2;
            groups[currentGroupIndex].scrollIntoView();
        } else if (currentGroupIndex === groups.length - 2) {
            // 移动到最后一个group
            currentGroupIndex = groups.length - 1;
            groups[currentGroupIndex].scrollIntoView();
        }
    }

    // 添加上箭头
    let previousArrow = document.createElement('div');
    previousArrow.innerHTML = '&#x25B2;'; // 上箭头的Unicode编码
    previousArrow.className = 'navigate-groups-arrow navigate-groups-arrow-previous';
    previousArrow.addEventListener('click', navigateToPreviousGroups);
    document.body.appendChild(previousArrow);

    // 添加下箭头
    let nextArrow = document.createElement('div');
    nextArrow.innerHTML = '&#x25BC;'; // 下箭头的Unicode编码
    nextArrow.className = 'navigate-groups-arrow navigate-groups-arrow-next';
    nextArrow.addEventListener('click', navigateToNextGroups);
    document.body.appendChild(nextArrow);

    // 创建一个观察器实例并传入回调函数
    let observer = new MutationObserver(updateGroups);

    // 选择需要观察的节点
    let targetNode = document.body;

    // 观察器的配置(需要观察什么变动)
    let config = { childList: true, subtree: true };

    // 开始观察目标节点
    observer.observe(targetNode, config);

    // 初始更新一次对话列表
    updateGroups();

    // 添加自定义样式
    GM_addStyle(`
        .navigate-groups-arrow {
            position: fixed;
            width: 40px;
            height: 40px;
            background-color: #ffffff;
            border-radius: 50%;
            text-align: center;
            line-height: 40px;
            cursor: pointer;
            box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2);
        }

        .navigate-groups-arrow:hover {
            background-color: #f5f5f5;
        }

        .navigate-groups-arrow-previous {
            bottom: 70px;
            right: 30px;
            font-size: 24px;
        }

        .navigate-groups-arrow-next {
            bottom: 20px;
            right: 30px;
            font-size: 24px;
        }
    `);
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址