ChatGPT Code Export Button

Adds Export button to code blocks in ChatGPT responses, prompts user to save code as file with predefined filename based on coding language detected from the code block's class name.

< Valutazione su ChatGPT Code Export Button

Recensione: Bene - lo script funziona

Living MenAutore
§
Pubblicato: 11/07/2024

Sometimes the button was inserted after the Copy code button, so I fixed it by changing the code:

// Insert "Export" button after the language label
languageLabel.parentNode.insertBefore(exportButton, languageLabel.nextSibling);

To

// Find the element containing "Copy code"
let copyCodeDiv = null;
const elements = header.querySelectorAll('.flex.items-center.relative.text-token-text-secondary.bg-token-main-surface-secondary.px-4.py-2.text-xs.font-sans.justify-between.rounded-t-md div');
elements.forEach(element => {
if (element.innerHTML.includes('Copy code')) {
copyCodeDiv = element;
}
});

// Insert "Export" button before the found element or append to header if not found
if (copyCodeDiv) {
copyCodeDiv.parentNode.insertBefore(exportButton, copyCodeDiv);
} else {
header.appendChild(exportButton);
}

§
Pubblicato: 11/07/2024
Modificato: 11/07/2024

Thanks a lot, it really fixed it!

Pubblica risposta

Accedi per pubblicare una risposta.