how to listen to tweets loaded dynamically in twitter?

淺唱寂寞╮ 提交于 2020-01-05 07:52:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!