gpt-4.1-mini-2025-04-14· OpenAI
WildChat-4.8M (AI2)
function copyToTextWithClipboard(text, ms, repeat)
- User
function copyToTextWithClipboard(text, ms, repeat)
- Assistant
Certainly! Here's an example implementation of a function named
copyToTextWithClipboardthat will copy the providedtextto the clipboard, wait formsmilliseconds, and repeat the copying processrepeatnumber of times:function copyToTextWithClipboard(text, ms, repeat) { if (!navigator.clipboard) { console.error('Clipboard API not supported'); return; } let count = 0; const copyText = () => { navigator.clipboard.writeText(text) .then(() => { console.log(`Copied: "${text}" (${count + 1}/${repeat})`); count++; if (count < repeat) { setTimeout(copyText, ms); } }) .catch(err => { console.error('Failed to copy text: ', err); }); }; copyText(); }Usage:
copyToTextWithClipboard("Hello World!", 1000, 3);This will copy
"Hello World!"to the clipboard every 1000 milliseconds (1 second), repeating 3 times.
If you want me to adjust this function to work in contexts other than browsers supporting the Clipboard API, or more features, just ask!