Created
June 7, 2011 23:52
-
-
Save jakemcgraw/1013487 to your computer and use it in GitHub Desktop.
Facebook Gallery Downloader
This file contains 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
// This has only been tested on Chrome | |
// A message for Facebook: I'm just automating something any user could waste an afternoon doing... | |
// 1) Open up Chrome. | |
// 2) Navigate to a Facebook friend's photo gallery. | |
// 3) Right click (Control+click on Mac) anywhere on the page and select "Inspect Element". | |
// 4) In the debugger that pops up, click on the "Console" tab. | |
// 5) Copy and paste this code into the Console window and hit "Enter" on your keyboard. | |
// 6) The page will fill up with photos, this may take a couple of minutes. | |
// 7) In the Chrome menu, click "File > Save Page As..." and select "Web Page, Complete". | |
// That's it! | |
(function(){ | |
function embedImage(url) { | |
$jq.get(url, function(html){ | |
var src = $jq("#myphoto", html).attr("src"); | |
$jq("<img/>").attr("src", src).appendTo("body") | |
}); | |
} | |
function loopEmbed(i, imageSrc) { | |
if (i > imageSrc.length) return; | |
embedImage(imageSrc[i++]); | |
window.setTimeout(function(){ | |
loopEmbed(i, imageSrc); | |
}, 500); | |
} | |
function downloadImages() { | |
var imageSrc = $jq.map($jq("a.uiMediaThumbHuge").get(), function(n){ | |
return $jq(n).attr("ajaxify"); | |
}); | |
var i = 0; | |
$jq("body").html(""); | |
loopEmbed(i, imageSrc); | |
} | |
// ripped from jQuery Bookmarklet | |
// http://www.learningjquery.com/2006/12/jquerify-bookmarklet | |
function getScript(url, success) { | |
var script = document.createElement('script'); | |
script.src = url; | |
var head = document.getElementsByTagName('head')[0], | |
done = false; | |
// Attach handlers for all browsers | |
script.onload = script.onreadystatechange = function(){ | |
if ( !done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete') ) { | |
done = true; | |
success(); | |
script.onload = script.onreadystatechange = null; | |
head.removeChild(script); | |
} | |
}; | |
head.appendChild(script); | |
} | |
var otherlib = false; | |
if (typeof $ == 'function') { | |
otherlib = true; | |
} | |
getScript( | |
'http://code.jquery.com/jquery-latest.min.js', | |
function(){ | |
if (otherlib) { | |
window.$jq = jQuery.noConflict(); | |
} | |
downloadImages(); | |
} | |
); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now in Bookmarklet form.