You had stated you were unable to get the .select() and .focus() to function after the alert() unless you placed them in a setTimeout(). In my testing, I'm unable to duplicate that issue. In both Firefox and Chrome there was no need for the setTimeout(). In fact, the .focus() and .select() don't appear to be needed, as the text remained selected after the alert() is dismissed. How were you testing (OS, browser, etc.)?
You are probably right about not requiring .select() again
I had probably assumed that the focus would shift to the copy button/link.
Regarding the setTimeout - I am pretty sure it wasn't working without it. So I can confirm that in the evening (10 hours from now in India) and get back to you, if you want.
Hmmm... I've been testing on Chrome 62, which indicates how long I've let this go. I'm sorry, again, that I've been so busy. The textarea is selected after the "copy" is clicked (which is needed in case someone used the keyboard to select the link and activate it.
I'd appreciate your testing again. At least for my own knowledge, I'd like to be able to duplicate the problem, so I can investigate what's going on, as the setTimeout() shouldn't be needed.
@Makyen I just checked about both points: (1) if I call elem.select() or elem.focus() after alert withoutsetTimeout they do not work, and (2) the focus and text selection is lost as soon as the alert is triggered in the browser.
You can see the second point in the GIF above. I didn't record the first one as it looks identical.
@NisargShah OK. Thanks. Interesting. That's definitely not what I experience (also Win10, but Chrome 62) (and Firefox 56, 57, 58 & 52 ESR). For me the text within the textarea remains selected. Are you still on Chrome 61, or has it auto-updated at this point? I'll have to try some other things to see if I can duplicate (longer term issue, shouldn't block moving forward with this code).
Okay now I have figured out the steps to reproduce this. In the GIF you'll see that the text doesn't get selected after alert if the cv-pls menu is open. But if it is not open, the text does get copied.
As I started to make changes, I realized what causes this. The issue is interaction with the other click event handler we use, which gets called after the one for the "copy" as the event bubbles up the DOM. I had already made an associated change which prevents it from being called. Thanks for working on this.
@NisargShah It's the click handler used to hide the GUI menu when someone clicks elsewhere in the page, which is on document (hence the bubbling up). If the GUI is visible, then it calls hideMenu().
@NisargShah Until the 15th (or whenever I finish the updates needed due to the Greasemonkey update), I'll probably defer any additional PRs (mostly to make my life easier). But after that, feel free to work on what you see needs to happen.
@NisargShah No. At this point, my plan is to merge it into a different branch, make some modifications, merge the other pending PR for this script, then make the updates to roll the revision number (causing people to update) and merge into main.