// ==UserScript==
// @name Claude Pasted Content Copier
// @description Adds copy functionality to pasted content on Claude.ai
// @icon https://claude.ai/favicon.ico
// @version 1.3
// @author afkarxyz
// @namespace https://github.com/afkarxyz/userscripts/
// @supportURL https://github.com/afkarxyz/userscripts/issues
// @license MIT
// @match *://claude.ai/*
// @grant none
// @downloadURL https://update.greasyfork.icu/scripts/511406/Claude%20Pasted%20Content%20Copier.user.js
// @updateURL https://update.greasyfork.icu/scripts/511406/Claude%20Pasted%20Content%20Copier.meta.js
// ==/UserScript==
(function() {
'use strict';
function addCopyButton() {
const targetHeading = document.querySelector('h2.font-styrene-display.flex-1.truncate.text-lg.font-medium');
if (targetHeading && !targetHeading.querySelector('.copy-button')) {
targetHeading.textContent = 'Pasted content';
const copyButton = document.createElement('button');
copyButton.className = `copy-button inline-flex items-center justify-center relative shrink-0 ring-offset-2 ring-offset-bg-300 ring-accent-main-100 focus-visible:outline-none focus-visible:ring-1 disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none disabled:drop-shadow-none text-text-200 transition-all font-styrene active:bg-bg-400 hover:bg-bg-500/40 hover:text-text-100 h-8 w-8 rounded-md active:scale-95 ml-2`;
copyButton.setAttribute('data-state', 'closed');
copyButton.innerHTML = `
`;
copyButton.addEventListener('click', copyText);
targetHeading.style.display = 'flex';
targetHeading.style.alignItems = 'center';
targetHeading.appendChild(copyButton);
}
}
function copyText() {
const textElement = document.querySelector('div.-m-1.mt-0.min-h-0.flex-1.whitespace-pre-wrap.break-all.text-xs.p-4.bg-bg-000.rounded-lg.border-0\\.5.border-border-300.overflow-y-auto.font-mono.shadow-sm');
if (textElement) {
navigator.clipboard.writeText(textElement.textContent).then(() => {
const copyButton = document.querySelector('.copy-button');
if (copyButton) {
const originalHTML = copyButton.innerHTML;
copyButton.innerHTML = `
`;
setTimeout(() => {
copyButton.innerHTML = originalHTML;
}, 1000);
}
});
}
}
function init() {
addCopyButton();
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.type === 'childList') {
addCopyButton();
}
});
});
observer.observe(document.body, { childList: true, subtree: true });
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
})();