I am developing a chrome extension that makes annotate for the selected word, and I want to take the whole context to compare it later when searching at the word.
Example:
A stack is a linear ***data structure*** that follows
the LIFO (Last–In, First–Out) principle.
That means the objects can be inserted or
removed only at one end of it, also called a top.
for now, I can store and take the selected word using this code:
chrome.contextMenus.create(
{
"id": "annotate",
"title": "Click To Add Comment 👆", /* what appears in the menu */
"contexts": ['selection'] /* to make this appear only when user selects something on page */
}
);
chrome.contextMenus.onClicked.addListener( (clickData) => {
if(clickData.menuItemId == "annotate" && clickData.selectionText)
{
var selected = clickData.selectionText
alert(selected)
}
})
here is the picture of the alert
how to select alert of the selected word
now I want to retrieve the whole paragraph or the whole context