Skip to content
This repository has been archived by the owner on Dec 26, 2022. It is now read-only.

Commit

Permalink
add max date for appointment
Browse files Browse the repository at this point in the history
  • Loading branch information
Pistashe committed Dec 8, 2021
1 parent 403dd9b commit 97cd1ee
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 18 deletions.
9 changes: 9 additions & 0 deletions browser_action/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@

<div class="panel-section-separator"></div>

<div class="panel-formElements-item">
<div>
<input type="date" name="dateMaxSearch" id="dateMax" />
<label for="dateMax">Date maximale de recherche</label>
</div>
</div>

<div class="panel-section-separator"></div>

<div class="panel-formElements-item">
<div>
<input type="radio" name="autoBook" id="disableAutoBook" checked />
Expand Down
11 changes: 11 additions & 0 deletions browser_action/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@
document.getElementById(injectionType).checked = true;
}

function displayDateMaxSearch(dateMaxSearch) {
const date = new Date(dateMaxSearch);
document.getElementById('dateMax').value = date.toISOString().split('T')[0]
}

// Preparation des données
const appStatus = new AppStatus();
const vCLStorage = new VCLocalStorage({
Expand All @@ -101,6 +106,7 @@
appStatus.onStoppedChange(displayStopStart);
appStatus.onAutoBookChange(displayAutoBook);
appStatus.onInjectionTypeChange(displayInjectionType);
appStatus.onDateMaxSearchChange(displayDateMaxSearch);

// Initialisation donnée
appStatus.init();
Expand Down Expand Up @@ -129,6 +135,10 @@
document.getElementById("thirdInjectionOnly").onclick =
appStatus.setInjectionType.bind(appStatus, "thirdInjectionOnly");


document.getElementById("dateMax").onblur =
appStatus.setDateMaxSearch.bind(appStatus, document.getElementById('dateMax'));

document.getElementById("reset").onclick = () => {
if (
!confirm(
Expand All @@ -145,5 +155,6 @@
displayStopStart(appStatus.getStopped());
displayAutoBook(appStatus.getAutoBook());
displayInjectionType(appStatus.getInjectionType());
displayDateMaxSearch(appStatus.getDateMaxSearch());
displayLocations();
})();
26 changes: 26 additions & 0 deletions commons/AppStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class AppStatus {
this.autoBook = false;
/** @type {'fullServiceInjection' | 'firstInjectionOnly' | 'secondInjectionOnly' | 'thirdInjectionOnly'} type d'injection souhaité par le user */
this.injectionType = "fullServiceInjection";
this.dateMaxSearch = new Date(2022, 1, 15);
/** @type {(string) => void} callback quand une {@link VaccineLocation} a été ajouté */
this.onLocationAddedCb = (job) => {};
/** @type {(string) => void} callback quand une {@link VaccineLocation} a été supprimée */
Expand All @@ -30,6 +31,7 @@ class AppStatus {
this.onAutoBookChangeCb = (newValue) => {};
/** @type {('fullServiceInjection' | 'firstInjectionOnly' | 'secondInjectionOnly' | 'thirdInjectionOnly') => void} callback quand injectionType change de valeur */
this.onInjectionTypeCb = (newValue) => {};
this.onDateMaxSearchCb = (newValue) => {};

this.onStorageChange = this.onStorageChange.bind(this);
browser.storage.onChanged.addListener(this.onStorageChange);
Expand All @@ -44,6 +46,7 @@ class AppStatus {
stopped: false,
autoBook: false,
injectionType: "fullServiceInjection",
dateMaxSearch: new Date(2022, 1, 15),
});

Object.keys(result.locations).forEach((url) => {
Expand All @@ -59,6 +62,8 @@ class AppStatus {

this.injectionType = result.injectionType;
this.onInjectionTypeCb(this.injectionType);
this.dateMaxSearch = result.dateMaxSearch;
this.onDateMaxSearchCb(this.dateMaxSearch);
}

getLocations() {
Expand Down Expand Up @@ -93,6 +98,10 @@ class AppStatus {
return this.injectionType;
}

getDateMaxSearch() {
return this.dateMaxSearch;
}

/**
* @param {(string) => void} cbAdd callback quand une {@link VaccineLocation} a été ajouté
* @param {(string) => void} cbDelete callback quand une {@link VaccineLocation} a été supprimée
Expand Down Expand Up @@ -123,6 +132,10 @@ class AppStatus {
this.onInjectionTypeCb = callback;
}

onDateMaxSearchChange(callback) {
this.onDateMaxSearchCb = callback;
}

start() {
this.stopped = false;
browser.storage.sync.set({ stopped: this.stopped });
Expand All @@ -149,6 +162,11 @@ class AppStatus {
browser.storage.sync.set({ injectionType: this.injectionType });
}

setDateMaxSearch(value) {
this.dateMaxSearch = new Date(value.value);
browser.storage.sync.set({ dateMaxSearch: this.dateMaxSearch });
}

/**
* Gérer le clean complet du stockage de l'application
*/
Expand All @@ -164,6 +182,8 @@ class AppStatus {
this.onAutoBookChangeCb(this.autoBook);
this.injectionType = "fullServiceInjection";
this.onInjectionTypeCb(this.injectionType);
this.dateMaxSearch = new Date(2022, 1, 15);
this.onDateMaxSearchCb(this.dateMaxSearch);
}

/**
Expand All @@ -179,6 +199,7 @@ class AppStatus {
this.onStoppedChangeCb = null;
this.onAutoBookChangeCb = null;
this.onInjectionTypeCb = null;
this.onDateMaxSearchCb = null;
}

/**
Expand Down Expand Up @@ -226,5 +247,10 @@ class AppStatus {

this.onInjectionTypeCb(this.injectionType);
}
if (change.dateMaxSearch) {
this.dateMaxSearch = change.dateMaxSearch.newValue;

this.onDateMaxSearchCb(this.dateMaxSearch);
}
}
}
46 changes: 28 additions & 18 deletions content_scripts/doctolib/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
const url = document.URL;

const MONTHS = {
janvier: 1,
fevrier: 2,
mars: 3,
avril: 4,
mai: 5,
juin: 6,
juillet: 7,
aout: 8,
septembre: 9,
octobre: 10,
novembre: 11,
decembre: 12,
'janv.': 1,
'févr.': 2,
'mars': 3,
'avr.': 4,
'mai': 5,
'juin': 6,
'juil.': 7,
'aout': 8,
'sept.': 9,
'oct.': 10,
'nov.': 11,
'déc.': 12,
};

async function waitTimeout(timeout) {
Expand Down Expand Up @@ -186,14 +186,18 @@

let running = false;
async function checkAvailability() {
const { locations, stopped, autoBook, injectionType } =
const { locations, stopped, autoBook, injectionType, dateMaxSearch } =
await browser.storage.sync.get({
locations: {},
stopped: false,
autoBook: false,
injectionType: "fullServiceInjection",
dateMaxSearch: new Date(2022, 1, 15)
});

const dateMaxSearchDate = typeof(dateMaxSearch) === 'string' ? new Date(dateMaxSearch) : dateMaxSearch;
console.log(dateMaxSearchDate)

if (stopped || !locations[url]) {
running = false;
return;
Expand Down Expand Up @@ -350,15 +354,18 @@
// jeu. 29 juil. 13:25
const parts = slot.title.match(
/([0-9]+) [\p{Letter}]+\.? ([0-9]+:[0-9]+)/gu
);
)[0].split(' ');
if (!parts) {
throw new Error(
`Impossible de cliquer sur le slot avec le titre ${slot.title}`
);
}

console.log(parts)
const year = parts[1] === 'decembre' ? 2021 : 2022;
const date = new Date(
`${MONTHS[parts[2]]} ${parts[1]} ${new Date().getFullYear()} ${
parts[3]
`${MONTHS[parts[1]]} ${parts[0]} ${year} ${
parts[2]
}`
);

Expand All @@ -367,10 +374,13 @@
tomorrow.setMinutes(59);
tomorrow.setDate(tomorrow.getDate() + 1);

if (date > tomorrow && date < new Date("2021-05-31T00:20:00"))

if (date > dateMaxSearchDate) {
const formatedDate = dateMaxSearchDate.toLocaleDateString();
throw new Error(
"Pas de créneau dispo d'ici demain soir ou après le 31 mai"
`Pas de créneau dispo d'ici demain soir ou avant le ${formatedDate}`
);
}

if (!autoBook) {
browser.runtime.sendMessage({
Expand Down

0 comments on commit 97cd1ee

Please sign in to comment.