使用 Window.getSelection() 和 Selection.toString() 获取当前选定的文本。
Window.getSelection()
Selection.toString()
getSelection() 返回一个 Selection 对象,表示用户选择的文本范围或光标的当前位置。
getSelection()
Selection
const getSelectedText = window.getSelection().toString()
查看效果