Get the selected text

JavaScript version
const getSelectedText = () => window.getSelection().toString();