Copy Green Text on OpenAI Playground

Create a button that copies the text of all green spans on a page

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

You will need to install an extension such as Tampermonkey to install this script.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Copy Green Text on OpenAI Playground
// @version      0.1
// @description  Create a button that copies the text of all green spans on a page
// @match        https://beta.openai.com/playground
// @icon         https://www.google.com/s2/favicons?sz=64&domain=openai.com
// @author       Taylor Bell
// @grant        none
// @license      MIT
// @namespace https://greatest.deepsurf.us/users/999210
// ==/UserScript==

(function() {
    'use strict';

    // Create the button
    window.onload = function() {
        const button = document.createElement('button');
        button.innerText = 'Copy Green Text';

        // Add the specified classes to the button
        button.classList.add('btn', 'btn-sm', 'btn-filled', 'btn-neutral');

        // Add a click event listener to the button
        button.addEventListener('click', async () => {
            // When clicked, get all the green span elements and their text
            const greenSpans = document.querySelectorAll('span[style*="background-color: var(--green"]');
            const greenText = [...greenSpans].map(x => x.innerText).join('');

            // Copy the text to the clipboard
            try {
                await navigator.clipboard.writeText(greenText);
            } catch (err) {
                console.error('Failed to copy text: ', err);
            }
        });

        // Keep checking for the element to append the button to
        const interval = setInterval(() => {
            // Find the element
            const headerActions = document.querySelector('div.pg-header > div.pg-header-section.pg-header-actions');

            // Check if the element exists
            if (headerActions) {
                // Append the button to the page
                headerActions.appendChild(button);

                // Clear the interval
                clearInterval(interval);
            }
        }, 500); // Check every 500ms
    }
})();