【发布时间】:2014-07-24 04:22:00
【问题描述】:
我正在 Facebook 上运行一个脚本,要求我在“朋友”窗口中获取人员的 ID(这可能不是完成此特定任务的最有效方式,但因为我想知道如何一般来说,这是一个很好的例子)。
这意味着如果我的朋友数量过多,我必须向下滚动 Facebook 才能将他们添加到页面。
我添加了将页面向下滚动到页脚的逻辑,但我不知道如何强制获取 ID 的函数在内容加载后运行。
目前,我已经使用 setTimeout 几秒钟 - 显然,这不能保证在适当的时间,所以我想知道如何正确地做到这一点:
var k;
function doit(){
k = document.getElementsByClassName("_698");
var g= Array.prototype.slice.call(k);
confirm(g.length);
// the confirm is just to make sure it's working
// (if i don't use setTimeout it'll return a smaller number
// since not all the friends were included)
}
window.addEventListener("load", function(){
document.getElementById( "pageFooter" )
.scrollIntoView();setTimeout(doit,3000);
});
【问题讨论】:
标签: javascript facebook greasemonkey tampermonkey