how to listen to tweets loaded dynamically in twit

2019-08-05 09:11发布

I am trying to add an image to every tweet in my timeline by building a chrome plugin. Currently the plugin works for tweets loaded when the page is refreshed. But how do i extend the plugin to include the "new tweets" and the "past tweets" which are dynamically loaded in my timeline?

1条回答
闹够了就滚
2楼-- · 2019-08-05 09:58

You can check for them periodically using setInterval() or search if there is any event that is called by Twitter script after pulling tweets.

There are also some events that look relevant, but I did not test them, eg.:

  • DOMNodeInserted - fires when a node has been added as a child of another node,

EDIT:

I see that Twitter uses jQuery. jQuery in turn has jQuery.ajaxPrefilter() function that is called before AJAX request is being made. You can probably use it to bind your event to the jqXHR object (which is XMLHttpRequest object, I suppose) and do different things depending on what it will return. See the documentation of jQuery.ajaxPrefilter() and the documentation on XMLHttpRequest.

查看更多
登录 后发表回答