Safari 扩展,直接从工具栏访问页面/内容?
是否可以直接从 (Safari) 工具栏访问网页内容?我现在可以从上下文菜单访问它,但不知道如何在工具栏上获得相同的功能。
这就是我得到的:
// injected
document.addEventListener("contextmenu", handleMessage, false);
function handleMessage(msgEvent) {
var sel = '';
sel = window.parent.getSelection()+'';
safari.self.tab.setContextMenuEventUserInfo(msgEvent, sel);
}
// global
safari.application .addEventListener("command", performCommand, false);
function performCommand(event) {
console.log('performCommand');
if (event.command == "abc") {
var query = event.userInfo;
console.log(query);
alert(query);
}
}
但是我如何直接从工具栏获取此内容?
IS it possible to access web content directly from the (Safari) toolbar? I can now access it from a contextmenu, but no idea how i get the same functionaliy to a toolbar.
This is what i got:
// injected
document.addEventListener("contextmenu", handleMessage, false);
function handleMessage(msgEvent) {
var sel = '';
sel = window.parent.getSelection()+'';
safari.self.tab.setContextMenuEventUserInfo(msgEvent, sel);
}
// global
safari.application .addEventListener("command", performCommand, false);
function performCommand(event) {
console.log('performCommand');
if (event.command == "abc") {
var query = event.userInfo;
console.log(query);
alert(query);
}
}
But how do i this content directly from the toolbar ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,基本上它的工作原理是这样的:
>捕获
OK, basically it works like this:
>
好的,很好找到了。我用消息解决了。
我在“全局”中发送一条消息,该消息由注入的脚本捕获。该函数获取选定的文本(将其放入用户信息中),并将消息发送回全局。
就是这样。
OK, well found it. I solved it with messages.
I send in 'global' a message, which is catches by the injected script. That function get the selected text (puts it in userinfo), and sends a message back to global.
Thats it.