diff --git a/browser_action/index.html b/browser_action/index.html
index b425005..cb77867 100644
--- a/browser_action/index.html
+++ b/browser_action/index.html
@@ -60,6 +60,15 @@
diff --git a/browser_action/index.js b/browser_action/index.js
index 3a3c940..3715f4c 100644
--- a/browser_action/index.js
+++ b/browser_action/index.js
@@ -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({
@@ -101,6 +106,7 @@
appStatus.onStoppedChange(displayStopStart);
appStatus.onAutoBookChange(displayAutoBook);
appStatus.onInjectionTypeChange(displayInjectionType);
+ appStatus.onDateMaxSearchChange(displayDateMaxSearch);
// Initialisation donnée
appStatus.init();
@@ -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(
@@ -145,5 +155,6 @@
displayStopStart(appStatus.getStopped());
displayAutoBook(appStatus.getAutoBook());
displayInjectionType(appStatus.getInjectionType());
+ displayDateMaxSearch(appStatus.getDateMaxSearch());
displayLocations();
})();
diff --git a/commons/AppStatus.js b/commons/AppStatus.js
index 7e7e0cf..df8a4d0 100644
--- a/commons/AppStatus.js
+++ b/commons/AppStatus.js
@@ -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 */
@@ -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);
@@ -44,6 +46,7 @@ class AppStatus {
stopped: false,
autoBook: false,
injectionType: "fullServiceInjection",
+ dateMaxSearch: new Date(2022, 1, 15),
});
Object.keys(result.locations).forEach((url) => {
@@ -59,6 +62,8 @@ class AppStatus {
this.injectionType = result.injectionType;
this.onInjectionTypeCb(this.injectionType);
+ this.dateMaxSearch = result.dateMaxSearch;
+ this.onDateMaxSearchCb(this.dateMaxSearch);
}
getLocations() {
@@ -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
@@ -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 });
@@ -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
*/
@@ -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);
}
/**
@@ -179,6 +199,7 @@ class AppStatus {
this.onStoppedChangeCb = null;
this.onAutoBookChangeCb = null;
this.onInjectionTypeCb = null;
+ this.onDateMaxSearchCb = null;
}
/**
@@ -226,5 +247,10 @@ class AppStatus {
this.onInjectionTypeCb(this.injectionType);
}
+ if (change.dateMaxSearch) {
+ this.dateMaxSearch = change.dateMaxSearch.newValue;
+
+ this.onDateMaxSearchCb(this.dateMaxSearch);
+ }
}
}
diff --git a/content_scripts/doctolib/book.js b/content_scripts/doctolib/book.js
index 45e7662..30b7a50 100644
--- a/content_scripts/doctolib/book.js
+++ b/content_scripts/doctolib/book.js
@@ -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) {
@@ -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;
@@ -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]
}`
);
@@ -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({