场景: 我开发了一个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
});
http://stackoverflow.com/questions/8226042/how-to-implement-mes sage-passing-in-firefox-extension – Chris
@Chris:感谢您的链接。我已经理解了消息传递的概念,但我无法弄清楚这个插件是如何被调用的。由于附加组件检测到网页上的电话号码,因此用户点击该号码以提供点击通话功能。以上是我的代码 – logan