Wrote this really quickly while prototyping some social tools. Might wrap it into a Chrome extension at some point.
let friends = [];
let delay = 2000;
const createFriend = (name, link, image) => {
return {
name,
link,
image
};
}
const isLoadingFriends = () => {
return document.querySelectorAll('.img.async_saving').length === 1;
}
const getFriendsOnPage = () => {
let _friends = [];
let links = document.querySelectorAll('a');
let friend_links = [...links].filter(x => x.href.endsWith('&hc_location=friends_tab'));
for (let x = 0; x < friend_links.length - 1; x += 2) {
let name = friend_links[x + 1].innerText;
let link = friend_links[x + 1].href;
let image = friend_links[x].firstElementChild.src;
_friends.push(createFriend(name, link, image));
}
return _friends;
}
const getFriendsOnPageWithScroll = () => {
window.scrollTo(0, document.body.scrollHeight);
setTimeout(() => {
while (isLoadingFriends()) { /* do nothing */ };
let _friends = getFriendsOnPage();
if (_friends.length == friends.length) {
// All done!
console.log("Finished loading friends.");
} else {
friends = _friends;
getFriendsOnPageWithScroll();
}
}, delay);
}