initial commit
This commit is contained in:
commit
8d34088021
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;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
BIN
icons/icon.png
Normal file
BIN
icons/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.0 KiB |
30
manifest.json
Normal file
30
manifest.json
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"manifest_version": 2,
|
||||||
|
"name": "BC100 Autofill",
|
||||||
|
"description": "Autofills your BahnCard 100 number and birthday into the passenger rights claim form.",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"icons": {
|
||||||
|
"64": "icons/icon.png"
|
||||||
|
},
|
||||||
|
"content_scripts": [
|
||||||
|
{
|
||||||
|
"matches": [
|
||||||
|
"https://www.bahn.de/buchung/fahrgastrechte?einstiegtyp=BC100"
|
||||||
|
],
|
||||||
|
"js": [
|
||||||
|
"content_script.js"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"permissions": [
|
||||||
|
"storage"
|
||||||
|
],
|
||||||
|
"options_ui": {
|
||||||
|
"page": "options/index.html"
|
||||||
|
},
|
||||||
|
"browser_specific_settings": {
|
||||||
|
"gecko": {
|
||||||
|
"id": "bc100-autofill@iw0.name"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
28
options/index.html
Normal file
28
options/index.html
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<link href="style.css" rel="stylesheet" />
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<form>
|
||||||
|
<fieldset>
|
||||||
|
<label for="bcnum">The number of your BahnCard 100</label>
|
||||||
|
<input name="bcnum" id="bcnum" type="text" pattern="70814[0-9]{11}" />
|
||||||
|
</fieldset>
|
||||||
|
<fieldset>
|
||||||
|
<label for="birthday">Your date of birth</label>
|
||||||
|
<input name="birthday" id="birthday" type="date" />
|
||||||
|
</fieldset>
|
||||||
|
<fieldset>
|
||||||
|
<label for="autocontinue">Automatically continue to the "I was delayed by more than 60 minutes" screen</label>
|
||||||
|
<input name="autocontinue" id="autocontinue" type="checkbox" />
|
||||||
|
</fieldset>
|
||||||
|
<button type="submit">Save</button>
|
||||||
|
</form>
|
||||||
|
<script src="script.js"></script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
29
options/script.js
Normal file
29
options/script.js
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
async function saveOptions(e) {
|
||||||
|
console.log("Saving options.");
|
||||||
|
e.preventDefault();
|
||||||
|
let bcNum = document.querySelector("#bcnum").value;
|
||||||
|
let bDay = document.querySelector('#birthday').value;
|
||||||
|
let autoContinue = document.querySelector('#autocontinue').checked;
|
||||||
|
let options = {
|
||||||
|
bcnum: bcNum,
|
||||||
|
bday: bDay,
|
||||||
|
autocontinue: autoContinue
|
||||||
|
};
|
||||||
|
await browser.storage.sync.set(options);
|
||||||
|
console.log("Saved!");
|
||||||
|
}
|
||||||
|
|
||||||
|
async function restoreOptions() {
|
||||||
|
// We do not save user data in managed storage.
|
||||||
|
// let res = await browser.storage.managed.get('colour');
|
||||||
|
// document.querySelector("#managed-colour").innerText = res.colour;
|
||||||
|
|
||||||
|
settings = await browser.storage.sync.get();
|
||||||
|
console.log(settings);
|
||||||
|
document.querySelector("#bcnum").value = settings.bcnum || "";
|
||||||
|
document.querySelector("#birthday").value = settings.bday || "";
|
||||||
|
document.querySelector("#autocontinue").checked = settings.autocontinue || false;
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', restoreOptions);
|
||||||
|
document.querySelector("form").addEventListener("submit", saveOptions);
|
3
options/style.css
Normal file
3
options/style.css
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
h1 {
|
||||||
|
font-style: italic;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user