title: Delay execution after eventlistener is triggered
body: <p>I'm new to javascript, and have a lot of confusions...
  I'm trying to write a script in Tampermonkey which would allow to put the cursor at the end of the input area once "copy" event listener is triggered. 
  This is the site where I want to apply it: <a href="https://voicenotebook.com/#medtrdiv" rel="nofollow noreferrer">https://voicenotebook.com/#medtrdiv</a>
  The original code is:</p>
  
  <pre><code>var input = document.querySelector('#docel');
  var textarea = document.querySelector('#docel');
  var reset = function (e) {
     var len = this.value.length;
      this.setSelectionRange(len, len);
  };
  input.addEventListener('copy', reset, false);
  textarea.addEventListener('copy', reset, false);
  </code></pre>
  
  <p>The problem is that if I click copy, it doesn't copy the text, though it puts the cursor at the end. So I guess the problem is that the function executes too soon.</p>
  
  <p>I wanted to add some delay to this function, but nothing seems to work. So I think the solution would be to delay the function by 100ms once an eventlistener is triggered. 
  This is what I tried:</p>
  
  <pre><code>var input = document.querySelector('#docel');
   var textarea = document.querySelector('#docel');
       var reset = function (e) {
       var len = this.value.length;
       this.setSelectionRange(len, len);
    };
   textarea.addEventListener('copy', setTimeout(reset, 100), false);
   input.addEventListener('copy', setTimeout(reset, 100), false);
  </code></pre>
  
  <p>I know this probably doesn't make sense at all. I've tried different things also. I've researched many topics about this, but nothing works for me. Can you please help me to figure it out?
  Thank you in advance!</p>