Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(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
You can’t perform that action at this time.