ChatGPT Remove Special Characters on Copy

Auto remove special characters '(', ')', '[', ']' when copying text in ChatGPT

目前为 2024-09-19 提交的版本。查看 最新版本

// ==UserScript==
// @name         ChatGPT Remove Special Characters on Copy
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Auto remove special characters '(', ')', '[', ']' when copying text in ChatGPT
// @author       eternal-echo
// @match        https://chatgpt.com/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Wait until the page fully loads
    window.addEventListener('load', function() {

        // Function to remove special characters from text
        function removeSpecialCharacters(text) {
            return text.replace(/\\\[|\\\]|\\\(|\\\)/g, '');
        }

        // Listen for any clicks on buttons with the 'data-testid="copy-turn-action-button"' attribute
        document.body.addEventListener('click', function(e) {
            if (e.target.closest('[data-testid="copy-turn-action-button"]')) {
                // Wait for the text to be copied to the clipboard
                setTimeout(() => {
                    navigator.clipboard.readText().then((text) => {
                        let modifiedText = removeSpecialCharacters(text);
                        // Write the modified text back to the clipboard
                        navigator.clipboard.writeText(modifiedText);
                    });
                }, 100); // Delay to ensure the text is copied before we modify it
            }
        });
    });
})();

QingJ © 2025

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