WIP
This commit is contained in:
parent
b47b1e2073
commit
59e8e9f225
@ -27,19 +27,6 @@ const personalDataConfigKeys = ["addr__appellation", "addr__firstName", "addr__s
|
||||
const bankDetailConfigKeys = ["pymt__iban", "pymt__bic"];
|
||||
|
||||
|
||||
function hasConfiguredPersonalData() {
|
||||
browser.storage.sync.get(personalDataConfigKeys).then(res => {
|
||||
return res.length > 0;
|
||||
})
|
||||
}
|
||||
|
||||
function hasConfiguredBankDetails() {
|
||||
browser.storage.sync.get(bankDetailConfigKeys).then(res => {
|
||||
return res.length > 0;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function processMutations(mutationList, observer) {
|
||||
for (const mutation of mutationList) {
|
||||
if (mutation.type === "childList") {
|
||||
@ -48,10 +35,13 @@ function processMutations(mutationList, observer) {
|
||||
}
|
||||
}
|
||||
let clickThroughForms;
|
||||
let hasConfiguredBankDetails, hasConfiguredPersonalData;
|
||||
let observer = new MutationObserver(processMutations);
|
||||
const addObserver = () => {
|
||||
browser.storage.sync.get(['autocontinue', 'enable']).then(v => {
|
||||
browser.storage.sync.get(['autocontinue', 'enable'].concat(personalDataConfigKeys, bankDetailConfigKeys)).then(v => {
|
||||
clickThroughForms = !!v.autocontinue;
|
||||
hasConfiguredPersonalData = Object.keys(v).filter(k => personalDataConfigKeys.includes(k)).length > 0;
|
||||
hasConfiguredBankDetails = Object.keys(v).filter(k => bankDetailConfigKeys.includes(k)).length > 0;
|
||||
if (!!v.enable) {
|
||||
observer.observe(document.body, {
|
||||
childList: true, subtree: true
|
||||
@ -64,11 +54,9 @@ addObserver();
|
||||
|
||||
function fillTextInput(parentNode, selector, value) {
|
||||
const node = parentNode.querySelector(selector);
|
||||
if (node instanceof HTMLInputElement) {
|
||||
node.value = value;
|
||||
node.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
}
|
||||
}
|
||||
|
||||
const startClaim = {
|
||||
name: "startClaim",
|
||||
@ -165,7 +153,7 @@ const continueToForm = {
|
||||
|
||||
const enterPersonalData = {
|
||||
name: "enterPersonalData",
|
||||
match: node => node.classList.contains("persoenlicheangaben") && hasConfiguredPersonalData(),
|
||||
match: node => node.classList.contains("persoenlicheangaben") && hasConfiguredPersonalData,
|
||||
execute: node => {
|
||||
browser.storage.sync.get(personalDataConfigKeys).then(foundKeys => {
|
||||
console.log("storage returned", foundKeys);
|
||||
@ -174,34 +162,22 @@ const enterPersonalData = {
|
||||
// let dropDownSelectList = node.querySelector('.test-name-anrede ul.db-web-select-list');
|
||||
|
||||
// }
|
||||
const configKey_Selector = {
|
||||
"addr__firstName": ".test-name-vorname input",
|
||||
"addr__surName": ".test-name-nachname input",
|
||||
"addr__email": ".persoenlicheangaben__email input",
|
||||
"addr__street": ".test-adresse-strasse input",
|
||||
"addr__postcode": ".test-adresse-plz input",
|
||||
"addr__placename": ".test-adresse-ort input"
|
||||
}
|
||||
|
||||
for (const [k, v] of Object.entries(foundKeys)) {
|
||||
console.log("processing:", k, ": ", v);
|
||||
switch (k) {
|
||||
case "addr__firstName":
|
||||
console.log("firstName", k, v);
|
||||
fillTextInput(node, ".test-name-vorname input", v);
|
||||
break;
|
||||
case "addr__surName":
|
||||
console.log("lastname", k, v);
|
||||
fillTextInput(node, '.test-name-nachname input', v);
|
||||
break;
|
||||
case "addr__email":
|
||||
console.log("em", k, v);
|
||||
fillTextInput(node, '.persoenlicheangaben__email input', v);
|
||||
break;
|
||||
case "addr__street":
|
||||
console.log("street", k, v);
|
||||
fillTextInput(node, ".test-adresse-strasse input", v);
|
||||
break;
|
||||
case "addr__postcode":
|
||||
fillTextInput(node, ".test-adresse-plz input", v);
|
||||
break;
|
||||
case "addr__placename":
|
||||
fillTextInput(node, ".test-adresse-ort input", v);
|
||||
break;
|
||||
default:
|
||||
console.log(k, ":", v, "did not match");
|
||||
if (Object.keys(configKey_Selector).includes(k)) {
|
||||
//TODO WIP this only works on some fields
|
||||
console.log("filling", configKey_Selector, "with", v);
|
||||
fillTextInput(node, configKey_Selector[k], v);
|
||||
} else {
|
||||
console.log("no selector found for config key", k);
|
||||
}
|
||||
}
|
||||
const continueBtn = document.querySelector(".fahrgastrechte-editable__buttons button.fahrgastrechte-continue-button");
|
||||
@ -216,7 +192,7 @@ const enterPersonalData = {
|
||||
|
||||
const enterPaymentDetails = {
|
||||
name: "enterPaymentDetails",
|
||||
match: node => node.classList.contains("entschaedigung") && hasConfiguredBankDetails(),
|
||||
match: node => node.classList.contains("entschaedigung") && hasConfiguredBankDetails,
|
||||
execute: node => {
|
||||
node.querySelector('#ueberweisung').dispatchEvent(new Event('change'));
|
||||
browser.storage.sync.get(bankDetailConfigKeys).then(results => {
|
||||
|
@ -128,13 +128,33 @@ async function restoreOptions() {
|
||||
document.querySelector("#bcnum").value = settings.bcnum || "";
|
||||
document.querySelector("#birthday").value = settings.bday || "";
|
||||
document.querySelector("#autocontinue").checked = settings.autocontinue || false;
|
||||
document.querySelector('#title').value = settings.addr__appellation || "";
|
||||
document.querySelector('#firstname').value = settings.addr__firstName || "";
|
||||
document.querySelector('#surname').value = settings.addr__surName || "";
|
||||
document.querySelector('#email').value = settings.addr__email || "";
|
||||
document.querySelector('#addr1').value = settings.addr__street || "";
|
||||
document.querySelector('#postcode').value = settings.addr__postcode || "";
|
||||
document.querySelector('#placename').value = settings.addr__placename || "";
|
||||
document.querySelector('#iban').value = settings.pymt__iban || "";
|
||||
document.querySelector('#bic').value = settings.pymt__bic || "";
|
||||
}
|
||||
|
||||
let bahncardWindow;
|
||||
|
||||
function startBcnumAcquisition(ev) {
|
||||
browser.storage.sync.set({ "acquireBahncard": true }).then(() => {
|
||||
win = window.open("https://www.bahn.de/buchung/kundenkonto/bahncard", "_blank", "popup")
|
||||
if (win instanceof Window){
|
||||
win.postMessage("__WINDOW_OPENED_FOR_BC_ACQUISITION__");
|
||||
browser.storage.sync.onChanged.addListener(changes => {
|
||||
console.log(changes);
|
||||
for (const [key, changeSet] of Object.entries(changes)) {
|
||||
if (key === "bcnum") {
|
||||
bahncardWindow.close();
|
||||
browser.storage.sync.onChanged.removeListener(this);
|
||||
}
|
||||
}
|
||||
})
|
||||
bahncardWindow = window.open("https://www.bahn.de/buchung/kundenkonto/bahncard", "_blank", "popup")
|
||||
if (bahncardWindow instanceof Window) {
|
||||
bahncardWindow.postMessage("__WINDOW_OPENED_FOR_BC_ACQUISITION__");
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user