initial commit
This commit is contained in:
82
content_script.js
Normal file
82
content_script.js
Normal file
@@ -0,0 +1,82 @@
|
||||
// Put all the javascript code here, that you want to execute after page load.
|
||||
|
||||
let bcFilled = false;
|
||||
let bdayFilled = false;
|
||||
let clickThroughForms = false;
|
||||
|
||||
function clickContinue() {
|
||||
if (bdayFilled && bcFilled) {
|
||||
document.querySelector('.fahrgastrechte-bahn-card-auswahl button.fahrgastrechte-continue-button')?.dispatchEvent(new Event('click'));
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
clickContinue();
|
||||
}
|
||||
|
||||
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
|
||||
})
|
||||
})
|
||||
};
|
||||
|
||||
addObserver();
|
||||
|
||||
async function fillBcnum() {
|
||||
let bcNumberInput = document.querySelector('input[name=fahrgastrechte-bahn-card-nummer]');
|
||||
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;
|
||||
}
|
||||
})
|
||||
}
|
||||
async function fillBday() {
|
||||
let birthdayInput = document.querySelector('input[name=fahrgastrechte-bahn-card-auswahl-geburts-datum');
|
||||
browser.storage.sync.get('bday').then(v => {
|
||||
bDay = v.bday || null;
|
||||
if (bDay !== null && bDay !== "") {
|
||||
birthdayInput.value = bDay;
|
||||
birthdayInput.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
bdayFilled = true;
|
||||
}
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user