// ==UserScript== // @name 提问问题目录列表导航生成器(ChatGPT 和 Perplexity.ai)- 优化版本 // @name:zh-CN 提问问题目录列表导航生成器(ChatGPT 和 Perplexity.ai)- 优化版本 // @name:zh-TW 提問目錄生成器(ChatGPT & Perplexity.ai) // @name:en Question Directory Generator (ChatGPT & Perplexity.ai) // @version 1.0.3 // @author 9dian9 // @namespace https://github.com/KelvienLee/question-directory-script // @description 为 ChatGPT 和 Perplexity.ai 提供提问目录导航功能,支持点击跳转至问题开头。 // @description:zh-CN 提供 ChatGPT 和 Perplexity.ai 提问目录功能,点击目录可跳转到问题开头。 // @description:zh-TW 提供 ChatGPT 和 Perplexity.ai 提問目錄功能,點選目錄可跳轉至問題開頭。 // @description:en Adds a question directory for ChatGPT and Perplexity.ai, enabling smooth scroll to question start. // @match https://chatgpt.com/* // @match https://www.perplexity.ai/* // @grant none // @license MIT // @downloadURL https://update.greasyfork.icu/scripts/523445/%E6%8F%90%E9%97%AE%E9%97%AE%E9%A2%98%E7%9B%AE%E5%BD%95%E5%88%97%E8%A1%A8%E5%AF%BC%E8%88%AA%E7%94%9F%E6%88%90%E5%99%A8%EF%BC%88ChatGPT%20%E5%92%8C%20Perplexityai%EF%BC%89-%20%E4%BC%98%E5%8C%96%E7%89%88%E6%9C%AC.user.js // @updateURL https://update.greasyfork.icu/scripts/523445/%E6%8F%90%E9%97%AE%E9%97%AE%E9%A2%98%E7%9B%AE%E5%BD%95%E5%88%97%E8%A1%A8%E5%AF%BC%E8%88%AA%E7%94%9F%E6%88%90%E5%99%A8%EF%BC%88ChatGPT%20%E5%92%8C%20Perplexityai%EF%BC%89-%20%E4%BC%98%E5%8C%96%E7%89%88%E6%9C%AC.meta.js // ==/UserScript== (function () { 'use strict'; // 这里可自由调整,设置滚动到问题时保留多少顶部空间 // 如果有固定导航栏,可适度增大这个值 const SCROLL_MARGIN = 100; let observer; let lastUrl = window.location.href; /** * 初始化 */ function init() { const siteType = detectSite(); if (!siteType) { console.warn('不支持的网站'); return; } const chatContainer = siteType === 'chatgpt' ? document.querySelector('div.m-auto.text-base') : document.querySelector('main'); // Perplexity 的主内容区 if (!chatContainer) { console.warn('未找到聊天容器,稍后重试'); return; } if (document.getElementById('question-directory-container')) return; // 创建提问目录容器 const container = document.createElement('div'); container.id = 'question-directory-container'; container.style.cssText = ` position: fixed; top: 150px; right: 10px; z-index: 9999; font-family: "Arial", sans-serif; `; document.body.appendChild(container); // 创建展开/收起按钮 const toggleButton = document.createElement('button'); toggleButton.id = 'toggle-question-directory'; toggleButton.textContent = ' ▼'; toggleButton.style.cssText = ` position: absolute; right: 0; padding: 10px 15px; background-color: #4CAF50; color: white; border: none; border-radius: 8px; cursor: pointer; font-size: 16px; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1); transition: background-color 0.3s ease, box-shadow 0.3s ease; `; toggleButton.addEventListener('mouseover', () => { toggleButton.style.backgroundColor = '#45A049'; toggleButton.style.boxShadow = '0px 6px 12px rgba(0, 0, 0, 0.2)'; }); toggleButton.addEventListener('mouseout', () => { toggleButton.style.backgroundColor = '#4CAF50'; toggleButton.style.boxShadow = '0px 4px 8px rgba(0, 0, 0, 0.1)'; }); container.appendChild(toggleButton); // 创建目录面板 const directory = document.createElement('div'); directory.id = 'question-directory'; directory.style.cssText = ` display: none; /* 默认收起 */ margin-top: 10px; width: 300px; max-height: 70vh; overflow-y: auto; background-color: #fff; padding: 15px; border: 1px solid #ddd; border-radius: 8px; box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.1); `; directory.innerHTML = '