From c69655ac903f63c82cc00ab4c21b09b9eaa06e16 Mon Sep 17 00:00:00 2001 From: Refhi Date: Thu, 8 Feb 2024 18:17:47 +0100 Subject: [PATCH] poursuite migration vers lightObserver --- companionlink.js | 15 +++++++++------ content.js | 26 +++++++++++++++----------- keyCommands.js | 24 +++++++++++------------- prescription.js | 30 +++++++++--------------------- 4 files changed, 44 insertions(+), 51 deletions(-) diff --git a/companionlink.js b/companionlink.js index a256972..05edf3d 100644 --- a/companionlink.js +++ b/companionlink.js @@ -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; @@ -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'); }); }); } @@ -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) { @@ -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); diff --git a/content.js b/content.js index ea13d9d..1185020 100644 --- a/content.js +++ b/content.js @@ -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) } } }); @@ -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)); @@ -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); diff --git a/keyCommands.js b/keyCommands.js index 56f0967..235605b 100644 --- a/keyCommands.js +++ b/keyCommands.js @@ -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 diff --git a/prescription.js b/prescription.js index c36832f..4881901 100644 --- a/prescription.js +++ b/prescription.js @@ -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; @@ -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'); @@ -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(); @@ -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); });