So say you go to some place and select some text:
When you look at the DOM it's around here:
But it's actually this text: "Local embassy – For Wikipedia"
, the debugger doesn't quite get it right.
What I'm wondering is how to essentially find the set of selectors that most closely match the selected text. So in terms of highlighting, you would get this:
<b><a href="/wiki/Wikipedia:Local_Embassy" title="Wikipedia:Local Embassy">Local embassy</a></b> – For Wikipedia
Somehow it should go from this simple text selection function:
function getSelectionText() {
var text = ''
if (window.getSelection) {
text = window.getSelection().toString()
} else if (document.selection && document.selection.type != 'Control') {
text = document.selection.createRange().text
}
return text
}
(which resolves to this):
...To a function that instead returns the set of selectors that match the text, something like:
parent == '#mp-other-content li'
selectors relative to parent ==
[
'b',
'#text'
]
Wondering how to properly do this. Not wondering how to get the debugger to highlight the text, just how to get the selected text and return the selectors most closely matching it.