more utility functions
This commit is contained in:
parent
37a04c2155
commit
b21aa010c2
@ -24,7 +24,7 @@ const settings = browser.storage.sync;
|
|||||||
const ensureSettingsProp = (prop, existCallback, noExistCallback) => {
|
const ensureSettingsProp = (prop, existCallback, noExistCallback) => {
|
||||||
settings.get(prop).then(foundKeys => {
|
settings.get(prop).then(foundKeys => {
|
||||||
console.log("storage returned", 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)) {
|
if (currentStage.match(node)) {
|
||||||
console.log(currentStage.name, "matched: ", node);
|
console.log(currentStage.name, "matched: ", node);
|
||||||
console.log(currentStage.name, currentStage.execute(node) ? "executed" : "execution failed");
|
console.log(currentStage.name, currentStage.execute(node) ? "executed" : "execution failed");
|
||||||
if (stages.length > 0) {
|
nextStage();
|
||||||
currentStage = stages.shift();
|
|
||||||
} else {
|
|
||||||
observer.disconnect();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
console.log(currentStage.name, "did not match: ", mutation);
|
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 = {
|
const startClaim = {
|
||||||
name: "startClaim",
|
name: "startClaim",
|
||||||
match: node => node.classList.contains("main-layout"),
|
match: node => node.classList.contains("main-layout"),
|
||||||
|
Loading…
Reference in New Issue
Block a user