Skip to content

Instantly share code, notes, and snippets.

@smpanaro
Last active August 29, 2015 14:05
Show Gist options
  • Save smpanaro/7aa129af760ed64dc5fc to your computer and use it in GitHub Desktop.
Save smpanaro/7aa129af760ed64dc5fc to your computer and use it in GitHub Desktop.
A bookmarklet to download photos taken with the MoMA's audio guide.
/* get all photo urls */
var photoSpans = $("span.icon.share[data-title='My Photo']");
var urls = photoSpans.map(function() {
return $(this).attr('data-url');
});
urls = $.unique(urls);
/* add a div for results */
var resultDiv = $('<div></div>');
resultDiv.insertAfter($('header'));
function photoPageDownloaded(data, textStatus, jqXHR) {
/* display photos in page, use html5 download attribute on links */
if (textStatus != "success") {
console.log("Failed to download a photo page.");
return;
}
var response = $('<html />').html(data);
var siteRoot = location.protocol + '//' + location.host;
var imgPath = response.find('.my-path-photo').find('img').attr('src');
var fullImagePath = siteRoot + imgPath;
console.log(fullImagePath);
var imgTag = $('<img/>', {src: fullImagePath.replace("detail", "thumb")});
var aTag = $('<a href="' + fullImagePath + '" download></a>');
aTag.append(imgTag);
resultDiv.append(aTag);
}
/* download photos */
urls.each(function(idx, el) {
console.log(el);
$.get(el).done(photoPageDownloaded).fail(function(err) {console.log(err)});
});
# Install
This script is meant to be used as a bookmarklet. For best results use Chrome or Firefox (the only browsers to [support](http://caniuse.com/#feat=download) the HTML5 download attribute).
1. Go [here](http://mrcoles.com/bookmarklet/) (or to any other bookmarklet generator) and paste the JavaScript below.
2. Check the Include jQuery box.
3. Click Convert to bookmarklet.
4. Drag into your bookmarks bar.
# Usage
Navigate to the http://www.moma.org/path/... URL emailed to you after your visit and click the bookmarklet.
A series of images should appear at the top of your page. Click them to download them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment