// ==UserScript== // @name Export Claude.Ai // @description Download the conversation with Claude // @version 1.3 // @namespace https://github.com/TheAlanK // @grant none // @match *://claude.ai/* // @license MIT // @downloadURL none // ==/UserScript== (function() { 'use strict'; function getTextByClass(className) { const elements = document.getElementsByClassName(className); const result = []; Array.from(elements).forEach(el => { console.log(elements); const clone = el.cloneNode(true); const unwantedElements = clone.querySelectorAll('svg, button'); unwantedElements.forEach(unwantedEl => { unwantedEl.remove(); }); result.push(clone.innerText.trim()); }); return result.join("\n"); } function addButton() { const inputFile = document.querySelector('[data-testid="file-upload"]'); if (!inputFile) return; const container = inputFile.closest('div'); if (!container) return; if (document.getElementById('customExportButton')) return; const button = document.createElement("button"); button.id = 'customExportButton'; button.setAttribute("title", "Download Chat"); const svgIcon = ` `; button.innerHTML = svgIcon; button.style.cssText = ` -webkit-text-size-adjust: 100%; tab-size: 4; -webkit-font-smoothing: antialiased; border: 0 solid #e5e7eb; box-sizing: border-box; font-family: inherit; font-size: 100%; line-height: inherit; margin: 0; text-transform: none; -webkit-appearance: button; background-image: none; cursor: pointer; display: inline-flex; aspect-ratio: 1/1; align-items: center; justify-content: center; gap: .25rem; border-radius: .75rem; background-color: hsl(var(--color-uivory-300)/var(--tw-bg-opacity)); color: rgb(255 255 255); transition-property: background-color, color, border-color, text-decoration-color, fill, stroke; transition-timing-function: cubic-bezier(.4,0,.2,1); transition-duration: .15s; font-weight: 500; `; button.onmouseover = function() { this.style.backgroundColor = 'hsl(37, 26%, 78%)'; } button.onmouseout = function() { this.style.backgroundColor = 'hsl(var(--color-uivory-300)/var(--tw-bg-opacity))'; } button.addEventListener("click", function() { const text = getTextByClass('font-claude-message'); const blob = new Blob([text], {type: "text/plain;charset=utf-8"}); const url = URL.createObjectURL(blob); const link = document.createElement("a"); link.download = 'extracted.txt'; link.href = url; link.click(); URL.revokeObjectURL(url); }); container.appendChild(button); } const observer = new MutationObserver(addButton); observer.observe(document.body, {childList: true, subtree: true}); addButton(); })();