Skip to content

Commit

Permalink
poursuite migration vers lightObserver
Browse files Browse the repository at this point in the history
  • Loading branch information
Refhi committed Feb 8, 2024
1 parent 469f0a3 commit c69655a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 51 deletions.
15 changes: 9 additions & 6 deletions companionlink.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// // lien avec Weda-Helper-Companion
function sendToCompanion(urlCommand, blob = null) {
function sendToCompanion(urlCommand, blob = null, buttonToClick = null) {
chrome.storage.local.get(['portCompanion', 'apiKey'], function (result) {
const portCompanion = result.portCompanion;
const apiKey = result.apiKey;
Expand Down Expand Up @@ -36,6 +36,12 @@ function sendToCompanion(urlCommand, blob = null) {
if (!error.message.startsWith('[focus]')) {
alert(errortype + ' Impossible de joindre Weda-Helper-Companion : est-il bien paramétré et démarré ? Erreur: ' + error);
}
})
.finally(() => {
if (buttonToClick) {
buttonToClick.click();
}
console.log('finally');
});
});
}
Expand Down Expand Up @@ -90,7 +96,7 @@ function startDMPSender() {
}

// déclenchement de l'impression dans Weda-Helper-Companion
function sendPrint() {
function sendPrint(buttonToClick) {
chrome.storage.local.get('RemoveLocalCompanionPrint', function (result) {
const RemoveLocalCompanionPrint = result.RemoveLocalCompanionPrint;
if (RemoveLocalCompanionPrint !== false) {
Expand Down Expand Up @@ -133,11 +139,8 @@ function sendPrint() {
fetch(iframe.contentWindow.location.href)
.then(response => response.blob())
.then(blob => {
sendToCompanion(`print`, blob);
sendToCompanion(`print`, blob, buttonToClick);
watchForFocusLoss();
setTimeout(() => {
startDMPSender(); // nécessaire car la fermeture automatique de la fenêtre d'impression empêche l'envoi classique au DMP
}, 100); // petit délais car semble sinon empêcher la fermeture de la fenêtre de prévisualisation
})
.catch(error => {
console.error('Error:', error);
Expand Down
26 changes: 15 additions & 11 deletions content.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,20 +362,22 @@ if (window.location.href === 'https://secure.weda.fr/vitalzen/gestion.aspx') {
// // Retrait des suggestions de titre
chrome.storage.local.get('RemoveTitleSuggestions', function (result) {
function RemoveTitleSuggestions(elements) {
console.log('RemoveTitleSuggestions started');
if (elements) {
elements[0].remove();
}
setTimeout(() => {
console.log('Remove TitleSuggestions started');
if (elements[0]) {
elements[0].remove();
}
}, 400);
}
if (result.RemoveTitleSuggestions !== false) {
console.log('RemoveTitleSuggestions démarré');
// vérifie que l'on est sur une page soufrant du problème
if (window.location.href.startsWith('https://secure.weda.fr/FolderMedical/')
&& window.location.href.includes('Form.aspx')
&& !window.location.href.startsWith('https://secure.weda.fr/FolderMedical/PatientViewForm.aspx')
&& !window.location.href.startsWith('https://secure.weda.fr/FolderMedical/UpLoaderForm.aspx')) {


lightObserver('.consultation-form #DivGlossaireReponse', RemoveTitleSuggestions)
RemoveTitleSuggestions(document.querySelectorAll('#DivGlossaireReponse')); // nécessaire pour certaines pages se chargeant trop vite
lightObserver('#DivGlossaireReponse', RemoveTitleSuggestions)
}
}
});
Expand All @@ -390,7 +392,7 @@ chrome.storage.local.get('WarpButtons', function (result) {
function addIdToButton(button) {
var actions = {
'Annuler': ['Continuez sans l\'ordonnance numérique', 'Non', 'NON', 'Annuler'],
'Valider': ['Oui', 'OUI', 'Valider', 'Réessayer', 'Désactiver aujourd\'hui', 'Transmettre']
'Valider': ['Oui', 'OUI', 'Confirmer', 'Valider', 'Réessayer', 'Désactiver aujourd\'hui', 'Transmettre']
};
if (button) {
var action = Object.keys(actions).find(key => actions[key].includes(button.textContent));
Expand Down Expand Up @@ -418,18 +420,20 @@ chrome.storage.local.get('WarpButtons', function (result) {
button.textContent += raccourci;
}
}

resizeTextBox();
}

function resizeTextBox () {
function resizeTextBox () { // TODO à ne faire que si des boutons ont été modifiés
let textbox = document.querySelector('.mat-dialog-container');
if (textbox) {
let currentHeight = parseInt(window.getComputedStyle(textbox).height, 10);
if (textbox && currentHeight < 440) {
textbox.style.height = '440px';
} else {
console.log('textBox not found :-/ can\'t resize it');
}
}

resizeTextBox();

buttons.forEach(function (button) {
console.log('Bouton trouvé ! Je le redimentionne, lui ajoute un id et note le raccourcis clavier par défaut', button);
Expand Down
24 changes: 11 additions & 13 deletions keyCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,32 +89,30 @@ function push_annuler() {
function startPrinting() {
console.log('print_meds activé');
clickFirstPrinter();
waitForElement('[id^="ContentPlaceHolder1_ViewPdfDocumentUCForm1_iFrameViewFile"]', null, 5000, function (iframe) {
function whenFrameLoaded(elements) {
let iframe = elements[0];
console.log('iframe détecté:', iframe);
chrome.storage.local.get(['RemoveLocalCompanionPrint', 'postPrintBehavior'], function (result) {
if (result.RemoveLocalCompanionPrint) {
iframe.contentWindow.print();
}
else {
sendPrint();
console.log('sendPrint envoyé');
let closebutton = {
'doNothing' : null,
'closePreview' : 'ContentPlaceHolder1_ViewPdfDocumentUCForm1_ButtonCloseStay',
'returnToPatient' : 'ContentPlaceHolder1_ViewPdfDocumentUCForm1_ButtonClose',
}
setTimeout(function () {
console.log('id to look for ', closebutton[result.postPrintBehavior], 'postPrintBehavior is ', result.postPrintBehavior)
buttonToClick = document.getElementById(closebutton[result.postPrintBehavior]);
console.log('button to click', buttonToClick)
if (buttonToClick) {
console.log('clicking on element ', buttonToClick)
buttonToClick.click();
}
}, 100);

console.log('id to look for ', closebutton[result.postPrintBehavior], 'postPrintBehavior is ', result.postPrintBehavior)
let buttonToClick = document.getElementById(closebutton[result.postPrintBehavior]);
console.log('button to click', buttonToClick)

sendPrint(buttonToClick);
console.log('sendPrint envoyé');
}
});
});
}
lightObserver("#ContentPlaceHolder1_ViewPdfDocumentUCForm1_iFrameViewFile", whenFrameLoaded);
}

// // Diverses aides au clic
Expand Down
30 changes: 9 additions & 21 deletions prescription.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
let DemandeForm = window.location.href.startsWith('https://secure.weda.fr/FolderMedical/DemandeForm.aspx');
let PrescriptionForm = window.location.href.startsWith('https://secure.weda.fr/FolderMedical/PrescriptionForm.aspx');
if (PrescriptionForm) {
var isFirstCall = true;
// maintient le texte d'un type de recherche à l'autre et ajoute des boutons de recherche
chrome.storage.local.get(['keepMedSearch', 'addMedSearchButtons'], function (result) {
let keepMedSearch = result.keepMedSearch;
Expand Down Expand Up @@ -53,6 +54,7 @@ if (PrescriptionForm) {
}

function typeText(savedValue) {
console.log('typeText started');
if (savedValue !== undefined) {
console.log('typeText started with savedValue', savedValue);
var inputField = document.getElementById('ContentPlaceHolder1_BaseVidalUcForm1_TextBoxFindPack');
Expand Down Expand Up @@ -125,14 +127,17 @@ if (PrescriptionForm) {
});
}

function onDOMChange(setup = false) {
function onDOMChange() {
var panneauFav = document.getElementById('PanelBasesPosologies');
if (!panneauFav) { // sinon le panneau se ferme au DOM refresh
if (!panneauFav) {
console.log('onDOMChange started et panneau fav non présent');
if (keepMedSearch !== false) {
console.log('keepMedSearch started');
searchTextKeeper();
if (!setup) {textSorter();}
if (!isFirstCall) {
textSorter();
}
isFirstCall = false;
}
if (addMedSearchButtons !== false) {
addMedSearchButtonsFunction();
Expand All @@ -146,24 +151,7 @@ if (PrescriptionForm) {
}
}

// Obtenez une référence au champ d'entrée et au menu déroulant
var observer = new MutationObserver(function(mutationsList, observer) {
observer.disconnect();
console.log('DOM Mutation detected, restarting');
onDOMChange();
setTimeout(function() {
observer.observe(document, { childList: true, subtree: true });
}, 100);
});

// Commence à observer le document avec les configurations spécifiées
waitForElement('#ContentPlaceHolder1_BaseVidalUcForm1_DropDownListRecherche', null, 5000, function() {
onDOMChange(true);
setTimeout(function() {
console.log('page normalement complètement chargée, observer started');
observer.observe(document, { childList: true, subtree: true });
}, 1000);
});
lightObserver('#ContentPlaceHolder1_BaseVidalUcForm1_DropDownListRecherche', onDOMChange);
});


Expand Down

0 comments on commit c69655a

Please sign in to comment.