more utility functions

This commit is contained in:
iw0 2024-04-10 23:25:34 +02:00
parent 37a04c2155
commit b21aa010c2

View File

@ -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"),