Quickly Merge Facebook Photo Albums

Now that Timeline is out to the general public, and many of us are home for the holidays with our parents and/or off of work, a lot of Facebook users are spending time uploading and back-dating photos of their childhood, and adding locations to photos they’ve uploaded to Facebook over the past few years to fill in their Timeline’s Map tab.

If, like me, you’ve been on Facebook since 2006, you’ve probably uploaded hundreds if not thousands of photos to the site. I personally have nearly a hundred albums. Upon closer inspection, some of these are closely related – e.g. two college parties during the same quarter at Stanford. Given that I graduated over a year ago, it makes sense to put them in the same album. As such, I’ve been merging albums as part of my Facebook Photos binge.

Facebook allows you to merge albums, but to do so you have to manually select a new album from a drop-down for every single photo in your source album. If your albums have more than a dozen photos, this can be a repetitive process. Thankfully, using a single line of Javascript that borrows from Facebook’s client-side JS library, a user can select the same album from every drop-down easily. Let me show you how!

First, navigate to the album on Facebook, and click the “Edit Album” link at the top. I’m going to be merging an album of Human Mario Kart (racing tricycles down a parking garage) into a road trip album called BAWK6.

When the “Edit Album” dialog is open, click the “Edit Photos” link in the lower-left.

Here’s the tricky part. Using any “Move to:” dropdown, open the dropdown and count the number of albums up to and including the album at hand. For example, the BAWK 6 album is 21st on the list. (I told you I have a lot of albums.) The blank line is part of the list, but it has index 0 in the children array, so we can ignore it for counting purposes.

Pro tip: If you’re a programmer like me and you don’t like counting above 2, you can figure out the correct album number by trial and error – a chronological binary search of sorts. The Javascript code doesn’t submit the form, so you can use it as many times as you like on the same page.

Now, copy this Javascript code into your address bar, but replace the 123 with whatever number your album is. For example, I used “21″. Make sure the “javascript:” appears at the beginning of the address bar (Google Chrome will remove it by default immediately after pasting). The purpose of this line of code is to change the value of all of the drop-down selectors on the page. It does not read any data directly from the page, nor does it submit the form.

javascript:DOM.scry($('editphotoalbum'),'select').each(function(x){x.children[123].selected=true;})

Then, hit enter. Every single photo should now have the destination album selected in its Move To: dropdown.

The form isn’t saved yet. Once everything looks correct, scroll down and hit Save Changes:

If the form was saved successfully, your old album will be empty. Facebook will alert you to this and prompt you to delete it.

Disclaimer: Matt is a software engineer at Facebook. Any opinions and views from this post are solely those of only Matt, not Facebook. Javascript is a powerful language, so please use caution and common sense when copying Javascript into your address bar.