add personal data inputs
This commit is contained in:
@@ -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() {
|
||||
|
Reference in New Issue
Block a user