-
-
Save Rovack/51e0fb558ee0fa4ce0e2cd5f0ab17cb1 to your computer and use it in GitHub Desktop.
// Note that this has some limitations, such as looking specifically for adult tickets, | |
// looking for the given days only in the nearest month that has availability, | |
// and always choosing the earliest time if several are found within the desired dates. | |
function setAdultTickets(adultTicketsWanted) { | |
const adultTicketsCount = parseInt($('.quantity-control.row > input')[0].value, 10); | |
const ticketChangeIterations = Math.abs(adultTicketsWanted - adultTicketsCount); | |
const ticketChangeButton = $(`.quantity-control.row > button.typcn-${adultTicketsCount < adultTicketsWanted ? 'plus' : 'minus'}`)[0]; | |
for (let i = 0; i < ticketChangeIterations; i++) { | |
ticketChangeButton.click(); | |
} | |
} | |
function playSound(src) { | |
return new Promise((resolve) => { | |
const audio = new Audio(src); | |
audio.onended = resolve; | |
audio.play(); | |
}); | |
} | |
function repeatHeyListen() { | |
playSound('https://www.myinstants.com/media/sounds/hey_listen.mp3') | |
.then(repeatHeyListen); | |
} | |
function waitForAvailability() { | |
return new Promise((resolve) => { | |
setTimeout(() => { | |
const availableEls = $('.calendar>.row:not(.blankLoader) .calendar-body .day.available'), isLoading = $('.calendar-modal[data-component=eventTimeModal] .modal-content > .loading-mask.hide').length === 0; | |
if (isLoading) { | |
return waitForAvailability() | |
.then((res) => resolve(res)); | |
} | |
resolve(availableEls); | |
}, 1000); | |
}); | |
} | |
function playSounds() { | |
playSound('https://www.myinstants.com/media/sounds/mlg-airhorn.mp3') | |
.then(() => playSound('https://www.myinstants.com/media/sounds/sound-9______.mp3')) | |
.then(() => playSound('https://www.myinstants.com/media/sounds/ps_1.mp3')) | |
.then(() => playSound('https://www.myinstants.com/media/sounds/wrong-answer-sound-effect.mp3')) | |
.then(() => playSound('https://www.myinstants.com/media/sounds/lalalalala.swf.mp3')) | |
.then(() => playSound('https://www.myinstants.com/media/sounds/tuturu_1.mp3')) | |
.then(() => playSound('https://www.myinstants.com/media/sounds/hallelujahshort.swf.mp3')) | |
.then(repeatHeyListen); | |
} | |
function addTicketsToBasket(dayElement) { | |
dayElement.click(); | |
setTimeout(() => waitForAvailability() | |
.then(() => { | |
$('.ui-control.button.select-time')[0].click(); | |
setTimeout(() => { | |
$('.typcn.typcn-shopping-cart.ng-binding')[0].click(); | |
}, 2000); | |
}), 2000); | |
} | |
function checkForTickets(datesWanted=[6, 7, 8], adultTicketsWanted=2, checkFrequency=15) { | |
setAdultTickets(adultTicketsWanted); | |
function check() { | |
$('.shared-calendar-button').click(); | |
waitForAvailability() | |
.then(availableEls => { | |
console.log(new Date(), 'Availability loaded. Checking for relevant dates...'); | |
for (let i = 0; i < availableEls.length; i++) { | |
const day = parseInt(availableEls[i].innerText, 10); | |
console.log('Day', day, 'is available...'); | |
if (datesWanted.includes(day)) { | |
console.log('Found tickets!!!!!'); | |
playSounds(); | |
addTicketsToBasket(availableEls[i]); | |
return; | |
} | |
} | |
console.log(`Relevant dates not yet available. Will check again in ${checkFrequency} seconds.`); | |
$('#page > div:nth-child(11) > div.modal.info-modal.w-auto-c > div > div.close').click(); | |
setTimeout(check, checkFrequency * 1000); | |
}); | |
}; | |
check(); | |
} |
Hmm, how interesting... I haven't been able to get it to happen for me, but sounds like it could be a result of the race condition mentioned here, which may become more likely once we add hour constraints.
If you could send the exact parameters you pass to checkForTicketsInMonth
, maybe I'll be able to see how it happens. Or, if you could send the lines printed above the error, so I can see what was happening that led up to it, that could help as well.
Of course, if this happens randomly only every so often, and not in some deterministic fashion, one workaround would be to just automatically ignore the error and continue. I think you might be able to achieve this by turning checkForTickets
into:
function checkForTickets(datesWanted=[6, 7, 8], adultTicketsWanted=2, checkFrequency=15, monthWanted, hourRange) {
setAdultTickets(adultTicketsWanted);
async function check() {
try {
if ($('.ui-control.button.extendSession').length != 0) {
console.log('Extending session');
$('.ui-control.button.extendSession').click();
}
$('.shared-calendar-button').click();
await waitForAvailability(monthWanted)
.then(async ({ availableEls, month }) => {
console.log(new Date(), `Availability loaded${month != null ? ` for month ${month}` : ''}. Checking for relevant dates...`);
if (monthWanted != null && month > monthWanted) {
console.log(`Month is too late (${month}). Will check again in ${checkFrequency} seconds.`);
setTimeout(check, checkFrequency * 1000);
return;
}
for (let i = 0; i < availableEls.length; i++) {
const day = parseInt($('.calendar>.row:not(.blankLoader) .calendar-body .day.available')[i].innerText, 10);
console.log('Day', day, 'is available...');
if (datesWanted.includes(day)) {
const succeeded = await addTicketsToBasket($('.calendar>.row:not(.blankLoader) .calendar-body .day.available')[i], hourRange);
if (succeeded) return;
}
}
console.log(`Relevant dates not yet available. Will check again in ${checkFrequency} seconds.`);
setTimeout(check, checkFrequency * 1000);
});
} catch (err) {
console.error('Error checking. Just gonna keep trying.', err);
setTimeout(check, checkFrequency * 1000);
}
};
check();
}
@Rovack today i tried it again and it works perfectly 👍 i dont now why it dosn‘t the last time. Thank u very much for your support
Great! Glad to hear it @Mirtel123.
Let me know how it turns out or if you run into any further issues. :)
Hello there,
Sorry for this dumb questions but really i need to ask :/
i've modified the script in which days i want to buy. (14 - 15 may) here is the script code;
// Note that this has some limitations, such as looking specifically for adult tickets,
// looking for the given days only in the nearest month that has availability,
// and always choosing the earliest time if several are found within the desired dates.
function setAdultTickets(adultTicketsWanted) {
const adultTicketsCount = parseInt($('.quantity-control.row > input')[0].value, 10);
const ticketChangeIterations = Math.abs(adultTicketsWanted - adultTicketsCount);
const ticketChangeButton = $(.quantity-control.row > button.typcn-${adultTicketsCount < adultTicketsWanted ? 'plus' : 'minus'}
)[0];
for (let i = 0; i < ticketChangeIterations; i++) {
ticketChangeButton.click();
}
}
function playSound(src) {
return new Promise((resolve) => {
const audio = new Audio(src);
audio.onended = resolve;
audio.play();
});
}
function repeatHeyListen() {
playSound('https://www.myinstants.com/media/sounds/hey_listen.mp3')
.then(repeatHeyListen);
}
function waitForAvailability() {
return new Promise((resolve) => {
setTimeout(() => {
const availableEls = $('.c-14-all.available')
if (availableEls.length === 0) {
return waitForAvailability()
.then((res) => resolve(res));
}
resolve(availableEls);
}, 1000);
});
}
function playSounds() {
playSound('https://www.myinstants.com/media/sounds/mlg-airhorn.mp3')
.then(() => playSound('https://www.myinstants.com/media/sounds/sound-9______.mp3'))
.then(() => playSound('https://www.myinstants.com/media/sounds/ps_1.mp3'))
.then(() => playSound('https://www.myinstants.com/media/sounds/wrong-answer-sound-effect.mp3'))
.then(() => playSound('https://www.myinstants.com/media/sounds/lalalalala.swf.mp3'))
.then(() => playSound('https://www.myinstants.com/media/sounds/tuturu_1.mp3'))
.then(() => playSound('https://www.myinstants.com/media/sounds/hallelujahshort.swf.mp3'))
.then(repeatHeyListen);
}
function addTicketsToBasket(dayElement) {
dayElement.click();
waitForAvailability()
.then(() => {
$('.ui-control.button.select-time')[0].click();
setTimeout(() => {
$('.typcn.typcn-shopping-cart.ng-binding')[0].click();
}, 2000);
});
}
function checkForTickets(datesWanted=[14, 15], adultTicketsWanted=2, checkFrequency=15) {
setAdultTickets(adultTicketsWanted);
function check() {
$('.shared-calendar-button').click();
waitForAvailability()
.then(availableEls => {
console.log(new Date(), 'Availability loaded. Checking for relevant dates...');
for (let i = 0; i < availableEls.length; i++) {
const day = parseInt(availableEls[i].innerText, 10);
console.log('Day', day, 'is available...');
if (datesWanted.includes(day)) {
console.log('Found tickets!!!!!');
playSounds();
addTicketsToBasket(availableEls[i]);
return;
}
}
console.log(`Relevant dates not yet available. Will check again in ${checkFrequency} seconds.`);
$('#page > div:nth-child(11) > div.modal.info-modal.w-auto-c > div > div.close').click();
setTimeout(check, checkFrequency * 1000);
});
};
check();
}
i just updated datesWanted.
here are the questions;
- when i run script, google chrome says ''undefined'' i think this is normal but i have to be sure :)
- after a while webpage popups an error ''SESSION WARNING
Your session has expired.
START OVER''
is it normal?
again sorry for disturb.
thanks for your help.
Hi @gokhanalpdogan! First of all, yes: getting "undefined" is normal. Just make sure after you run that, you also actually use checkForTickets
, as described here, because until you do nothing is actually happening. That's also actually where you're supposed to specify the dates, although the way you did it should be fine too.
That same comment also mentions, near the bottom, how to deal with these expiring sessions, by linking here where there's a solution for that.
Hope this helps, but let me know if there are any further questions or complications.
Hey @Rovack I just wanted to say a big thank you for this one. Got it up and running, took about five days straight use and I was able to get four tickets for next week.
@chfrodin That's awesome, makes me really happy to hear - thanks so much for letting me know! 😄
Hello @Rovack i just tried it and if its on a day with available timeslots it works very fine 👍 but with a error:
this is my code now and bellow you see the errors
VM233:37 Uncaught TypeError: Cannot read properties of undefined (reading 'value')
at :37:176
| (anonymous) | @ | VM233:37
| setTimeout (async) | |
| (anonymous) | @ | VM233:26
| waitForAvailability | @ | VM233:25
| addTicketsToBasket | @ | VM233:66
| await in addTicketsToBasket (async) | |
| (anonymous) | @ | VM233:124
| Promise.then (async) | |
| check | @ | VM233:111
| checkForTickets | @ | VM233:133
| checkForTicketsInMonth | @ | VM233:137
| (anonymous) | @ | VM238:1
and
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'innerText')
at :121:97
| (anonymous) | @ | VM233:121
| setTimeout (async) | |
| (anonymous) | @ | VM233:26
| waitForAvailability | @ | VM233:25
| addTicketsToBasket | @ | VM233:66
| await in addTicketsToBasket (async) | |
| (anonymous) | @ | VM233:124
| Promise.then (async) | |
| check | @ | VM233:111
| checkForTickets | @ | VM233:133
| checkForTicketsInMonth | @ | VM233:137
| (anonymous) | @ | VM238:1
it is impressive, how fast you can do this coding!
Thank you for your support and patience