Capture text selection in Google Docs

前端 未结 3 1516
谎友^
谎友^ 2021-01-07 22:28

I\'m writing a Chrome extension that captures the user text selection and sends the selected text to Google search.

manifest.json

{
         


        
3条回答
  •  不思量自难忘°
    2021-01-07 23:11

    You can get this from the context menu. I bet you'll be adding a context menu item anyway.

    chrome.contextMenus.create({
       id:"g-search",
       title:"Search %s",
       contexts:["selection"]
    });
    
    chrome.contextMenus.onClicked.addListener(function(sel){
       console.log(sel.selectionText);
    });
    

提交回复
热议问题