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

Commit

Permalink
feat: add vaccine injection choice moderna or pfizer (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayce45 authored Dec 8, 2021
1 parent 403dd9b commit 1b453c0
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 6 deletions.
19 changes: 19 additions & 0 deletions browser_action/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,25 @@

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

<div class="panel-formElements-item">
<div>
<input
type="radio"
name="injectionVaccine"
id="modernaInjection"
checked
/>
<label for="modernaInjection">Moderna</label>
</div>

<div>
<input type="radio" name="injectionVaccine" id="pfizerInjection" />
<label for="pfizerInjection">Pfizer-BioNTech</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
12 changes: 12 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;
}

/** @param {'modernaInjection' | 'pfizerInjection'} injectionVaccine Le vaccin d'injection souhaité par le user */
function displayInjectionVaccine(injectionVaccine) {
document.getElementById(injectionVaccine).checked = true;
}

// 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.onInjectionVaccineChange(displayInjectionVaccine);

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

document.getElementById("modernaInjection").onclick =
appStatus.setInjectionVaccine.bind(appStatus, "pfizerInjection");
document.getElementById("pfizerInjection").onclick =
appStatus.setInjectionVaccine.bind(appStatus, "pfizerInjection");

document.getElementById("reset").onclick = () => {
if (
!confirm(
Expand All @@ -145,5 +156,6 @@
displayStopStart(appStatus.getStopped());
displayAutoBook(appStatus.getAutoBook());
displayInjectionType(appStatus.getInjectionType());
displayInjectionVaccine(appStatus.getInjectionVaccine());
displayLocations();
})();
23 changes: 23 additions & 0 deletions commons/AppStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class AppStatus {
this.autoBook = false;
/** @type {'fullServiceInjection' | 'firstInjectionOnly' | 'secondInjectionOnly' | 'thirdInjectionOnly'} type d'injection souhaité par le user */
this.injectionType = "fullServiceInjection";
/** @type {'modernaInjection' | 'pfizerInjection'} vaccin d'injection souhaité par le user */
this.injectionVaccine = "modernaInjection";
/** @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 +32,8 @@ class AppStatus {
this.onAutoBookChangeCb = (newValue) => {};
/** @type {('fullServiceInjection' | 'firstInjectionOnly' | 'secondInjectionOnly' | 'thirdInjectionOnly') => void} callback quand injectionType change de valeur */
this.onInjectionTypeCb = (newValue) => {};
/** @type {'modernaInjection' | 'pfizerInjection'} callback quand injectionType change de valeur */
this.onInjectionVaccineCb = (newValue) => {};

this.onStorageChange = this.onStorageChange.bind(this);
browser.storage.onChanged.addListener(this.onStorageChange);
Expand Down Expand Up @@ -93,6 +97,10 @@ class AppStatus {
return this.injectionType;
}

getInjectionVaccine() {
return this.injectionVaccine;
}

/**
* @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 +131,13 @@ class AppStatus {
this.onInjectionTypeCb = callback;
}

/**
* @param {('modernaInjection' | 'pfizerInjection') => void} callback quand injectionVaccine change de valeur
*/
onInjectionVaccineChange(callback) {
this.onInjectionTypeCb = callback;
}

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

/**
* @param {'modernaInjection' | 'pfizerInjection'} value The new injectionVaccine value
*/
setInjectionVaccine(value) {
this.injectionVaccine = value;
browser.storage.sync.set({ injectionVaccine: this.injectionVaccine });
}

/**
* Gérer le clean complet du stockage de l'application
*/
Expand Down
27 changes: 21 additions & 6 deletions content_scripts/doctolib/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,13 @@
/**
* @param {string} text La description de la dose venant de Doctolib
* @param {'fullServiceInjection' | 'firstInjectionOnly' | 'secondInjectionOnly' | 'thirdInjectionOnly'} injectionType Le type d'injection choisi par le user
* @param {'modernaInjection' | 'pfizerInjection'} injectionVaccine Le vaccin d'injection choisi par le user
*/
function isARNmMotive(text, injectionType) {
function isARNmMotive(text, injectionType, injectionVaccine) {
return (
(text.includes("Pfizer") || text.includes("Moderna")) && // On ne veut que du Pifzer ou du Moderna, seuls ouverts à la population générale
text.includes(
injectionVaccine === "modernaInjection" ? "Moderna" : "Pfizer"
) &&
(injectionType === "fullServiceInjection"
? isfullServiceInjection(text)
: injectionType === "firstInjectionOnly"
Expand Down Expand Up @@ -186,12 +189,13 @@

let running = false;
async function checkAvailability() {
const { locations, stopped, autoBook, injectionType } =
const { locations, stopped, autoBook, injectionType, injectionVaccine } =
await browser.storage.sync.get({
locations: {},
stopped: false,
autoBook: false,
injectionType: "fullServiceInjection",
injectionVaccine: "modernaInjection",
});

if (stopped || !locations[url]) {
Expand Down Expand Up @@ -280,7 +284,11 @@
)) {
options.push($option.textContent);
if (
!isARNmMotive($option.textContent, injectionType) &&
!isARNmMotive(
$option.textContent,
injectionType,
injectionVaccine
) &&
!isGeneralPopulationMotive($option.textContent)
)
continue;
Expand Down Expand Up @@ -310,7 +318,10 @@
for (const $option of $bookingMotive.querySelectorAll("option")) {
// On ne s'occupe que de Pfizer et Moderna
// Pour le reste pas besoin de l'extension, de nombreux RDV sont disponibles
if (!isARNmMotive($option.textContent, injectionType)) continue;
if (
!isARNmMotive($option.textContent, injectionType, injectionVaccine)
)
continue;

selectOption($bookingMotive, $option);
optionFound = true;
Expand All @@ -327,7 +338,11 @@
const $bookingContent = document.getElementById("booking-content");
if (
$bookingContent === null ||
!isARNmMotive($bookingContent.textContent, injectionType)
!isARNmMotive(
$bookingContent.textContent,
injectionType,
injectionVaccine
)
)
throw new Error("Injection ARNm non disponible 2");
slot = await getAvailableSlot();
Expand Down

0 comments on commit 1b453c0

Please sign in to comment.