问题
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:
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.
来源:https://stackoverflow.com/questions/8818995/how-to-listen-to-tweets-loaded-dynamically-in-twitter