Skip to content
TheChatArchiveThe Chat Archive
gpt-4.1-mini-2025-04-14· OpenAIAi2 WildChat-4.8M (AI2)

function copyToTextWithClipboard(text, ms, repeat)

  1. User

    function copyToTextWithClipboard(text, ms, repeat)

  2. Assistant

    Certainly! Here's an example implementation of a function named copyToTextWithClipboard that will copy the provided text to the clipboard, wait for ms milliseconds, and repeat the copying process repeat number 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!