// eventPage
var eventPage = 'https://www.eventbrite.com/e/extreme-beer-fest-2016-tickets-17643961564';
// set button link URL to eventPage
$("#event")[0].href = eventPage;
// regex to grab tickets remaining element
var reg = /(\d+)(\sTickets)/;
// default to this ticket amount, when event is doesn't report ticket counts
var tr = 'no';
// do the thing
$.get('http://crossorigin.me/' + eventPage)
.success(function(data) {
text = $('td[itemprop="inventoryLevel"]', data).text();
waitList = /Add to Waitlist/.exec(data);
console.log('Waitlist: ' + waitList);
try {
tr = reg.exec(text)[1];
$("#event").html(tr + ' tickets remaining');
$("#premsg").html('hooray!');
} catch (err) {
if (waitList) {
$("#premsg").html('no tickets available :`(');
$("#event").html('get on waiting list');
}
}
})
.error(function(jqXHR, textStatus, errorThrown) {
$("#premsg").html('failed to get live ticket count');
});