检测时,新的鸣叫正在使用jQuery装? [英] Detect when new tweets are loaded using jQuery?
问题描述
您知道当您滚动到配置文件页面的底部(我说的是用户的个人页面,而不是时间表),新的鸣叫会自动加载。我正在写一个UserScript中,我想执行的函数每次这些新的鸣叫加载时间。
You know how when you scroll to the bottom of a profile page (I'm talking about a user's personal page, not the timeline), new tweets are loaded automatically. I'm writing a UserScript in which I want to execute a function every time those new tweets are loaded.
但我不能想出一个办法来检测这种新的鸣叫加载事件。我认为它的一个AJAX请求,对不对?所以,我想下面的两个功能,但无济于事。
But I can't figure out a way to detect this new tweets loaded event. I assume its an AJAX request, right? So I tried the below two functions but to no avail.
$(document).ajaxComplete(function() {
alert("Complete! New tweets loaded!");
});
$(document).ajaxSuccess(function() {
alert("Success! New tweets loaded!");
});
下面是我到目前为止所。此网页时首先加载工作。但是,当你向下滚动,不影响加载的tweet。
Here's what I have so far. This works when the page is loaded at first. But it doesn't affect the tweets loaded after you scroll down.
// ==UserScript==
// @name CoolScript
// @include https://twitter.com/IJNanayakkara
// @include https://twitter.com/IJNanayakkara/status/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @version 1.0
// @license GPL v3 or any later version (http://www.gnu.org/copyleft/gpl.html)
// @grant GM_addStyle
// ==/UserScript==
$.each($('p.js-tweet-text'), function() {
$(this).prepend("Brought to you by ");
});
我如何能够检测到来自jQuery的加载新的鸣叫?
How can I detect loading new tweets from jQuery?
编辑: 我注意到另一个问题。当你浏览网页的脚本不运行。其实,我刷新页面。我搜索发现这个答案。我导入的.js文件的脚本,但我不知道哪一个元素我实际上应该等待。
I noticed another issue. The script doesn't run when you navigate to the page. I actually have to refresh the page. I searched and found this answer. I imported that .js file to the script but I don't know which element I should actually wait for.
我怎样才能使无需人工清爽的脚本运行?
How can I make the script run without manual refreshing?
推荐答案
如果,你的code是这样的:
If, your code like this:
$.each($('p.js-tweet-text'), function() {
$(this).prepend("Brought to you by ");
});
适用于网页的静态位,或者在命令控制台,然后将其转化为这个 waitForKeyElements
code:
waitForKeyElements ("p.js-tweet-text", prependToTweet);
function prependToTweet (jNode) {
jNode.prepend("Brought to you by ");
}
简单:选择保持不变,而每个()
code端口直接,除了 $(本)
是 jNode
。
Simple: The selector stays the same, and the .each()
code ports directly, except that $(this)
is replaced by jNode
.
waitForKeyElements
自动处理AJAXed元素(适用于滚动下来,而不需要刷新)。
waitForKeyElements
handles the AJAXed elements automatically (works on scroll-down and without needing refresh).
这篇关于检测时,新的鸣叫正在使用jQuery装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!