Copy ChatGPT's all replies

Add a Copy button to the first element with class "ml-1" on https://chat.openai.com to copy content of all elements with class "prose" with basic formatting.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         Copy ChatGPT's all replies
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Add a Copy button to the first element with class "ml-1" on https://chat.openai.com to copy content of all elements with class "prose" with basic formatting.
// @author       You
// @match        https://chat.openai.com/*
// @grant        none
// @license MIT
// ==/UserScript==
(function() {
    'use strict';
    function getFormattedText(element) {
        let result = '';
        for (const child of element.childNodes) {
            switch (child.nodeType) {
                case Node.TEXT_NODE:
                    result += child.textContent;
                    break;
                case Node.ELEMENT_NODE:
                    switch (child.tagName) {
                        case 'BR':
                            result += '\n';
                            break;
                        case 'P':
                            result += getFormattedText(child) + '\n\n';
                            break;
                        case 'OL':
                        case 'UL':
                            const items = child.querySelectorAll('li');
                            if (child.tagName === 'OL') {
                                items.forEach((item, index) => {
                                    result += `${index + 1}. ${getFormattedText(item)}\n`;
                                });
                            } else {
                                items.forEach(item => {
                                    result += `- ${getFormattedText(item)}\n`;
                                });
                            }
                            result += '\n';
                            break;
                        default:
                            result += getFormattedText(child);
                    }
            }
        }
        return result;
    }
    function addCopyButton() {
        const ml1Element = document.querySelector('.ml-1');
        if (!ml1Element) return;
        const copyButton = document.createElement('button');
        copyButton.className = 'btn relative btn-neutral border-0 md:border';
        copyButton.textContent = 'Copy';
        copyButton.addEventListener('click', () => {
            const proseElements = document.querySelectorAll('.prose');
            let formattedText = '';
            for (const proseElement of proseElements) {
                formattedText += getFormattedText(proseElement);
            }
            navigator.clipboard.writeText(formattedText).then(() => {
                console.log('Prose content copied to clipboard with basic formatting.');
            }).catch(err => {
                console.error('Error copying prose content to clipboard:', err);
            });
        });
        ml1Element.appendChild(copyButton);
    }
    window.addEventListener('load', () => {
        setTimeout(addCopyButton, 1000);
    });
})();