diff --git a/_locales/de/messages.json b/_locales/de/messages.json index a33f342..d109a78 100644 --- a/_locales/de/messages.json +++ b/_locales/de/messages.json @@ -35,6 +35,10 @@ "message": "Auffrischimpfung", "description": "Text der alle Auffrischimpfungen beschreibt." }, + "maxDateLabel": { + "message": "Termin finden bis zum (DD. MM. YYYY)", + "description": "Bis zu diesem Datum wird nach einem Termin gesucht" + }, "modernaVaccine": { "message": "Moderna Impfstoff", "description": "Beschreibung des Moderna Impfstoffes." diff --git a/_locales/fr/messages.json b/_locales/fr/messages.json index ba30b22..810a093 100644 --- a/_locales/fr/messages.json +++ b/_locales/fr/messages.json @@ -35,6 +35,10 @@ "message": "Troisième dose", "description": "Text qui décrit une injection de rappel au dela de la deuxième dose." }, + " maxDateLabel": { + "message": "Date maximale de recherche (MM/DD/YYYY)", + "description": "Date jusqu'à laquelle un rdv sera cherché" + }, "modernaVaccine": { "message": "Vaccin Moderna", "description": "Text qui décrit un vaccin Moderna." diff --git a/browser_action/index.html b/browser_action/index.html index 3af5c50..aa6493e 100644 --- a/browser_action/index.html +++ b/browser_action/index.html @@ -95,6 +95,17 @@
+
+
+ + +
+
+ +
+
diff --git a/browser_action/index.js b/browser_action/index.js index 5a0a21d..20e7152 100644 --- a/browser_action/index.js +++ b/browser_action/index.js @@ -104,6 +104,12 @@ document.getElementById(injectionVaccine).checked = true; } + /** @param {Date} dateMaxSearch La date maximale de recherche de rdv */ + 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({ @@ -118,6 +124,7 @@ appStatus.onAutoBookChange(displayAutoBook); appStatus.onInjectionTypeChange(displayInjectionType); appStatus.onInjectionVaccineChange(displayInjectionVaccine); + appStatus.onDateMaxSearchChange(displayDateMaxSearch); // Initialisation donnée appStatus.init(); @@ -150,6 +157,10 @@ appStatus.setInjectionVaccine.bind(appStatus, "modernaInjection"); document.getElementById("pfizerInjection").onclick = appStatus.setInjectionVaccine.bind(appStatus, "pfizerInjection"); + document.getElementById("dateMax").onblur = appStatus.setDateMaxSearch.bind( + appStatus, + document.getElementById("dateMax") + ); document.getElementById("reset").onclick = () => { if ( @@ -169,5 +180,6 @@ displayAutoBook(appStatus.getAutoBook()); displayInjectionType(appStatus.getInjectionType()); displayInjectionVaccine(appStatus.getInjectionVaccine()); + displayDateMaxSearch(appStatus.getDateMaxSearch()); displayLocations(); })(); diff --git a/commons/AppStatus.js b/commons/AppStatus.js index 06d3440..379e123 100644 --- a/commons/AppStatus.js +++ b/commons/AppStatus.js @@ -22,6 +22,12 @@ class AppStatus { this.injectionType = "fullServiceInjection"; /** @type {'modernaInjection' | 'pfizerInjection'} vaccin d'injection souhaité par le user */ this.injectionVaccine = "pfizerInjection"; + /** @type {Date} Date max de recherche de rdv (par défaut aujd + 1 mois) */ + this.dateMaxSearch = new Date( + new Date().getFullYear() + 1, + new Date().getMonth(), + new Date().getDate() + ); /** @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 */ @@ -34,6 +40,8 @@ class AppStatus { this.onInjectionTypeCb = (newValue) => {}; /** @type {'modernaInjection' | 'pfizerInjection'} callback quand injectionVaccine change de valeur */ this.onInjectionVaccineCb = (newValue) => {}; + /** @type {Date} callback quand maxDateSearch change de valeur */ + this.onDateMaxSearchCb = (newValue) => {}; this.onStorageChange = this.onStorageChange.bind(this); browser.storage.onChanged.addListener(this.onStorageChange); @@ -49,6 +57,11 @@ class AppStatus { autoBook: false, injectionType: "fullServiceInjection", injectionVaccine: "pfizerInjection", + dateMaxSearch: new Date( + new Date().getFullYear() + 1, + new Date().getMonth(), + new Date().getDate() + ), }); Object.keys(result.locations).forEach((url) => { @@ -67,6 +80,9 @@ class AppStatus { this.injectionVaccine = result.injectionVaccine; this.onInjectionVaccineCb(this.injectionVaccine); + + this.dateMaxSearch = result.dateMaxSearch; + this.onDateMaxSearchCb(this.dateMaxSearch); } getLocations() { @@ -105,6 +121,10 @@ class AppStatus { return this.injectionVaccine; } + 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 @@ -142,6 +162,13 @@ class AppStatus { this.onInjectionVaccineCb = callback; } + /** + * @param {(Date) => void} callback quand dateMaxSearch change de valeur + */ + onDateMaxSearchChange(callback) { + this.onDateMaxSearchCb = callback; + } + start() { this.stopped = false; browser.storage.sync.set({ stopped: this.stopped }); @@ -168,6 +195,14 @@ class AppStatus { browser.storage.sync.set({ injectionType: this.injectionType }); } + /** + * @param {Date} value The new dateMaxSearch value + */ + setDateMaxSearch(value) { + this.dateMaxSearch = new Date(value.value); + browser.storage.sync.set({ dateMaxSearch: this.dateMaxSearch }); + } + /** * @param {'modernaInjection' | 'pfizerInjection'} value The new injectionVaccine value */ @@ -193,6 +228,12 @@ class AppStatus { this.onInjectionTypeCb(this.injectionType); this.injectionVaccine = "pfizerInjection"; this.onInjectionTypeCb(this.injectionVaccine); + this.dateMaxSearch = new Date( + new Date().getFullYear() + 1, + new Date().getMonth(), + new Date().getDate() + ); + this.onDateMaxSearchCb(this.dateMaxSearch); } /** @@ -209,6 +250,7 @@ class AppStatus { this.onAutoBookChangeCb = null; this.onInjectionTypeCb = null; this.onInjectionVaccineCb = null; + this.onDateMaxSearchCb = null; } /** @@ -262,5 +304,10 @@ class AppStatus { this.onInjectionVaccineCb(this.injectionVaccine); } + 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 9bf02c2..9d36ecc 100644 --- a/content_scripts/doctolib/book.js +++ b/content_scripts/doctolib/book.js @@ -295,14 +295,30 @@ let running = false; async function checkAvailability() { - const { locations, stopped, autoBook, injectionType, injectionVaccine } = - await browser.storage.sync.get({ - locations: {}, - stopped: false, - autoBook: false, - injectionType: "fullServiceInjection", - injectionVaccine: "pfizerInjection", - }); + const { + locations, + stopped, + autoBook, + injectionType, + injectionVaccine, + dateMaxSearch, + } = await browser.storage.sync.get({ + locations: {}, + stopped: false, + autoBook: false, + injectionType: "fullServiceInjection", + injectionVaccine: "pfizerInjection", + dateMaxSearch: new Date( + new Date().getFullYear() + 1, + new Date().getMonth(), + new Date().getDate() + ), + }); + + const dateMaxSearchDate = + typeof dateMaxSearch === "string" + ? new Date(dateMaxSearch) + : dateMaxSearch; if (stopped || !locations[url]) { running = false; @@ -437,15 +453,12 @@ `${selectedMonth} ${selectedDay} ${selectedYear} ${selectedTime}` ); - const tomorrow = new Date(); - tomorrow.setHours(23); - 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({