Javascript 在Firefox插件中,如何实现将脚本注入HTML页面并将消息发送回主脚本?

Javascript 在Firefox插件中,如何实现将脚本注入HTML页面并将消息发送回主脚本?,javascript,firefox,firefox-addon,Javascript,Firefox,Firefox Addon,我的附加组件专门在单个站点上工作 它注入一个contentscript并向弹出窗口(firefox术语中的面板)发送一条消息以显示 这是我的内容脚本: //this code is same for firefox as well as chrome since it is that which manipulates the page in which it is injected, so I think this is indepent of browser var table = doc

我的附加组件专门在单个站点上工作

它注入一个contentscript并向弹出窗口(firefox术语中的面板)发送一条消息以显示

这是我的内容脚本:

//this code is same for firefox as well as chrome since it is that which manipulates the page in which it is injected, so I think this is indepent of browser

var table = document.getElementsByClassName("collapse")[0];

var marks = new Array();

 for(var i=0;i<8;i++)
   marks[i] = table.children[0].children[i+1].children[5].innerHTML;

 var total=0;
 for(var i=0;i<8;i++)
   total += Number(marks[i]);

 ------------------------------------------------
//this code is different for firefox
 //code to send the data to popup 
 var fromDOM = total;
chrome.runtime.sendMessage(fromDOM);//what is the equivalent method for sending a message to popup(panel)?
//code to load the contentscript into the page 
chrome.tabs.executeScript({"file": "contentscript.js"});    
//equivalent firefox code??***
-----------------------------------------------------------------
    var total= 0,percentage = 0;

chrome.runtime.onMessage.addListener(function(response){
total = response;***
//Getting response sent from contentscript, how can I do the same in firefox?
percentage = total/7.25; 


document.getElementById("total").innerHTML = total;
document.getElementById("percentage").innerHTML = percentage.toFixed(2)+" %";


});
提到的一些ChromeAPI方法的具体firefox方法是什么

如果有人能帮我,我会很高兴的。
感谢来自chrome的

您可能需要插件sdk。对于panel:然后只要在contentScript中发出show函数,当你获得站点的页面负载时,请参见这里的page mod:Thank@Noitidart为你的回答,这确实帮助了我,给了我一个方向。但将面板连接到按钮似乎只在Firefox30之后才起作用,所以我应该使用小部件还是面板。谢谢我没有任何SDK演示:(我们必须等待其他回复。Bootrap需要一些理解。是的。我可以为您制作此演示并将其保存在我的教程中,但我正忙于为Australis竞赛制作一个插件。我可以在完成插件后为您编写此演示(我应该在大约2周内完成)使用带有面板的按钮的widget。试试widget。为了澄清,按钮的附加是从Australis(UI改造)开始的,所以FF30+,但在此之前,widget与面板执行相同的功能。widget在Australis中不工作,被“按钮”取代
//code to load the contentscript into the page 
chrome.tabs.executeScript({"file": "contentscript.js"});    
//equivalent firefox code??***
-----------------------------------------------------------------
    var total= 0,percentage = 0;

chrome.runtime.onMessage.addListener(function(response){
total = response;***
//Getting response sent from contentscript, how can I do the same in firefox?
percentage = total/7.25; 


document.getElementById("total").innerHTML = total;
document.getElementById("percentage").innerHTML = percentage.toFixed(2)+" %";


});