您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
限制Perplexity网站代码框高度为400px并添加复制按钮
当前为
// ==UserScript== // @name Perplexity 代码框限制高度 // @name:en Perplexity Code Height Limiter // @namespace http://tampermonkey.net/ // @version 1.1 // @description 限制Perplexity网站代码框高度为400px并添加复制按钮 // @description:en Limit code block height to 400px and add copy button on Perplexity // @author Dost // @match https://www.perplexity.ai/* // @grant GM_addStyle // @license MIT // ==/UserScript== (function() { 'use strict'; // Add styles for code block and copy button GM_addStyle(` pre { max-height: 400px !important; overflow-y: auto !important; position: relative !important; } .copy-button { position: sticky !important; bottom: 10px !important; right: 10px !important; float: right !important; background-color: #4a5568 !important; color: white !important; border: none !important; border-radius: 4px !important; padding: 5px 10px !important; cursor: pointer !important; opacity: 0 !important; transition: opacity 0.3s ease !important; z-index: 1000 !important; } pre:hover .copy-button { opacity: 1 !important; } .copy-button:hover { background-color: #2d3748 !important; } `); // Function to create and add copy button function addCopyButtonToCodeBlocks() { const codeBlocks = document.querySelectorAll('pre'); codeBlocks.forEach(pre => { if (!pre.querySelector('.copy-button')) { const copyButton = document.createElement('button'); copyButton.textContent = '复制'; copyButton.className = 'copy-button'; copyButton.addEventListener('click', async () => { const code = pre.textContent.replace('复制', '').trim(); try { await navigator.clipboard.writeText(code); copyButton.textContent = '已复制!'; setTimeout(() => { copyButton.textContent = '复制'; }, 2000); } catch (err) { copyButton.textContent = '复制失败'; setTimeout(() => { copyButton.textContent = '复制'; }, 2000); } }); pre.appendChild(copyButton); } }); } // Create observer to handle dynamically loaded content const observer = new MutationObserver(() => { addCopyButtonToCodeBlocks(); }); // Start observing observer.observe(document.body, { childList: true, subtree: true }); // Initial run addCopyButtonToCodeBlocks(); })();