Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created November 24, 2017 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmcw/35acf440035ea155bacbe085e29fc9ff to your computer and use it in GitHub Desktop.
Save tmcw/35acf440035ea155bacbe085e29fc9ff to your computer and use it in GitHub Desktop.
(async () => {
let id = location.pathname.split('/')[3];
let resp = await fetch(`https://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=YOUR_API_TOKEN&photo_id=${id}&format=json&nojsoncallback=1`).then(r => r.json());
let natural = resp.sizes.size.find(s => s.label === 'Medium 640');
let double = resp.sizes.size.find(s => (+s.width) >= 1280);
if (natural && double) {
return prompt('html', `<img src="${natural.source}"
srcset="${natural.source},
${natural.source} 320px,
${double.source} 2x" />`);
} else if (double) {
return prompt('html', `<img src="${double.source}" />`);
} else if (natural) {
return prompt('html', `<img src="${natural.source}" />`);
}
throw new Error(`trouble! couldn't find 1x or 2x images`);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment