我希望在firefox上下文菜单中添加一个菜单项,该菜单仅在用户右键单击特定url时才会显示 。我有一个函数来测试网址。 我用来做这个通过订阅“popupshowing”事件:使用附加SDK的Firefox中的自定义上下文菜单?
var item = document.getElementById("custom-menu-id");
if (item) // show only for specific links
item.hidden = gContextMenu.onLink && acceptableURL(gContextMenu.linkURL);
现在我试图使用Add-on SDK来开发,但我不再有机会获得gContextMenu。 从文档这段代码不为我工作:
var cm = require("sdk/context-menu");
cm.Item({
label: "Copy name to clipboard",
context: cm.URLContext("http://scholar.google*"),
contentScript: 'self.on("context", function(node) {return true; });'
});
在这里我认为它应该可以得到类似node.URL和测试, 但它不工作。也许有人可能会建议如何从SDK访问gContextMenu,或者如何从节点或其他东西获取URL。