Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save theJohnnyBrown/cfc7b500cc3c921fda83c4cea1b59607 to your computer and use it in GitHub Desktop.

Select an option

Save theJohnnyBrown/cfc7b500cc3c921fda83c4cea1b59607 to your computer and use it in GitHub Desktop.
// Navigate to https://facebook.com/MY_PROFILE/photos_of
// Paste this code, it will download each image and click "next" then download the next one
// The delays are to avoid being blocked by facebook
// If it hits an error you can restart by calling download(300) again (or whatever number)
async function downloadImage(imageSrc) {
const image = await fetch(imageSrc);
const imageBlog = await image.blob();
const imageURL = URL.createObjectURL(imageBlog);
const link = document.createElement('a');
link.href = imageURL;
const parts = imageSrc.split("/");
link.download = parts[parts.length - 1] + ".jpg";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
function imageSrc() {
return document.querySelector('[data-visualcompletion="media-vc-image"]').src;
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function download(numberOfPhotos) {
for (let i = 0; i < numberOfPhotos; i++) {
await downloadImage(imageSrc())
await sleep(1500);
document.querySelector('[aria-label="Next photo"]').click();
await sleep(200);
}
console.log('Done');
}
NUMBER_OF_PHOTOS = 300;
download(NUMBER_OF_PHOTOS);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment