When you got a range object from selection(like `myRange=mySelection.getRangeAt(0)`), send the range to this function:
function getSelectedText(range: Range):string {
const div = document.createElement('div');
div.appendChild(range.cloneContents());
// we need get style by window.getComputedStyle(),
// so, it must be append on dom tree.
// here is <body>,or some where that user can't see.
document.body.appendChild(div);
const it = document.createNodeIterator(div);
let i;
while (i = it.nextNode()) {
// remove `user-select:none` node
if (i.nodeType === Node.ELEMENT_NODE && window.getComputedStyle(i).userSelect === 'none') i.remove();
}
const cpt: string = div.innerText;
div.remove();
return cpt;
}