2014-03-25 122 views
1

場景: 我開發了一個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 
}); 
+0

http://stackoverflow.com/questions/8226042/how-to-implement-mes sage-passing-in-firefox-extension – Chris

+0

@Chris:感謝您的鏈接。我已經理解了消息傳遞的概念,但我無法弄清楚這個插件是如何被調用的。由於附加組件檢測到網頁上的電話號碼,因此用戶點擊該號碼以提供點擊通話功能。以上是我的代碼 – logan

回答

0

搶窗口並使用chromeWindow.gBrowser.selectedTab.linkedBrowser.contentWindow.wrappedJSObject.$

的wrappedJSObject,您可以訪問所有該窗口中的js

+0

由於我是開發插件的初學者,因此我無法理解您的意思。請您精心準備?提前致謝。 – logan

+0

我不知道如何把它放在插件SDK中,也許有人可以幫助將其轉換爲SDK。 – Noitidart