gpt-4.1-mini-2025-04-14· OpenAI
WildChat-4.8M (AI2)
function copyText(text, ms, repeat)
- User
function copyText(text, ms, repeat)
- Assistant
Certainly! Here's a JavaScript function
copyTextthat copies the providedtextto the clipboard everymsmilliseconds, repeating the actionrepeattimes:function copyText(text, ms, repeat) { let count = 0; const copyInterval = setInterval(() => { navigator.clipboard.writeText(text).then(() => { console.log(`Copied "${text}" to clipboard (${count + 1}/${repeat})`); }).catch(err => { console.error('Failed to copy text: ', err); clearInterval(copyInterval); // Stop if there's an error }); count++; if (count >= repeat) { clearInterval(copyInterval); console.log('Copying completed.'); } }, ms); }Usage example:
copyText('Hello World!', 1000, 5);This will copy "Hello World!" to the clipboard every 1 second, 5 times.
Note: This function uses the modern Clipboard API (
navigator.clipboard.writeText), which requires a secure context (HTTPS) and user interaction in most browsers to work properly.