开发者

Chrome extension double click on a word

开发者 https://www.devze.com 2023-01-21 07:50 出处:网络
I would like to know how to call a function once the user double-clicks on any word on the page they are开发者_如何学C visiting (from a content script). Something similar to Google Dictionary extensio

I would like to know how to call a function once the user double-clicks on any word on the page they are开发者_如何学C visiting (from a content script). Something similar to Google Dictionary extension. I have inspected the codes in the extension but it was not indented (compiled/minimized) so I've decided to ask this question here. A snippet of codes would be good. Thanks in advance :)


I suspect Google adds an EventListener to the page to register a double click, and then gets the text that was automatically selected.

http://developer.mozilla.org/en/DOM/element.addEventListener
http://developer.mozilla.org/en/DOM/window.getSelection

f=function(){
   console.log(window.getSelection().toString());
}
document.body.addEventListener('dblclick',f);
0

精彩评论

暂无评论...
验证码 换一张
取 消