Created
June 9, 2019 18:22
-
-
Save tylerlwsmith/f73cc4f6dd7e1b6399dfd140427c938e to your computer and use it in GitHub Desktop.
Get all Facebook friends' names from friends page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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