Get selected text

document.onselectionchange = () => {
  const text = document.getSelection().toString()
  console.log(text)
}