Copy Green Text on OpenAI Playground

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

  1. // ==UserScript==
  2. // @name Copy Green Text on OpenAI Playground
  3. // @version 0.1
  4. // @description Create a button that copies the text of all green spans on a page
  5. // @match https://beta.openai.com/playground
  6. // @icon https://www.google.com/s2/favicons?sz=64&domain=openai.com
  7. // @author Taylor Bell
  8. // @grant none
  9. // @license MIT
  10. // @namespace https://gf.qytechs.cn/users/999210
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // Create the button
  17. window.onload = function() {
  18. const button = document.createElement('button');
  19. button.innerText = 'Copy Green Text';
  20.  
  21. // Add the specified classes to the button
  22. button.classList.add('btn', 'btn-sm', 'btn-filled', 'btn-neutral');
  23.  
  24. // Add a click event listener to the button
  25. button.addEventListener('click', async () => {
  26. // When clicked, get all the green span elements and their text
  27. const greenSpans = document.querySelectorAll('span[style*="background-color: var(--green"]');
  28. const greenText = [...greenSpans].map(x => x.innerText).join('');
  29.  
  30. // Copy the text to the clipboard
  31. try {
  32. await navigator.clipboard.writeText(greenText);
  33. } catch (err) {
  34. console.error('Failed to copy text: ', err);
  35. }
  36. });
  37.  
  38. // Keep checking for the element to append the button to
  39. const interval = setInterval(() => {
  40. // Find the element
  41. const headerActions = document.querySelector('div.pg-header > div.pg-header-section.pg-header-actions');
  42.  
  43. // Check if the element exists
  44. if (headerActions) {
  45. // Append the button to the page
  46. headerActions.appendChild(button);
  47.  
  48. // Clear the interval
  49. clearInterval(interval);
  50. }
  51. }, 500); // Check every 500ms
  52. }
  53. })();

QingJ © 2025

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