Add "copy file to clipboard" feature
dmwyatt opened this issue · comments
Currently, on the results page, the user can download the text file or copy its contents to the clipboard.
Another useful function would be to copy the text file as a file to the clipboard. When the user pastes this into Claude, ChatGPT, Gemini, and probably others it ends up as an attachment rather than inserted inline.
A completely untested idea of how to do this:
function dataUriToFile(dataUri, filename) {
const byteString = atob(dataUri.split(',')[1]);
const mimeString = dataUri.split(',')[0].split(':')[1].split(';')[0];
const ab = new ArrayBuffer(byteString.length);
const ia = new Uint8Array(ab);
for (let i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
const blob = new Blob([ab], {type: mimeString});
return new File([blob], filename, {type: mimeString});
}
function copyFileToClipboard(dataUri, filename) {
const file = dataUriToFile(dataUri, filename);
navigator.clipboard.write([new ClipboardItem({'application/octet-stream': file})])
.then(() => console.log("File copied to clipboard!"))
.catch(err => console.error("Error copying file to clipboard:", err));
}
// Example usage with a data URI and filename
const dataUri = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA...';
const filename = 'example.png'; // Provide a meaningful filename here
copyFileToClipboard(dataUri, filename);