Skip to content
This repository was archived by the owner on Feb 20, 2026. It is now read-only.

Commit 56e22b7

Browse files
MIQ Fix 29th July (#102)
* MIQ Fix 29th July * Fix scroll * Update readme
1 parent 6401210 commit 56e22b7

3 files changed

Lines changed: 42 additions & 24 deletions

File tree

MIQ-Booking-Assistance/miq-assistance.js

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// MIQ BOOKING ASSISTANCE
22

33
// CHANGE DATES TO WHAT YOU ARE LOOKING FOR
4-
let myDates = ['2021-08-5', '2021-08-10', '2021-09'];
4+
let myDates = ['2021-08', '2021-09-10'];
55

66
// DON'T CARE ABOUT A SPECIFIC DATE? SET THIS TO TRUE
77
let findAnyDate = true;
@@ -33,9 +33,8 @@ let reset = false;
3333
let checkedCount = 0;
3434
let electronWindow;
3535

36-
// Enter some dates to simulate the MIQ website having availability, e.g. '2021-10-1'
37-
// It allows three checks before the injecting the date
38-
let testDates = [];
36+
// Set to true to turn on test mode
37+
let testDates = false;
3938

4039
const service = {
4140
start: start
@@ -65,6 +64,16 @@ function start(window, ipcMain) {
6564
updateElectronStatus('status', 'A new browser window should appear. Please navigate to "Secure your allocation" page.');
6665
console.log('A new browser window should appear. Please navigate to "Secure your allocation" page.')
6766

67+
// Modify DOM before js loads to remove a no class on date item.
68+
await page.evaluateOnNewDocument((testDates) => {
69+
window.addEventListener('DOMContentLoaded', (event) => {
70+
if (testDates) {
71+
//Todo, add test dates back
72+
document.querySelectorAll('[class$="d__item"]')[65]?.children[0]?.classList?.remove('no')
73+
}
74+
});
75+
}, testDates)
76+
6877
if (step === "login") await login(page)
6978
if (!page.url().includes('MIQ-DEFAULT-EVENT/accommodation')) {
7079
await page.goto('https://allocation.miq.govt.nz/portal/dashboard');
@@ -106,7 +115,7 @@ async function login(page) {
106115
}
107116

108117
async function prepareAndCheckPage(page) {
109-
await page.waitForSelector('#accommodation-calendar', {visible: true});
118+
await page.waitForSelector('#accommodation', {visible: true});
110119

111120
if (await findAvailability(page)) {
112121
const status = "AVAILABLE! Found at: " + new Date().toLocaleString();
@@ -131,28 +140,34 @@ async function prepareAndCheckPage(page) {
131140

132141
async function findAvailability(page) {
133142
return await page.evaluate((myDates, testDates, findAnyDate, checkedCount) => {
134-
const calendarElem = document.getElementById('accommodation-calendar');
135-
const fp = calendarElem._flatpickr;
136-
if (testDates && testDates.length > 0 && checkedCount > 2) {
137-
fp.config.enable = testDates;
138-
}
139-
calendarElem.scrollIntoView();
143+
const nextElem = document.getElementById('form_next');
144+
nextElem.scrollIntoView();
145+
146+
const availableDateElements = [...document.querySelectorAll('[class$="_item"] :not(.no)')].filter(d => d.ariaLabel);
147+
const availableDates = availableDateElements.map(e => {
148+
return {
149+
elem: e,
150+
str: getDateStringFromElement(e)
151+
}
152+
});
153+
154+
console.log(availableDates);
140155

141-
const dataArrivalDates = fp?.config?.enable;
142-
if (!dataArrivalDates || typeof dataArrivalDates[0] === 'function' || dataArrivalDates.length <= 0 ){
156+
if (availableDateElements.length <= 0){
143157
return false;
144158
}
145159

146-
const availableDates = dataArrivalDates.map(d => d.toISOString().split('T')[0]);
147-
const matchingDates = availableDates.filter(d => myDates.indexOf(d) !== -1);
160+
const matchingDates = availableDates.filter(d => myDates.indexOf(d.str) !== -1);
161+
console.log(matchingDates);
148162
const myMonths = [...new Set(myDates.filter(d => d.split('-').length === 2).map(d => d.split('-')[1]))].sort();
149-
const matchingMonths = availableDates.filter(d => myMonths.indexOf(d.split('-')[1]) > -1);
163+
const matchingMonths = availableDates.filter(d => myMonths.indexOf(d.str.split('-')[1]) > -1);
164+
console.log(matchingMonths);
150165

151166
if (matchingDates.length > 0 || matchingMonths.length > 0 || (findAnyDate && availableDates[0])) {
152-
const month = (findAnyDate ? availableDates[0] : matchingDates[0] || matchingMonths[0]).split('-')[1] - 1;
153-
fp.changeMonth(month, false);
167+
const date = (findAnyDate ? availableDates[0] : matchingDates[0] || matchingMonths[0]);
168+
console.log(date.elem);
169+
date.elem.click();
154170
beep()
155-
fp.setDate(matchingDates[0] || matchingMonths[0] || availableDates[0], true);
156171
return true;
157172
}
158173

@@ -163,6 +178,13 @@ async function findAvailability(page) {
163178
snd.loop = true;
164179
snd.play();
165180
}
181+
182+
function getDateStringFromElement(e) {
183+
let i = e.innerText
184+
, n = e.parentElement.parentElement.parentElement.querySelector('[class$="m__title"]').children[0].className
185+
, s = n.split("-")[1];
186+
return n.split("-")[2] + "-" + (s < 10 ? "0" + s : s) + "-" + (i < 10 ? "0" + i : i)
187+
}
166188
}, myDates, testDates, findAnyDate, checkedCount)
167189
}
168190

MIQ-Booking-Assistance/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "miq-nz-booking-assistance",
3-
"version": "0.10.2",
3+
"version": "0.10.3",
44
"description": "A tool to help you book MIQ",
55
"main": "main.js",
66
"scripts": {

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ It seems that currently, less than 3 seconds. This might vary though.
5151
5252
This means that unfortunately, someone was quicker than you to secure the date.
5353

54-
> The alert sounds but I don't see a date selected in tha calendar.
55-
56-
Don't worry, the app will input the date without having to change the calendar UI. You can proceed to complete the reCAPTCHA and click next as soon as you hear the beep.
57-
5854
## Contributions
5955

6056
These tools are only a quick attempt to create some remedy. They are by far, not finished or perfect. Also, in case MIQ changes their website, they might break any time too.

0 commit comments

Comments
 (0)