Javascript Chrome扩展开发Instagram加载事件

Javascript Chrome扩展开发Instagram加载事件,javascript,jquery,google-chrome,instagram,Javascript,Jquery,Google Chrome,Instagram,为了好玩,我最近开始开发一些小的Chrome扩展。我目前正在为Instagram开发一个“立即下载”扩展,它可以让你只需点击一个下载按钮,在帖子标题中输入“Get”值,就可以下载Instagram图片 正如您在下面的屏幕截图中所看到的,按钮按预期显示 但当我向下滚动到加载新帖子的位置时,按钮不会出现 我现在的问题是,如何预测加载事件,以便按钮将出现在正在加载的帖子上 到目前为止,我的jQuery看起来是这样的 jQuery(document).ready(function() {

为了好玩,我最近开始开发一些小的Chrome扩展。我目前正在为Instagram开发一个“立即下载”扩展,它可以让你只需点击一个下载按钮,在帖子标题中输入“Get”值,就可以下载Instagram图片

正如您在下面的屏幕截图中所看到的,按钮按预期显示

但当我向下滚动到加载新帖子的位置时,按钮不会出现

我现在的问题是,如何预测加载事件,以便按钮将出现在正在加载的帖子上

到目前为止,我的jQuery看起来是这样的

jQuery(document).ready(function() {
     jQuery(window).load(function() {
         var location = jQuery('._s6yvg');
         jQuery(location).each(function() {
             var image = jQuery(this).parent().find('div > div > div > div > img').attr('src');
             jQuery('<a class="get-button" href="' + image + '">Get</a>').appendTo(this);
         });
     });
});
jQuery(文档).ready(函数(){
jQuery(window).load(函数(){
var location=jQuery('.s6yvg');
jQuery(位置).each(函数(){
var image=jQuery(this).parent().find('div>div>div>div>img').attr('src');
jQuery(“”).附录(本);
});
});
});
如果您需要更多关于扩展的信息,请告诉我,我想我已经收到了最重要的书面通知。我很抱歉说了这么难听的话。我不是以英语为母语的人


提前感谢。

由于没有可供您尝试和配合的事件,您需要创建自己的“事件”。在这种情况下,它将用于加载图像时

考虑在页面上加载一组新图像时会发生什么情况。发生的一件事是文档的高度将发生变化。动态加载新内容时,文档的高度将增加。还和我在一起吗

知道了这一点,我们可以创建一个函数来检查文档的每个间隔的高度。我不打算为您编写完整的脚本,但下面的示例说明了您可以做些什么

// Your "append" method
function appendButton()
{
  var location = jQuery('._s6yvg');
  jQuery(location).each(function() {
    var image = jQuery(this).parent().find('div > div > div > div > img').attr('src');
    jQuery('<a class="get-button" href="' + image + '">Get</a>').appendTo(this);
  });
}

// This will monitor the document's height.
// When new images are loaded (thus making the document height increase),
// we will call the `appendButton` method again.
function monitorDocumentHeight()
{
  // Get the current $(document).height()

  // Compare the current height to the most recent height variable

  // If there is a difference in current_height and last_height:
    // > then the height has changed and we should
    // > call the `appendButton` method and store this height value.

  // Set an interval to run this method again and check the height (200ms)
}

jQuery(document).ready(function() {
  appendButton();             // The initial call
  monitorDocumentHeight();    // Start the interval
});
//您的“append”方法
函数appendButton()
{
var location=jQuery('.s6yvg');
jQuery(位置).each(函数(){
var image=jQuery(this).parent().find('div>div>div>div>img').attr('src');
jQuery(“”).附录(本);
});
}
//这将监视文档的高度。
//加载新图像时(从而使文档高度增加),
//我们将再次调用'appendButton'方法。
函数监视器DocumentHeight()
{
//获取当前$(文档).height()
//将当前高度与最近的高度变量进行比较
//如果当前_高度和上次_高度存在差异:
//>那么高度已经改变了,我们应该
//>调用'appendButton'方法并存储此高度值。
//设置再次运行此方法的间隔,并检查高度(200ms)
}
jQuery(文档).ready(函数(){
appendButton();//初始调用
monitorDocumentHeight();//开始间隔
});

请注意,这也会将按钮附加到具有按钮的现有图像上。您可以通过向
appendButton
方法添加一个条件来避免这种情况。

您可以绑定到新帖子出现时触发的事件吗?如果是这样的话,您可以在每次启动
loadImage
时运行脚本(例如函数名),我已经浏览了网站的几乎所有方面。我找不到触发事件的任何函数。我希望这里的一些人在这方面比我有更好的知识。谢谢!你是个救生员