nicer syntax

This commit is contained in:
iw0 2024-04-08 21:25:44 +02:00
parent c89de97523
commit 99fd412a83
2 changed files with 24 additions and 20 deletions

View File

@ -5,7 +5,7 @@ async function getAuthToken() {
while (!tok) {
storageData = window.sessionStorage.getItem("token");
dec = JSON.parse(storageData);
if (!!dec && Object.keys(dec).includes("accessToken")) {
if (!!dec && "accessToken" in dec) {
let tokInspect = dec.accessToken;
if (tokInspect && tokInspect.startsWith("eyJ")) {
tok = tokInspect;

View File

@ -15,6 +15,19 @@
let currentStage;
const settings = browser.storage.sync;
/**
*
* @param {string} prop
* @param {function.<string>} existCallback
* @param {function} noExistCallback
*/
const ensureSettingsProp = (prop, existCallback, noExistCallback) => {
settings.get(prop).then(foundKeys => {
console.log("storage returned", foundKeys);
prop in foundKeys ? existCallback(foundKeys[prop]) : noExistCallback();
});
}
const _clickEv = () => { return new Event('click', { bubbles: true }) };
/** @param {string} s */
@ -80,7 +93,7 @@ function processMutations(mutationList, observer) {
currentStage = stages.shift();
}
for (const mutation of mutationList) {
if (Object.keys(currentStage).includes('expects')) {
if ('expects' in currentStage) {
if (currentStage.expects == 'mutation') {
if (currentStage.match(mutation)) {
console.log(currentStage.name, "matched: ", mutation);
@ -244,14 +257,10 @@ const activateAppellationDropdown = {
name: "activateAppellationDropdown",
match: node => node.classList.contains("persoenlicheangaben") && hasConfiguredPersonalData,
execute: node => {
settings.get("addr__appellation").then(foundKeys => {
console.log("storage returned", foundKeys);
if (Object.keys(foundKeys).includes("addr__appellation")) {
return ensureSettingsProp("addr__appellation", () => {
const selectList = node.querySelector('.test-name-anrede.db-web-select');
selectList.querySelector('button').dispatchEvent(_clickEv());
}
});
return true;
}, () => true);
}
}
/**@type Stage */
@ -259,16 +268,13 @@ const enterAppellationAndActivateTitleDropdown = {
name: "enterAppellationAndActivateTitleDropdown",
match: node => node.classList.contains("db-web-dropdown-outer-container") && node.querySelector(".db-web-select-list") !== null,
execute: node => {
settings.get("addr__appellation").then(foundKeys => {
console.log("storage returned", foundKeys);
if (Object.keys(foundKeys).includes("addr__appellation")) {
ensureSettingsProp("addr__appellation", v => {
const selectList = $$(node, "ul");
selectList.querySelector(`[data-value=${foundKeys.addr__appellation}]`).dispatchEvent(_clickEv());
} else {
}, () => {
node.parentElement.parentElement.parentElement.querySelector("button").dispatchEvent(_clickEv());
}
$('.test-name-titel.db-web-select button').dispatchEvent(_clickEv());
});
$('.test-name-titel.db-web-select button').dispatchEvent(_clickEv());
return true;
}
}
@ -281,12 +287,10 @@ const enterTitle = {
execute: node => {
settings.get("addr__title").then(foundKeys => {
console.log("storage returned", foundKeys);
if (Object.keys(foundKeys).includes("addr__title")) {
ensureSettingsProp("addr__title", v => {
const selectList = $$(node, "ul");
selectList.querySelector(`[data-value=${foundKeys.addr__title}]`).dispatchEvent(_clickEv());
} else {
node.parentElement.parentElement.parentElement.querySelector("button").dispatchEvent(_clickEv());
}
}, () => { node.parentElement.parentElement.parentElement.querySelector("button").dispatchEvent(_clickEv()); })
});
return true;
}
@ -333,7 +337,7 @@ const enterTextPersonalData = {
"addr__placename": ".test-adresse-ort input"
}
for (const [k, v] of Object.entries(foundKeys)) {
if (Object.keys(configKey_Selector).includes(k)) {
if (k in configKey_Selector) {
//TODO WIP this only works on some fields
console.log("filling", configKey_Selector[k], "with", v);
setTimeout(() => {
@ -349,8 +353,8 @@ const enterTextPersonalData = {
continueBtn.focus();
continueBtn.dispatchEvent(_clickEv());
}, delay);
});
return true;
})
},
}