From b21aa010c2c46adda7759557a23fe38f35afe44e Mon Sep 17 00:00:00 2001 From: iw0 Date: Wed, 10 Apr 2024 23:25:34 +0200 Subject: [PATCH] more utility functions --- content_script.js | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/content_script.js b/content_script.js index 5d51e98..d2a5077 100644 --- a/content_script.js +++ b/content_script.js @@ -24,7 +24,7 @@ const settings = browser.storage.sync; const ensureSettingsProp = (prop, existCallback, noExistCallback) => { settings.get(prop).then(foundKeys => { console.log("storage returned", foundKeys); - prop in foundKeys ? existCallback(foundKeys[prop]) : noExistCallback(); + return (prop in foundKeys ? existCallback(foundKeys[prop]) : noExistCallback()); }); } @@ -53,11 +53,7 @@ function executeStage(node) { if (currentStage.match(node)) { console.log(currentStage.name, "matched: ", node); console.log(currentStage.name, currentStage.execute(node) ? "executed" : "execution failed"); - if (stages.length > 0) { - currentStage = stages.shift(); - } else { - observer.disconnect(); - } + nextStage(); } else { console.log(currentStage.name, "did not match: ", mutation); } @@ -158,6 +154,37 @@ function fillTextInput(parentNode, selector, value) { } +/** + * + * @param {MutationRecord} mut + * @param {string} testName + * @param {"open"|"close"} openOrClose + * @returns boolean + */ +const matchDropdown = (mut, testName, openOrClose) => { + let nodes; + if (openOrClose == "open") { + nodes = mut.addedNodes; + } else if (openOrClose == "close") { + nodes = mut.removedNodes; + } else { + throw new Error(`"${openOrClose}" is not a valid value for openOrClose`); + } + return mut.target.parentNode.parentNode.classList.contains(testName) && + Array.from(nodes).some( + n => n.nodeType === Node.ELEMENT_NODE && + n.classList.contains("db-web-dropdown-outer-container")) + } + +/**@param {MutationRecord} mut */ +const getDropdownList = (mut) => { + const dd = Array.from(mut.addedNodes).filter(e => e instanceof Element && e.querySelector("ul")!==null); + return dd.at(0).querySelector("ul"); +} + +/**@param {MutationRecord} mut */ +const getDropdownCloseButton = (mut) => mut.target.parentElement.parentElement.querySelector("button"); + const startClaim = { name: "startClaim", match: node => node.classList.contains("main-layout"),