Skip to content

Instantly share code, notes, and snippets.

@tylerlwsmith
Created June 9, 2019 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylerlwsmith/f73cc4f6dd7e1b6399dfd140427c938e to your computer and use it in GitHub Desktop.
Save tylerlwsmith/f73cc4f6dd7e1b6399dfd140427c938e to your computer and use it in GitHub Desktop.
Get all Facebook friends' names from friends page
scrollToBottomOfPage = {
// Configurable properties
interval: 1000,
allowedIntervalsInSamePosition: 10,
// Non-configurable properties
intervalContainer: null,
currentPosition: 0,
intervalsInSamePosition: 0,
callbackWhenFinished: function(){
console.log('No callback set on finish')
},
scroll: function(){
let currentPosition = document.body.offsetHeight;
window.scrollTo(0, currentPosition);
if (currentPosition == this.currentPosition){
this.intervalsInSamePosition++;
if(this.intervalsInSamePosition >= this.allowedIntervalsInSamePosition){
console.log('stop');
this.stop();
this.callbackWhenFinished();
}
} else {
this.currentPosition = currentPosition;
this.intervalsInSamePosition = 0;
}
console.log('Intervals in same position: ' + this.intervalsInSamePosition + ' out of ' + this.allowedIntervalsInSamePosition);
},
start: function(callbackWhenFinished = null){
if (callbackWhenFinished) {
this.callbackWhenFinished = callbackWhenFinished
}
intervalContainer = setInterval(this.scroll.bind(this), this.interval);
},
stop: function(){
clearInterval(intervalContainer);
}
}
function getFriends(){
let friends = document.querySelectorAll('.uiProfileBlockContent .fsl.fwb.fcb a');
let friendNames = [];
friends.forEach(function (element){
friendNames.push(element.innerHTML)
});
console.log(friendNames.sort().join('\n'));
}
scrollToBottomOfPage.start(getFriends);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment