I today found this answer that exactly says:
30 seconds of googeling: http://mark.koli.ch/2009/09/use-javascript-and-jquery-to-get-user-selected-text.html
I flagged it as "low quality post" because I thought it should be moved into a comment, or directly deleted. To me, it is a just link answer.
The flag is marked as disputed by tight difference on the review (4 recommend deletion / 3 looks OK), but I still think it should be deleted. Am I right?