【问题标题】:Calling a plug-in via an add-on通过插件调用插件
【发布时间】: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


【解决方案1】:

抓住窗口并使用chromeWindow.gBrowser.selectedTab.linkedBrowser.contentWindow.wrappedJSObject.$

wrappedJSObject 让您可以访问该窗口中的所有 js

【讨论】:

  • 我无法理解你的意思,因为我是开发插件的初学者。你能详细说明一下吗?提前致谢。
  • 我不知道如何把它放在插件 sdk 方面,也许其他人可以帮助将它翻译成 sdk。
猜你喜欢
  • 1970-01-01
  • 2013-03-18
  • 1970-01-01
  • 1970-01-01
  • 2014-04-15
  • 2018-07-20
  • 2015-03-15
  • 2011-07-21
  • 1970-01-01
相关资源
最近更新 更多