加载youtube评论后添加fire fox自动调用JavaScript

加载youtube评论后添加fire fox自动调用JavaScript,javascript,html,ajax,firefox-addon,Javascript,Html,Ajax,Firefox Addon,我正在尝试在FireFox浏览器中构建附加组件。我使用了一个页面模组,所以当登陆到Youtube的特定页面时会触发一个脚本,它可以将数据传递给主脚本。但是它不能与数据注释通信,因为它是在使用ajax或其他方法加载页面之后加载的。请帮帮我! 我的例子是: main.js pageMod.PageMod({ include: "*.youtube.com", contentScriptFile: data.url("jquery-1.8.3.js"), contentScriptFile

我正在尝试在FireFox浏览器中构建附加组件。我使用了一个页面模组,所以当登陆到Youtube的特定页面时会触发一个脚本,它可以将数据传递给主脚本。但是它不能与数据注释通信,因为它是在使用ajax或其他方法加载页面之后加载的。请帮帮我! 我的例子是:

main.js

pageMod.PageMod({
  include: "*.youtube.com",
  contentScriptFile: data.url("jquery-1.8.3.js"),
  contentScriptFile: data.url("element-getter.js"),
  contentScriptWhen: "end"          
});
element-getter.js

var divs = document.getElementsByTagName("div");
for (var i = 0; i < divs.length; ++i) {
    divs[i].setAttribute("style", "border: solid red 1px;");
}
你可以在里面看到评论的内容


非常感谢。

使用setTimer并在计时器处理程序中检查DOM节点的注释。完成注释处理后停止计时器


另一种方法是从页面中侦听XMLHTTPRequests并从这里获取注释

,因为内容是在初始页面加载之后加载的,所以应该使用api。这将允许您在修改监视讨论的内容时触发回调

以下是我的一个扩展的代码段:

// create an observer instance
var observer = new page.defaultView.MutationObserver(function(mutations, obs) {
  stopTube._handleMutation(mutations, obs);
});

// configuration of the observer:
var config = { childList: true};

// pass in the target node, as well as the observer options
// Here instead of page.body, you should be using page.getElementById('watch-discussion'), otherwise you will have too many notifications. 
observer.observe(page.body, config);         

page.addEventListener('unload', function(evt) {
  // remember to stop observing when you are done
  observer.disconnect();

});

我不建议使用突变事件。我对addon有过负面的评论经验,在同样的情况下使用了这样的事件。你还有其他的想法吗?我仍然无法应用它:我建议使用setTimer。我的一个扩展使用这种方式检查谷歌搜索输出。它与动态搜索模式配合得很好