Skip to content

Instantly share code, notes, and snippets.

@abou7mied
Created May 25, 2017 14:45
Show Gist options
  • Save abou7mied/9e18987031eff5731eccf58de9978e81 to your computer and use it in GitHub Desktop.
Save abou7mied/9e18987031eff5731eccf58de9978e81 to your computer and use it in GitHub Desktop.
Download the whole photos in a Facebook post
// var fbPhotosPhotoActionsItem
function getHttp(url, cb) {
let http = new XMLHttpRequest();
http.open("GET", url, true);
http.onreadystatechange = function () {
if (http.readyState === 4)
cb(null, http.responseURL);
}
http.send();
}
function remove() {
document.getElementById('results').remove();
}
function download(urls) {
console.log(urls);
console.log(arguments);
for (let link of urls) {
window.open(link, '_blank');
// console.log(link)
}
}
function getUrls(arr, res) {
let links = arr || [];
let results = res || [];
let working = false;
document.querySelector(".fbPhotoSnowliftDropdownButton._p.uiButton").click();
let interval;
interval = setInterval(() => {
if (working) {
console.log("working !");
return;
}
let loaded = document.querySelector(".uiContextualLayerPositioner:not(.hidden_elem)");
let a = loaded && loaded.querySelector("[data-action-type='download_photo'] a");
if (a) {
working = true;
console.log("a: ", a);
let link = a.href;
let index = links.indexOf(link);
console.log("index: %o", index);
if (index === -1) {
links.push(link);
let goNextButton = document.querySelector(".snowliftPager.next");
console.log("goNextButton: %o", goNextButton);
// goNextButton.click();
goNextButton.click();
getHttp(link, (err, finalLink) => {
results.push(finalLink);
getUrls(links, results);
});
} else {
// console.log(results.join("\r\n"));
let e = document.createElement('div');
e.setAttribute("id", "results");
Object.assign(e.style, {
background: "white",
position: "fixed",
height: "100%",
width: "100%",
top: 0,
left: 0,
zIndex: 555,
});
let html = document.querySelector(".userContent").innerHTML;
let linksHtml = '<textarea style="width: 100%; height: 300px">' + results.join("\n") + '</textarea>';
// linksHtml.results = results;
window.results = results;
linksHtml += `<button onclick="download(window.results)">Download Links</button>`;
linksHtml += `<button onclick="remove()">Close</button>`;
e.innerHTML = html + linksHtml;
document.body.appendChild(e);
//document.write(html+linksHtml);
//document.write(results.join("<br>"));
}
working = false;
console.log("interval cleared");
clearInterval(interval);
} else {
console.log("can't find");
}
}, 300);
}
function start() {
let container = document.querySelector("._2a2q");
let children = container.children[0].click();
let interval;
interval = setInterval(() => {
if (document.querySelector(".fbPhotoSnowliftDropdownButton._p.uiButton")) {
clearInterval(interval);
getUrls();
}
}, 300);
}
start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment