【发布时间】:2014-03-25 11:44:12
【问题描述】:
场景: 我开发了一个 Firefox 插件。我希望我的插件能够调用 Firefox 中存在的另一个插件。
问题:
我无法弄清楚如何调用插件。在chrome中,扩展可以通过消息传递调用插件。消息传递可以用于firefox插件。如果可以,任何人都可以提供指导。
以下是代码:
这是main.js文件:
var {data} = require("sdk/self");
var pageMod = require("sdk/page-mod");
pageMod.PageMod({
include: "*",
attachTo: ["top"],
contentScriptFile: [data.url("jquery-2.1.0.js"),data.url("cwic.js"), data.url("my- script.js")]
});
这是my_script.js 文件:
//MAIN REGEX
var regex = /\+?\d{1,4}?[-.\s]?\(?\d{1,3}?\)?[-.\s]?\d{1,4}[-.\s]?\d{1,4}[-.\s]?\d{1,9}/g;
var text = $("body:first").html();
var textNodes = $("body:first").find('*').contents().filter(function(){
if(this.nodeType == 3 && regex.test(this.nodeValue) && this.parentElement.tagName !== "A"){
var anchor = document.createElement('a');
//alert(this.nodeValue.match(regex)[0]);
//anchor.setAttribute('href', this.nodeValue);
anchor.setAttribute('href', this.nodeValue.match(regex)[0]);
anchor.appendChild(document.createTextNode(this.nodeValue.match(regex)[0]));
//alert(this.nodeValue.match(regex));
if(this.nextSibling)
this.parentElement.insertBefore(anchor, this.nextSibling);
else
this.parentElement.appendChild(anchor);
this.nodeValue = this.nodeValue.replace(regex, '');
}
return this.nodeType === 3;
});
$('a').click(function() {
// When user clicks on the number it should call another plug-in to initiate communication
});
【问题讨论】:
-
@Chris:感谢您的链接。我已经了解消息传递背后的概念,但我无法弄清楚如何调用插件。由于该插件会检测网页上的电话号码,因此用户点击该号码即可提供点击通话功能。以上是我的代码
标签: plugins firefox-addon firefox-addon-sdk message-passing