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

Commit

Permalink
smells fix & prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Pistashe committed Dec 16, 2021
1 parent 9d20287 commit d30b647
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 36 deletions.
4 changes: 4 additions & 0 deletions _locales/de/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
4 changes: 4 additions & 0 deletions _locales/fr/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
4 changes: 3 additions & 1 deletion browser_action/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@
<div class="panel-formElements-item">
<div>
<input type="date" name="dateMaxSearch" id="dateMax" />
<label for="dateMax">Date maximale de recherche (MM/JJ/YYYY)</label>
<label for="dateMax" data-i18n="dateMaxLabel"
>Date maximale de recherche (MM/JJ/YYYY)</label
>
</div>
</div>

Expand Down
8 changes: 5 additions & 3 deletions browser_action/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
/** @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]
document.getElementById("dateMax").value = date.toISOString().split("T")[0];
}

// Preparation des données
Expand Down Expand Up @@ -157,8 +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("dateMax").onblur = appStatus.setDateMaxSearch.bind(
appStatus,
document.getElementById("dateMax")
);

document.getElementById("reset").onclick = () => {
if (
Expand Down
19 changes: 15 additions & 4 deletions commons/AppStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ class AppStatus {
/** @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());
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 */
Expand Down Expand Up @@ -53,7 +57,11 @@ class AppStatus {
autoBook: false,
injectionType: "fullServiceInjection",
injectionVaccine: "pfizerInjection",
dateMaxSearch: new Date((new Date()).getFullYear()+1, (new Date()).getMonth(), (new Date()).getDate()),
dateMaxSearch: new Date(
new Date().getFullYear() + 1,
new Date().getMonth(),
new Date().getDate()
),
});

Object.keys(result.locations).forEach((url) => {
Expand Down Expand Up @@ -187,7 +195,6 @@ class AppStatus {
browser.storage.sync.set({ injectionType: this.injectionType });
}


/**
* @param {Date} value The new dateMaxSearch value
*/
Expand Down Expand Up @@ -221,7 +228,11 @@ class AppStatus {
this.onInjectionTypeCb(this.injectionType);
this.injectionVaccine = "pfizerInjection";
this.onInjectionTypeCb(this.injectionVaccine);
this.dateMaxSearch = new Date((new Date()).getFullYear(), (new Date()).getMonth()+1, (new Date()).getDate());
this.dateMaxSearch = new Date(
new Date().getFullYear() + 1,
new Date().getMonth(),
new Date().getDate()
);
this.onDateMaxSearchCb(this.dateMaxSearch);
}

Expand Down
54 changes: 26 additions & 28 deletions content_scripts/doctolib/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,6 @@
if (currentMonth > selectedMonth) return new Date().getFullYear() + 1;
return new Date().getFullYear();
}
const MONTHS = {
'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) {
await new Promise((r) => setTimeout(r, timeout));
Expand Down Expand Up @@ -309,17 +295,30 @@

let running = false;
async function checkAvailability() {
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 {
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;
const dateMaxSearchDate =
typeof dateMaxSearch === "string"
? new Date(dateMaxSearch)
: dateMaxSearch;

if (stopped || !locations[url]) {
running = false;
Expand Down Expand Up @@ -438,8 +437,6 @@
const parts = slot.title.match(
/([0-9]+)\.? ([\p{Letter}]+)\.? ([0-9]+:[0-9]+)/u
);
// /([0-9]+) [\p{Letter}]+\.? ([0-9]+:[0-9]+)/gu
// )[0].split(' ');
if (!parts) {
throw new Error(
browser.i18n.getMessage("slotDateFormatNotFound", slot.title)
Expand All @@ -453,14 +450,15 @@
const selectedTime = parts[3];

const date = new Date(
`${selectedMonth} ${selectedDay} ${selectedYear} ${selectedTime}`);
`${selectedMonth} ${selectedDay} ${selectedYear} ${selectedTime}`
);

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

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

0 comments on commit d30b647

Please sign in to comment.