ChatGPT Share Messages

Adds a share button to the action bar of each message in ChatGPT.

  1. // ==UserScript==
  2. // @name ChatGPT Share Messages
  3. // @namespace https://gf.qytechs.cn/en/users/1444872-tlbstation
  4. // @version 1.8
  5. // @description Adds a share button to the action bar of each message in ChatGPT.
  6. // @icon https://i.ibb.co/jZ3HpwPk/pngwing-com.png
  7. // @author TLBSTATION
  8. // @match https://chatgpt.com/*
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. function addShareButtons() {
  17. document.querySelectorAll('.flex.items-center.justify-start.rounded-xl.p-1').forEach(actionContainer => {
  18. if (!actionContainer || actionContainer.querySelector('.share-button')) return; // Prevent duplicates
  19.  
  20. // Locate the exact div where icons are placed
  21. const buttonGroup = actionContainer.querySelector('.flex.items-center.transition-opacity');
  22. if (!buttonGroup) return;
  23.  
  24. // Find the message text
  25. const messageContainer = actionContainer.closest('.flex.w-full');
  26. if (!messageContainer) return;
  27.  
  28. const messageTextElement = messageContainer.querySelector('.prose');
  29. if (!messageTextElement) return;
  30. const messageText = messageTextElement.innerText.trim();
  31.  
  32. // Create the Share button
  33. const shareButton = document.createElement('span');
  34. shareButton.setAttribute('data-state', 'closed');
  35. shareButton.innerHTML = `
  36. <button class="rounded-lg text-token-text-secondary hover:bg-token-main-surface-secondary share-button" aria-label="Share message" title="Share message">
  37. <span class="flex h-[30px] w-[30px] items-center justify-center">
  38. <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" class="icon-md-heavy">
  39. <path fill-rule="evenodd" clip-rule="evenodd" d="M11.2929 3.29289C11.6834 2.90237 12.3166 2.90237 12.7071 3.29289L16.7071 7.29289C17.0976 7.68342 17.0976 8.31658 16.7071 8.70711C16.3166 9.09763 15.6834 9.09763 15.2929 8.70711L13 6.41421V15C13 15.5523 12.5523 16 12 16C11.4477 16 11 15.5523 11 15V6.41421L8.70711 8.70711C8.31658 9.09763 7.68342 9.09763 7.29289 8.70711C6.90237 8.31658 6.90237 7.68342 7.29289 7.29289L11.2929 3.29289ZM4 14C4.55228 14 5 14.4477 5 15V18C5 18.5523 5.44772 19 6 19H18C18.5523 19 19 18.5523 19 18V15C19 14.4477 19.4477 14 20 14C20.5523 14 21 14.4477 21 15V18C21 19.6569 19.6569 21 18 21H6C4.34315 21 3 19.6569 3 18V15C3 14.4477 3.44772 14 4 14Z" fill="currentColor"></path>
  40. </svg>
  41. </span>
  42. </button>
  43. `;
  44.  
  45. // Share functionality
  46. shareButton.querySelector('button').addEventListener('click', () => {
  47. if (navigator.share) {
  48. navigator.share({ text: messageText }).catch(err => console.error('Sharing failed:', err));
  49. } else if (navigator.clipboard) {
  50. navigator.clipboard.writeText(messageText).then(() => {
  51. alert('Message copied to clipboard!');
  52. }).catch(err => console.error('Failed to copy text: ', err));
  53. }
  54. });
  55.  
  56. // Find the "Edit in Canvas" button
  57. const editCanvasButton = buttonGroup.querySelector('[aria-label="Edit in canvas"]');
  58. if (editCanvasButton) {
  59. // Insert the share button **directly after** "Edit in Canvas"
  60. editCanvasButton.parentNode.insertAdjacentElement('afterend', shareButton);
  61. } else {
  62. // Fallback: Append at the end if "Edit in Canvas" isn't found
  63. buttonGroup.appendChild(shareButton);
  64. }
  65. });
  66. }
  67.  
  68. // Observe new messages and apply the button dynamically
  69. const observer = new MutationObserver(addShareButtons);
  70. observer.observe(document.body, { childList: true, subtree: true });
  71.  
  72. // Initial run
  73. addShareButtons();
  74. })();

QingJ © 2025

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