Skip to content

Instantly share code, notes, and snippets.

@jpagand
Last active December 16, 2020 13:19
Show Gist options
  • Save jpagand/bbceb1624a1bfb04db9a66eaf5df9be8 to your computer and use it in GitHub Desktop.
Save jpagand/bbceb1624a1bfb04db9a66eaf5df9be8 to your computer and use it in GitHub Desktop.
Coronaprover availability finder
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();
})();

Coronaprover availability finder

This script will help you the find an available time slot for a covid test on coronaprover.dk

Installation

This script only work on Google chrome

  1. Go to https://www.coronaprover.dk/ and bookmark it
  2. Edit the newly created bookmark and replace the url by the code in availabilityFinder.js

Usage

  1. Go to https://www.coronaprover.dk/ login and go to the booking page
  2. Click the bookmark you created during the installation
  3. A sound will play once an available slot is found and tell you the name of the testing center and the day that you quickly have to select

Disclaimer

This tool do not book a test for you and do not guarantee to find an available time slot. None of the authors, contributors or anyone else connected with this tool, can assumes responsibility or liability for your use of this tool. This tool is provided on an "as is" basis with no guarantees of completeness, accuracy or usefulness...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment