Get the selected text

const selectedText = window.getSelection().toString();

See also