diff --git a/options/index.html b/options/index.html
index 0e577b5..cdac416 100644
--- a/options/index.html
+++ b/options/index.html
@@ -18,17 +18,65 @@
The number on the front of your card starting with 7081 .
- Get from profile (experimental)
+ Get from profile (experimental)
Your date of birth
-
+
Skip questionnaire
Automatically answer "I was delayed, by more than 60 minutes."
+
+ Address data
+
+ Title
+
+ Please choose
+ Mr
+ Ms
+
+
+
+ Name
+
+
+
+ Surname
+
+
+
+ Email address
+
+
+
+ Street address
+
+
+
+ Postcode
+
+
+
+ Place
+
+
+
+
+ Bank details
+
+ IBAN
+ Please make sure to enter any letters in upper case.
+
+
+
+ BIC
+ Bank Identifier Code for your bank. Can mostly be omitted.
+
+
+
Save
diff --git a/options/script.js b/options/script.js
index cfe4d2a..5b3183a 100644
--- a/options/script.js
+++ b/options/script.js
@@ -26,6 +26,27 @@ function luhnValidate(cardNumber) {
return (total !== 0 && (total % 10) === 0);
}
+function ibanLatinCharId(chr){
+ c = chr.charCodeAt(0);
+ if (c > 0x40 && c <= 0x5a) {
+ return chr.charCodeAt(0) - 0x40 + 9;
+ } else if (c > 0x60 && c <= 0x7a) {
+ return chr.charCodeAt(0) - 0x60 + 9;
+ }
+ return false;
+}
+function ibanValidate(iban){
+ iban = iban.toUpperCase();
+ countryId = iban.slice(0, 2);
+ checksum = iban.slice(2, 4);
+ countryDigits = countryId.split('').map(ibanLatinCharId).join('');
+ body = iban.substring(4);
+ processing = `${body}${countryDigits}${checksum}`;
+ resultingNumber = BigInt(processing, 10);
+ mod = resultingNumber % 97n;
+ return mod == 1;
+
+}
function putError(s){
document.querySelector('#errors').textContent += s;
@@ -34,6 +55,13 @@ function clearError(){
document.querySelector('#errors').textContent = "";
}
+async function saveValueIfNotEmpty(k, v){
+ if (v!==""){
+ return browser.storage.sync.set({k:v})
+ }
+ return false
+}
+
async function saveOptions(ev) {
clearError();
ev.preventDefault();
@@ -49,18 +77,44 @@ async function saveOptions(ev) {
}
let autoContinue = this.querySelector('#autocontinue').checked;
let enable = this.querySelector('#enable').checked;
+ let title = this.querySelector('#title').value;
+ let firstName = this.querySelector('#firstname').value;
+ let surName = this.querySelector('#surname').value;
+ let emailAddress = this.querySelector('#email').value;
+ let streetAddr = this.querySelector('#addr1').value;
+ let postCode = this.querySelector('#postcode').value;
+ let placeName = this.querySelector('#placename').value;
+ let iban = this.querySelector('#iban').value;
+ if (iban != "" && !ibanValidate(iban)){
+ putError("Please check your IBAN for typing errors.");
+ return;
+ }
+ let bic = this.querySelector('#bic').value;
let options = {
bcnum: bcNum,
bday: bDay,
- autocontinue: autoContinue
+ autocontinue: autoContinue,
+ enable: enable,
+ addr__appellation: title,
+ addr__firstName: firstName,
+ addr__surName: surName,
+ addr__email: emailAddress,
+ addr__street: streetAddr,
+ addr__postcode: postCode,
+ addr__placename: placeName,
+ pymt__iban: iban,
+ pymt__bic: bic
};
+ options = Object.fromEntries(Object.entries(options).filter(([k, v]) => v !== ""))
console.log("saving", options);
+
browser.storage.sync.set(options).then(() => {
document.querySelector('#success').textContent = "✔";
setTimeout(() => {
document.querySelector('#success').textContent = '';
}, 5000);
})
+
}
async function restoreOptions() {
diff --git a/options/style.css b/options/style.css
index 23c8ae3..eddef4e 100644
--- a/options/style.css
+++ b/options/style.css
@@ -12,7 +12,7 @@ label.item {
display: block;
}
-input {
+input, select {
margin: 8px 0px;
}