文本选择和气泡叠加作为 Chrome 扩展
我正在寻找一种在 Chrome 中选择网站上的文本的方法,并根据文本选择弹出覆盖/工具提示内容。
有没有人以前做过这个或者知道如何让工具栏弹出?
非常感谢。
I am looking for a way to select text on a website in Chrome and have a overlay/tooltip pop with content depending on the text selection.
Has anyone done this before or knows from the top of their heads how to make the toolip pop-up?
Much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要做的就是监听鼠标事件:
例如,这可能会帮助您入门。需要进行更多调整,以确定您是否从下->上、右->左等(所有方向)发起选择。您可以使用以下代码作为启动:
contentscript.js
contentscript.css
manifest.json
将匹配部分更改为您想要的域注入这些内容脚本。
如果你想让它看起来像一个气泡,Nicolas Gallagher 做了一些很棒的 CSS3 demos< /a> 泡泡!
All you need to do is listen for mouse events:
For example, this might help you get started. More tweaks are needed, to figure out if you initiated the selection from down->up, right->left, etc (all directions). You can use the following code as a startup:
contentscript.js
contentscript.css
manifest.json
Change the matches portion to the domain you want to inject these content scripts.
If you want to style it to look like a bubble, Nicolas Gallagher did some awesome CSS3 demos for bubbles!
我写了一些和你问的类似的东西。我聆听用户选择文本,当有选择时,我显示了诸如“Facebook 上的注释”、“定义”等内容的链接列表。
在我开始编写它的一两天后,我发现谷歌打算在未来的版本中添加上下文菜单支持,所以直到最近(当我转换为上下文菜单时)我才触及这个。
看一下代码:
http: //code.google.com/p/select-actions/source/browse/trunk/select_actions.js?r=4
I wrote something similar to what you're asking about. I listened for the user to select text and when there was a selection, I displayed a list of links for things like "Note on Facebook", "Define", etc.
A day or two after I started to write it, I found that google was going to add context menu support in a future release so I didn't touch this until recently (when I converted to context menus).
Take a look at the code:
http://code.google.com/p/select-actions/source/browse/trunk/select_actions.js?r=4
如果没有人提供更好的答案,那么您可以看看 Google 词典 扩展程序是如何做到这一点的(它会很困难,因为它的代码被最小化了)。
If nobody provides a better answer then you might look at how Google Dictionary extension does it (it would be hard as its code is minimized).