Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var OPTIONS = {
- startTime: "2018-02-20T13:29:45",
- ticketIndex: 0,
- ticketQuantity: 1
- };
- function checkLocation() {
- if (location.href.indexOf("eventbrite") == -1)
- throw new Error("Not being run on the Eventbrite event page");
- }
- function post(path, params) {
- var form = document.createElement("form");
- form.setAttribute("method", "post");
- form.setAttribute("action", path);
- for (var key in params)
- if (params.hasOwnProperty(key)) {
- var hiddenField = document.createElement("input");
- hiddenField.setAttribute("type", "hidden");
- hiddenField.setAttribute("name", key);
- hiddenField.setAttribute("value", params[key]);
- form.appendChild(hiddenField);
- }
- document.body.appendChild(form);
- form.submit();
- }
- function findAll(needle, haystack) {
- const rx = new RegExp(needle, "g");
- const matches = [];
- while ((match = rx.exec(haystack)) !== null) {
- matches.push(match);
- }
- return matches;
- }
- function getTicket(data) {
- const ticketMatches = findAll("ticket_form_element_name\":\"([^\"]+)\"", data);
- return ticketMatches[OPTIONS.ticketIndex][1];
- }
- function isTicketAvailable(source) {
- const mediator = require('mediatorjs');
- const ticketData = mediator && mediator.get('ticketOrderOptions');
- if (ticketData && ticketData.collection) {
- const ticket = ticketData.collection[OPTIONS.ticketIndex];
- if (ticket && (ticket.status_is_sold_out || ticket.status_is_ended)) {
- throw new Error("SOLD OUT: " + ticket.status_is_sold_out + " or ENDED: " + ticket.status_is_ended);
- }
- }
- const notOnSale = findAll("\"not_on_sale\":(true|false)+", source);
- if (notOnSale[OPTIONS.ticketIndex] && notOnSale[OPTIONS.ticketIndex][1] == "true")
- return false;
- return true;
- }
- var scheduler = initScheduler();
- var running = true;
- function run() {
- checkLocation();
- $.get(location.href, (data) => {
- const ticket = getTicket(data);
- if (!ticket || !isTicketAvailable(data)) {
- console.log("Unsuccessful: " + (new Date()).toLocaleTimeString());
- if (running) setTimeout(run, 500);
- return;
- }
- const payload = {
- 'eid': $("form input[name=eid]").attr('value'),
- 'has_javascript': 1,
- [ticket]: OPTIONS.ticketQuantity
- };
- console.log(payload);
- post("https://www.eventbrite.co.uk/orderstart", payload);
- });
- }
- function stop() {
- if (!running) return "Already stopped";
- running = false;
- return "Stopped";
- }
- function initScheduler() {
- if (typeof scheduler !== 'undefined') clearTimeout(scheduler);
- return null;
- }
- $(document).ready(function() {
- checkLocation();
- const diff = Date.parse(OPTIONS.startTime) - Date.now();
- const timeToStart = Math.max(0, diff || 0);
- console.log(`Scheduled start in:` +
- `${Math.floor(timeToStart / (1000 * 60))}m ` +
- `${Math.floor(timeToStart / 1000)%60}s`);
- scheduler = setTimeout(run, timeToStart);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement