简体   繁体   English

我如何为 Chrome 扩展编写 JavaScript 代码,向下滚动到最后(我想获得所有 Facebook 好友列表)

[英]How I can write the JavaScript code for Chrome extension that scroll down till end (I want to get all Facebook friends list)

I'm working on a Chrome extension and I have to read all my friends on Facebook without API. I have used window.scrollTo(0, document.body.scrollHeight);我正在开发 Chrome 扩展程序,我必须阅读 Facebook 上的所有朋友,而无需 API。我使用了 window.scrollTo(0, document.body.scrollHeight); in while loop with sleep function in Javascript but sleep pause all the javascript execution and Facebook data not load well.在 Javascript 中睡眠 function 的 while 循环中,但睡眠暂停所有 javascript 执行和 Facebook 数据加载不正确。

friend list link https://web.facebook.com/profile-id/friends_all好友列表链接https://web.facebook.com/profile-id/friends_all

You can implement it this way- scroll, wait for the more content to load, compare scroll heights, and repeat if more content was loaded.您可以这样实现它——滚动,等待更多内容加载,比较滚动高度,如果加载更多内容则重复。 Here's the implementation with async/await and setTimeout sleep duration:这是带有 async/await 和 setTimeout 睡眠持续时间的实现:

(async (sleepDuration = 2000) => {
  let previousHeight;
  let newHeight = document.body.scrollHeight;
  do {
    previousHeight = newHeight;
    window.scrollTo(0, previousHeight);
    await new Promise(resolve => setTimeout(resolve, sleepDuration));
    newHeight = document.body.scrollHeight;
  } while (previousHeight !== newHeight);
})();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在jsp文件中使用Javascript从Facebook API获取“获取朋友”列表 - How can I get Get friends list from Facebook API using Javascript in a jsp file 如何使用 JavaScript 获取 Facebook 好友列表 - How to get facebook friends list using JavaScript 如何使用他们的API获取Facebook上的共同朋友列表? - How do I get the list of mutual friends on Facebook using their API? 如何使用 javascript 获取已安装的 chrome 扩展列表 - How can I get installed chrome extensions list with javascript 如何获得此代码以仅平滑滚动所需的元素? - How can I get this code to only smooth scroll only the elements I want? 我想编写javascript代码以获得额外的倒计时 - I want to write javascript code to get a addition countdown 如何在onClick函数中编写JavaScript代码以及我也想调用另一个函数 - How can I write JavaScript code in onClick function as well as I also want to call another function 如何在新的 Facebook 活动中邀请 UI 中的所有朋友 select? - How can I select all friends in new Facebook events invite UI? 如何通过JavaScript检测指定元素的滚动结束? - How can I detect scroll end of the specified element by JavaScript? 如何使用Chrome Extension API获取网页的所有HTTP请求 - How can I get all HTTP requests of a web page by using Chrome Extension API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM