I'm writing an chrome extension, and I want to pick up selected text in code sections of tech.io, like this one: https://prnt.sc/hhfkwu on https://tech.io/playgrounds/347/javascript-promises-mastering-the-asynchronous/what-is-asynchronous-in-javascript
I have this function which works pretty much on any other website, but it doesn't work correctly here, it returns empty string or some weird unicode character:
function getSelectedText() {
var text = "";
var activeEl = document.activeElement;
var activeElTagName = activeEl ? activeEl.tagName.toLowerCase() : null;
if (
(activeElTagName == "textarea") || (activeElTagName == "input" &&
/^(?:text|search|password|tel|url)$/i.test(activeEl.type)) &&
(typeof activeEl.selectionStart == "number")
) {
text = activeEl.value.slice(activeEl.selectionStart, activeEl.selectionEnd);
} else if (window.getSelection) {
text = window.getSelection().toString();
}
return text;
}
How should I alter it in order to work on this particular code section on tech.io website?