lotsa stuff
This commit is contained in:
@@ -1,55 +1,42 @@
|
||||
"use strict";
|
||||
// Put all the javascript code here, that you want to execute after page load.
|
||||
|
||||
let bcFilled = false;
|
||||
let bdayFilled = false;
|
||||
let clickThroughForms = false;
|
||||
let currentStage;
|
||||
|
||||
function clickContinue() {
|
||||
if (bdayFilled && bcFilled) {
|
||||
document.querySelector('.fahrgastrechte-bahn-card-auswahl button.fahrgastrechte-continue-button')?.dispatchEvent(new Event('click'));
|
||||
function executeStage(node) {
|
||||
if (node.nodeType === 1) {
|
||||
if (currentStage === undefined) {
|
||||
currentStage = stages.shift();
|
||||
}
|
||||
if (currentStage.match(node)) {
|
||||
console.log(currentStage.name, "matched");
|
||||
console.log(currentStage.name, currentStage.execute(node) ? "executed" : "execution failed");
|
||||
if (stages.length > 0) {
|
||||
currentStage = stages.shift();
|
||||
} else {
|
||||
observer.disconnect();
|
||||
}
|
||||
} else {
|
||||
console.log(currentStage.name, "did not match");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function processMutations(mutationList, observer) {
|
||||
for (const mutation of mutationList) {
|
||||
if (mutation.type === "childList") {
|
||||
mutation.addedNodes.forEach(node => {
|
||||
if (node.nodeType === 1) {
|
||||
if (node.classList.contains("antrag-starten")) {
|
||||
node.querySelector('button.test-antrag-starten-button').dispatchEvent(new Event('click', { bubbles: true }));
|
||||
}
|
||||
else if (node.classList.contains("fahrgastrechte-bahn-card-auswahl")) {
|
||||
node.querySelectorAll('input').forEach(e => {
|
||||
if (e.name === "fahrgastrechte-bahn-card-nummer") {
|
||||
fillBcnum().then(clickContinue);
|
||||
} else if (e.name === "fahrgastrechte-bahn-card-auswahl-geburts-datum") {
|
||||
fillBday().then(clickContinue);
|
||||
}
|
||||
})
|
||||
}
|
||||
if (clickThroughForms) {
|
||||
if (node.classList.contains("antrags-typ-auswahl")) {
|
||||
node.querySelector('input#antragstyp-verspaetung').dispatchEvent(new Event('change'));
|
||||
} else if (node.classList.contains("verspaetungs-auswahl")) {
|
||||
node.querySelector('#verspaetungstyp-mehr-als-stunde').dispatchEvent(new Event('change'));
|
||||
} else if (node.classList.contains("verspaetung-bestaetigung")) {
|
||||
node.querySelector('button.fahrgastrechte-continue-button').dispatchEvent(new Event('click', { bubbles: true }));
|
||||
}
|
||||
} else {
|
||||
console.log(node);
|
||||
}
|
||||
}
|
||||
})
|
||||
mutation.addedNodes.forEach(executeStage);
|
||||
}
|
||||
}
|
||||
clickContinue();
|
||||
}
|
||||
|
||||
let clickThroughForms;
|
||||
let observer = new MutationObserver(processMutations);
|
||||
const addObserver = () => {
|
||||
browser.storage.sync.get('autocontinue').then(v => {
|
||||
clickThroughForms = !!v.autocontinue;
|
||||
}).then(() => {
|
||||
observer.observe(document.body, {
|
||||
childList: true, subtree: true
|
||||
})
|
||||
@@ -58,25 +45,98 @@ const addObserver = () => {
|
||||
|
||||
addObserver();
|
||||
|
||||
async function fillBcnum() {
|
||||
let bcNumberInput = document.querySelector('input[name=fahrgastrechte-bahn-card-nummer]');
|
||||
const startClaim = {
|
||||
name: "startClaim",
|
||||
match: node => node.classList.contains("antrag-starten"),
|
||||
execute: node => {
|
||||
const startenButton = node.querySelector('button.test-antrag-starten-button');
|
||||
if (startenButton instanceof HTMLButtonElement) {
|
||||
startenButton.dispatchEvent(new Event('click', { bubbles: true }));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function fillBcnum(bcNumberInput) {
|
||||
browser.storage.sync.get('bcnum').then(v => {
|
||||
let bcNum = v.bcnum || null;
|
||||
if (bcNum !== null && bcNum !== "") {
|
||||
bcNumberInput.value = bcNum;
|
||||
bcNumberInput.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
bcFilled = true;
|
||||
return true;
|
||||
}
|
||||
})
|
||||
return false;
|
||||
}
|
||||
async function fillBday() {
|
||||
let birthdayInput = document.querySelector('input[name=fahrgastrechte-bahn-card-auswahl-geburts-datum');
|
||||
function fillBday(birthdayInput) {
|
||||
browser.storage.sync.get('bday').then(v => {
|
||||
bDay = v.bday || null;
|
||||
const bDay = v.bday || null;
|
||||
if (bDay !== null && bDay !== "") {
|
||||
birthdayInput.value = bDay;
|
||||
birthdayInput.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
bdayFilled = true;
|
||||
return true;
|
||||
}
|
||||
})
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const fillData = {
|
||||
name: "fillData",
|
||||
match: node => node.classList.contains("fahrgastrechte-bahn-card-auswahl"),
|
||||
execute: node => {
|
||||
let bcNumField, bdayField;
|
||||
node.querySelectorAll('input').forEach(e => {
|
||||
if (e.name === "fahrgastrechte-bahn-card-nummer") {
|
||||
bcNumField = e;
|
||||
} else if (e.name === "fahrgastrechte-bahn-card-auswahl-geburts-datum") {
|
||||
bdayField = e;
|
||||
}
|
||||
})
|
||||
fillBcnum(bcNumField);
|
||||
fillBday(bdayField);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
const clickContinue = {
|
||||
name: "clickContinue",
|
||||
match: () => true,
|
||||
execute: e => {
|
||||
const continueButton = document.querySelector('.fahrgastrechte-bahn-card-auswahl button.fahrgastrechte-continue-button');
|
||||
if (continueButton instanceof Element) {
|
||||
continueButton.dispatchEvent(new Event('click'));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const iWasDelayed = {
|
||||
name: "iWasDelayed",
|
||||
match: node => node.classList.contains("antrags-typ-auswahl") && clickThroughForms,
|
||||
execute: node => {
|
||||
const delay = node.querySelector('input#antragstyp-verspaetung');
|
||||
if (delay instanceof HTMLInputElement) {
|
||||
delay.dispatchEvent(new Event('change'));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const moreThan60Minutes = {
|
||||
name: "moreThan60Minutes",
|
||||
match: node => node.classList.contains("verspaetungs-auswahl") && clickThroughForms,
|
||||
execute: node => node.querySelector('#verspaetungstyp-mehr-als-stunde').dispatchEvent(new Event('change'))
|
||||
}
|
||||
const continueToForm = {
|
||||
name: "continueToForm",
|
||||
match: node => node.classList.contains("verspaetung-bestaetigung") && clickThroughForms,
|
||||
execute: node => node.querySelector('button.fahrgastrechte-continue-button').dispatchEvent(new Event('click', { bubbles: true }))
|
||||
}
|
||||
let stages = [
|
||||
startClaim, fillData, clickContinue, iWasDelayed, moreThan60Minutes, continueToForm
|
||||
];
|
||||
|
Reference in New Issue
Block a user