|
javascript:(function() { |
|
const REQ_ID = RequisitionId; |
|
const DATES = []; |
|
const CENTERS = {}; |
|
const sleep = sleepTime => { |
|
return new Promise(resolve => { |
|
setTimeout(resolve, sleepTime); |
|
}); |
|
}; |
|
const fetchAvailability = async (date, center) => { |
|
await sleep(1000); |
|
const res = await fetch('https://www.coronaprover.dk/patient/GetAmbBookingDato', { |
|
headers: { |
|
accept: '*/*', |
|
'accept-language': 'en-US,en;q=0.9,fr-FR;q=0.8,fr;q=0.7', |
|
'cache-control': 'no-cache', |
|
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8', |
|
pragma: 'no-cache', |
|
'sec-fetch-dest': 'empty', |
|
'sec-fetch-mode': 'cors', |
|
'sec-fetch-site': 'same-origin', |
|
'x-requested-with': 'XMLHttpRequest', |
|
}, |
|
referrer: `https://www.coronaprover.dk/Patient/CreateAmbBookingSP/${REQ_ID}`, |
|
referrerPolicy: 'strict-origin-when-cross-origin', |
|
body: `reqId=${REQ_ID}&ambBookingSted=${center}&dato=${date}`, |
|
method: 'POST', |
|
mode: 'cors', |
|
credentials: 'include', |
|
}); |
|
|
|
return res; |
|
}; |
|
const isAvailable = async text => { |
|
return text && text.length && !text.includes('Ingen ledige tider denne dato'); |
|
}; |
|
const findAvailabilities = async () => { |
|
for (let index = 0; index < DATES.length; index++) { |
|
const date = DATES[index]; |
|
for (const key in CENTERS) { |
|
if (Object.prototype.hasOwnProperty.call(CENTERS, key)) { |
|
const centerName = CENTERS[key]; |
|
const centerId = key; |
|
const res = await fetchAvailability(date, centerId); |
|
const text = await res.text(); |
|
const available = await isAvailable(text); |
|
if (available) { |
|
const sound = new Audio('https://soundbible.com/mp3/service-bell_daniel_simion.mp3'); |
|
await sound.play(); |
|
alert(`Center: ${centerName} is available on: ${date}`); |
|
return; |
|
} |
|
} |
|
} |
|
} |
|
findAvailabilities(); |
|
}; |
|
|
|
const initDate = () => { |
|
const maxDay = 7; |
|
let promptDay; |
|
while (!promptDay || promptDay === 0 || promptDay > maxDay || promptDay <= -1) { |
|
promptDay = prompt(`Enter number of days (incl. today) you want to check for availability? max:${maxDay}`); |
|
promptDay = parseInt(promptDay, 10); |
|
} |
|
const now = new Date(); |
|
for (let i = 0; i < promptDay; i++) { |
|
const nextDay = new Date(now.valueOf()); |
|
nextDay.setDate(nextDay.getDate() + i); |
|
const year = nextDay.getFullYear(); |
|
const month = nextDay.getMonth() + 1; |
|
const day = nextDay.getDate(); |
|
DATES.push(`${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`); |
|
} |
|
}; |
|
|
|
const initCenters = () => { |
|
const maxCenters = 5; |
|
let promptCenters; |
|
while (!promptCenters || promptCenters === 0 || promptCenters > maxCenters || promptCenters <= -1) { |
|
promptCenters = prompt(`In how many of the closest centers you want to check for availability? max:${maxCenters}`); |
|
promptCenters = parseInt(promptCenters, 10); |
|
} |
|
for (let i = 0; i < promptCenters; i++) { |
|
const name = document.querySelector(`#steder > tbody > tr:nth-child(${i + 1})`).getAttribute('data-html'); |
|
const id = document.querySelector(`#steder > tbody > tr:nth-child(${i + 1})`).getAttribute('href'); |
|
CENTERS[id] = name; |
|
} |
|
}; |
|
const init = () => { |
|
initDate(); |
|
initCenters(); |
|
findAvailabilities(); |
|
}; |
|
|
|
init(); |
|
})(); |