Export Claude.Ai v1.1-miniaturized

Download the conversation with Claude; works now on small screens.

// ==UserScript==
// @name     Export Claude.Ai v1.1-miniaturized
// @description Download the conversation with Claude; works now on small screens. 
// @version  1.1-mini
// @author   TheAlanK & SAPIENT
// @grant    none
// @match    *://claude.ai/*
// @namespace https://github.com/TheAlanK
// @license MIT
// ==/UserScript==

function getTextByClass(className) {
    var elements = document.getElementsByClassName(className);
    var result = [];

    for (var i = 0; i < elements.length; i++) {
        // Clone the node to not affect the original element
        var clone = elements[i].cloneNode(true);

        // Remove all SVG and button elements
        var unwantedElements = clone.querySelectorAll('svg, button');
        for (var j = 0; j < unwantedElements.length; j++) {
            unwantedElements[j].remove();
        }

        // Add cleaned text to the result
        result.push(clone.innerText.trim());
    }

    return result.join("\n");
}


function addButton() {
    var button = document.createElement("button");
    button.innerHTML = `Export`;
    button.style.cssText = `
        position: fixed;
        bottom: 10px;
        right: 10px;
        padding: 2px 4px;
        background-color: #4CAF50; /* Green */
        border: none;
        color: white;
        text-align: center;
        text-decoration: none;
        display: inline-block;
        font-size: 11px;
        cursor: pointer;
        border-radius: 4px;
        z-index: 999;
    `;

    button.addEventListener ("click", function() {
        var text = getTextByClass('col-start-2');
        var blob = new Blob([text], {type: "text/plain;charset=utf-8"});
        var url = URL.createObjectURL(blob);

        var link = document.createElement("a");
        link.download = 'extracted.txt';
        link.href = url;
        link.click();
    });

    document.body.appendChild(button);
}

addButton();