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
(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