From 62a08c91667b85a6244d0fcab47843a284293dd1 Mon Sep 17 00:00:00 2001 From: iw0 Date: Tue, 4 Jun 2024 21:36:38 +0200 Subject: [PATCH] move execution into function --- content_script.js | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/content_script.js b/content_script.js index 636dc8f..755c915 100644 --- a/content_script.js +++ b/content_script.js @@ -62,21 +62,28 @@ const personalDataConfigKeys = [ "addr__email", "addr__street", "addr__postcode", "addr__placename"]; const bankDetailConfigKeys = ["pymt__iban", "pymt__bic"]; +const genericExecute = (stage, o) => { + const success = stage.execute(o); + Promise.resolve(success).then(result => { + if (result === true) { + console.info(currentStage.name, "executed successfully"); + } else { + console.error(currentStage.name, "failed"); + } + nextStage(); + }, failReason => { + console.error(currentStage.name, "failed: ", failReason); + }); +} + + /** * @param {Node} n */ function processSingleAddedNode(n) { if (currentStage.match(n)) { console.info(currentStage.name, "matched: ", n); - const success = currentStage.execute(n); - Promise.resolve(success).then((result => { - if (result === true) { - console.info(currentStage.name, "executed successfully"); - } else { - console.error(currentStage.name, "failed"); - } - nextStage(); - })); + genericExecute(currentStage, n); } else { console.debug(currentStage.name, "did not match: ", n); @@ -110,13 +117,7 @@ function processMutations(mutationList, observer) { if (currentStage.expects == 'mutation') { if (currentStage.match(mutation)) { console.info(currentStage.name, "matched: ", mutation); - let success = currentStage.execute(mutation); - if (success){ - console.info(currentStage.name, "executed successfully"); - } else { - console.error(currentStage.name, "failed"); - } - nextStage(); + genericExecute(currentStage, mutation); } else { console.debug(currentStage.name, "did not match: ", mutation); } @@ -180,7 +181,7 @@ function fillTextInput(parentNode, selector, value) { /** * - * @param {MutationRecord} mut + * @param {MutationRecord} mut * @param {string} testName * @param {"open"|"close"} openOrClose * @returns boolean