function toNativePromise(jQueryPromise) {
return new Promise(function(resolve, reject) {
return jQueryPromise.done(resolve).fail(reject);
});
}
function isOnebox(msgId) {
return toNativePromise($.post('/message/' + msgId, {plain: true}))
.then(function(response) {
return /^!?https?:\/\/[^ ]+\.(?:jpg|png|gif|svn)$/.test(response);
});
}
var potentialOneboxes = [20669131, 20859254, 20859233]
Promise.all(potentialOneboxes.map(isOnebox))
.then(console.log.bind(console));