您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Adds a button to trim the middle part of text inside `.text-message` elements on chatgpt.com.
当前为
// ==UserScript== // @name Middle Text Ellipsis for ChatGPT // @namespace http://yournamespace.example.com // @version 1.0.1 // @description Adds a button to trim the middle part of text inside `.text-message` elements on chatgpt.com. // @match *://*.chatgpt.com/* // @license MIT // @locale en // ==/UserScript== (function() { 'use strict'; // Function to trim the middle of a string, keeping the first and last parts with an ellipsis in the middle const trimMiddle = (text, startChars, endChars) => { if (text.length <= startChars + endChars) return text; return `${text.slice(0, startChars)}...${text.slice(-endChars)}`; }; // Function to apply the trimming logic to all eligible `.text-message` elements const applyTrim = () => { const textMessages = document.querySelectorAll(".text-message"); console.log(textMessages); Array.from(textMessages).map((messageElement, index, allMessages) => { // Only apply the function to the last fifth of the elements if (index > allMessages.length * 0.8) return; // Traverse through specific child elements of the current '.text-message' element Array.from(messageElement.children[0].children[0]?.children).map((childElement, childIndex) => { if (childIndex === 0) { childElement.innerHTML = trimMiddle(childElement.innerHTML, 10, 10); } }); }); alert("Trim applied to the last fifth of text-message elements!"); // Notify when trim is applied }; // Create and inject a button to trigger the trimming function const createButton = () => { const button = document.createElement('button'); button.innerHTML = 'Trim Messages'; button.style.position = 'fixed'; button.style.bottom = '20px'; button.style.right = '20px'; button.style.padding = '10px'; button.style.backgroundColor = '#007bff'; button.style.color = '#fff'; button.style.border = 'none'; button.style.borderRadius = '5px'; button.style.cursor = 'pointer'; button.style.zIndex = '1000'; // When the button is clicked, apply the trim function button.addEventListener('click', applyTrim); document.body.appendChild(button); }; // Wait for the page to load and then create the button window.addEventListener('load', createButton); })();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址