Skip to content

Instantly share code, notes, and snippets.

@anapsix
Last active October 7, 2015 18:21
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 anapsix/9761705e868c38a905c8 to your computer and use it in GitHub Desktop.
Save anapsix/9761705e868c38a905c8 to your computer and use it in GitHub Desktop.
eventbrite tickets count

remaining tickets count from Eventbrite, without API key

<span style="text-align:center">
<h4 id="premsg">checking available tickets..</h4>
<p><a href="#" type="button" id="event" class="btn btn-success">get your tickets!</a></p>
</span>
// 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, 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');
}
}
});
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment