experiment: acquire bc number from account

This commit is contained in:
iw0
2023-10-17 19:04:15 +02:00
parent eb7d1edbaa
commit 97d3ac1492
4 changed files with 88 additions and 3 deletions

View File

@@ -1,3 +1,4 @@
"use strict;"
function luhnValidate(cardNumber) {
cardNumber = String(cardNumber).replace(/[\s]/g, "");
let odd = false;
@@ -37,7 +38,7 @@ async function saveOptions(ev) {
clearError();
ev.preventDefault();
let bcNum = this.querySelector("#bcnum").value;
if (!bcNum.length == 16 || !bcNum.startsWith("70814") || !luhnValidate(bcNum)) {
if (bcNum.length !== 16 || !bcNum.startsWith("70814") || !luhnValidate(bcNum)) {
putError("Your BahnCard number is not valid. Please make sure you haven't made any typos.");
return;
}
@@ -75,5 +76,15 @@ async function restoreOptions() {
document.querySelector("#autocontinue").checked = settings.autocontinue || false;
}
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__");
}
})
}
document.addEventListener('DOMContentLoaded', restoreOptions);
document.querySelector("form").addEventListener("submit", saveOptions);
document.querySelector("form").addEventListener("submit", saveOptions);
document.querySelector("#bcnum-get-from-profile").addEventListener("click", startBcnumAcquisition)