我想要一些帮助:
这是一些代码(对不起,但我非常喜欢):
var Widget = require("widget").Widget;
var tabs = require('tabs');
exports.main = function() {
data = require("self").data
var Panel = require("panel").Panel({
width:1000,
height:630,
contentURL: "http://mysite.com/news.html",
});
require("widget").Widget({
id: "News",
label: "News",
contentURL: "http://mysite.com/images/favicon.ico",
panel: Panel
});
};
答案 0 :(得分:1)
您想要将一些contentScript注入页面(http://mysite.com/news.html)并通过该脚本监视更改。当您看到所需的更改时,只需向面板发送一条消息,通知该更改的附加组件。
我将在文档中添加示例,
// this could be listening to any event happening in the page
var myScript = "window.addEventListener('click', function(event) {" +
" var t = event.target;" +
" if (t.nodeName == 'A')" +
// this self.port.emit is what sends the 'click-link' signal
// to your add-on code
" self.port.emit('click-link', t.toString());" +
"}, false);"
var panel = require("sdk/panel").Panel({
contentURL: "http://mysite.com/news.html",
// !!! use contentScriptFile, this is just for small inline stuff
contentScript: myScript
});
// this is how your add-on listens for the 'click-link' signal, but it could be any signal name you want
panel.port.on("click-link", function(url) {
// here is where you fire the "There are some news!" event in the browser
console.log(url);
});