nicer syntax
This commit is contained in:
parent
c89de97523
commit
99fd412a83
@ -5,7 +5,7 @@ async function getAuthToken() {
|
|||||||
while (!tok) {
|
while (!tok) {
|
||||||
storageData = window.sessionStorage.getItem("token");
|
storageData = window.sessionStorage.getItem("token");
|
||||||
dec = JSON.parse(storageData);
|
dec = JSON.parse(storageData);
|
||||||
if (!!dec && Object.keys(dec).includes("accessToken")) {
|
if (!!dec && "accessToken" in dec) {
|
||||||
let tokInspect = dec.accessToken;
|
let tokInspect = dec.accessToken;
|
||||||
if (tokInspect && tokInspect.startsWith("eyJ")) {
|
if (tokInspect && tokInspect.startsWith("eyJ")) {
|
||||||
tok = tokInspect;
|
tok = tokInspect;
|
||||||
|
@ -15,6 +15,19 @@
|
|||||||
let currentStage;
|
let currentStage;
|
||||||
const settings = browser.storage.sync;
|
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 }) };
|
const _clickEv = () => { return new Event('click', { bubbles: true }) };
|
||||||
/** @param {string} s */
|
/** @param {string} s */
|
||||||
@ -80,7 +93,7 @@ function processMutations(mutationList, observer) {
|
|||||||
currentStage = stages.shift();
|
currentStage = stages.shift();
|
||||||
}
|
}
|
||||||
for (const mutation of mutationList) {
|
for (const mutation of mutationList) {
|
||||||
if (Object.keys(currentStage).includes('expects')) {
|
if ('expects' in currentStage) {
|
||||||
if (currentStage.expects == 'mutation') {
|
if (currentStage.expects == 'mutation') {
|
||||||
if (currentStage.match(mutation)) {
|
if (currentStage.match(mutation)) {
|
||||||
console.log(currentStage.name, "matched: ", mutation);
|
console.log(currentStage.name, "matched: ", mutation);
|
||||||
@ -244,14 +257,10 @@ const activateAppellationDropdown = {
|
|||||||
name: "activateAppellationDropdown",
|
name: "activateAppellationDropdown",
|
||||||
match: node => node.classList.contains("persoenlicheangaben") && hasConfiguredPersonalData,
|
match: node => node.classList.contains("persoenlicheangaben") && hasConfiguredPersonalData,
|
||||||
execute: node => {
|
execute: node => {
|
||||||
settings.get("addr__appellation").then(foundKeys => {
|
return ensureSettingsProp("addr__appellation", () => {
|
||||||
console.log("storage returned", foundKeys);
|
|
||||||
if (Object.keys(foundKeys).includes("addr__appellation")) {
|
|
||||||
const selectList = node.querySelector('.test-name-anrede.db-web-select');
|
const selectList = node.querySelector('.test-name-anrede.db-web-select');
|
||||||
selectList.querySelector('button').dispatchEvent(_clickEv());
|
selectList.querySelector('button').dispatchEvent(_clickEv());
|
||||||
}
|
}, () => true);
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**@type Stage */
|
/**@type Stage */
|
||||||
@ -259,16 +268,13 @@ const enterAppellationAndActivateTitleDropdown = {
|
|||||||
name: "enterAppellationAndActivateTitleDropdown",
|
name: "enterAppellationAndActivateTitleDropdown",
|
||||||
match: node => node.classList.contains("db-web-dropdown-outer-container") && node.querySelector(".db-web-select-list") !== null,
|
match: node => node.classList.contains("db-web-dropdown-outer-container") && node.querySelector(".db-web-select-list") !== null,
|
||||||
execute: node => {
|
execute: node => {
|
||||||
settings.get("addr__appellation").then(foundKeys => {
|
ensureSettingsProp("addr__appellation", v => {
|
||||||
console.log("storage returned", foundKeys);
|
|
||||||
if (Object.keys(foundKeys).includes("addr__appellation")) {
|
|
||||||
const selectList = $$(node, "ul");
|
const selectList = $$(node, "ul");
|
||||||
selectList.querySelector(`[data-value=${foundKeys.addr__appellation}]`).dispatchEvent(_clickEv());
|
selectList.querySelector(`[data-value=${foundKeys.addr__appellation}]`).dispatchEvent(_clickEv());
|
||||||
} else {
|
}, () => {
|
||||||
node.parentElement.parentElement.parentElement.querySelector("button").dispatchEvent(_clickEv());
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -281,12 +287,10 @@ const enterTitle = {
|
|||||||
execute: node => {
|
execute: node => {
|
||||||
settings.get("addr__title").then(foundKeys => {
|
settings.get("addr__title").then(foundKeys => {
|
||||||
console.log("storage returned", foundKeys);
|
console.log("storage returned", foundKeys);
|
||||||
if (Object.keys(foundKeys).includes("addr__title")) {
|
ensureSettingsProp("addr__title", v => {
|
||||||
const selectList = $$(node, "ul");
|
const selectList = $$(node, "ul");
|
||||||
selectList.querySelector(`[data-value=${foundKeys.addr__title}]`).dispatchEvent(_clickEv());
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
@ -333,7 +337,7 @@ const enterTextPersonalData = {
|
|||||||
"addr__placename": ".test-adresse-ort input"
|
"addr__placename": ".test-adresse-ort input"
|
||||||
}
|
}
|
||||||
for (const [k, v] of Object.entries(foundKeys)) {
|
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
|
//TODO WIP this only works on some fields
|
||||||
console.log("filling", configKey_Selector[k], "with", v);
|
console.log("filling", configKey_Selector[k], "with", v);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@ -349,8 +353,8 @@ const enterTextPersonalData = {
|
|||||||
continueBtn.focus();
|
continueBtn.focus();
|
||||||
continueBtn.dispatchEvent(_clickEv());
|
continueBtn.dispatchEvent(_clickEv());
|
||||||
}, delay);
|
}, delay);
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
})
|
|
||||||
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user